line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Snapforce::API; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
14675
|
use 5.018002; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
2
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
59
|
|
7
|
1
|
|
|
1
|
|
178
|
use XML::Parser; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use HTTP::Request::Common qw/GET POST/; |
9
|
|
|
|
|
|
|
use LWP::UserAgent; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Exporter; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
14
|
|
|
|
|
|
|
our $SNAPURL = 'https://crm2.snapforce.com/sf_receive_request.inc.php'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
|
|
|
|
|
|
my ($class, $authuser, $authkey) = @_; |
18
|
|
|
|
|
|
|
croak "Authentication user and/or key are missing" unless $authkey; |
19
|
|
|
|
|
|
|
my $self = bless { |
20
|
|
|
|
|
|
|
authuser => $authuser, |
21
|
|
|
|
|
|
|
authkey => $authkey |
22
|
|
|
|
|
|
|
}, $class; |
23
|
|
|
|
|
|
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub fetchRecords { |
27
|
|
|
|
|
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
return runAPI($self, 'method' => "fetchRecords", @_); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub runAPI { |
32
|
|
|
|
|
|
|
my ($self, %args) = @_; |
33
|
|
|
|
|
|
|
carp "No method specified for explicit call of runAPI. Defaulting to fetchRecords" if not $args{'method'}; |
34
|
|
|
|
|
|
|
my %params = ( |
35
|
|
|
|
|
|
|
format => "xml", |
36
|
|
|
|
|
|
|
module => "Accounts", |
37
|
|
|
|
|
|
|
api_user => $self->{authuser}, |
38
|
|
|
|
|
|
|
api_key => $self->{authkey}, |
39
|
|
|
|
|
|
|
status => "Active", |
40
|
|
|
|
|
|
|
method => "fetchRecords" |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
@params{keys %args} = values %args; |
43
|
|
|
|
|
|
|
my $ua = new LWP::UserAgent; |
44
|
|
|
|
|
|
|
my $resp = $ua->request(POST $SNAPURL, [%params]); |
45
|
|
|
|
|
|
|
return $resp->content; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub parseXML { |
49
|
|
|
|
|
|
|
my ($self, $info) = @_; |
50
|
|
|
|
|
|
|
my %data = (); |
51
|
|
|
|
|
|
|
my @tree = (); |
52
|
|
|
|
|
|
|
my $spot = ""; |
53
|
|
|
|
|
|
|
my $word = ""; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $sthdl = sub { |
56
|
|
|
|
|
|
|
my ($prsr, $elem, %atts) = @_; |
57
|
|
|
|
|
|
|
my $obj = \%data; |
58
|
|
|
|
|
|
|
$obj = ${$obj}{$_} foreach (@tree); |
59
|
|
|
|
|
|
|
$spot = $elem.(%atts ? "-".$atts{(keys %atts)[0]} : ""); |
60
|
|
|
|
|
|
|
push @tree, $spot; |
61
|
|
|
|
|
|
|
${$obj}{$spot} = {}; |
62
|
|
|
|
|
|
|
$word = ""; |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
my $edhdl = sub { |
65
|
|
|
|
|
|
|
my ($prsr, $elem) = @_; |
66
|
|
|
|
|
|
|
pop @tree; |
67
|
|
|
|
|
|
|
my $obj = \%data; |
68
|
|
|
|
|
|
|
$obj = ${$obj}{$_} foreach @tree; |
69
|
|
|
|
|
|
|
${$obj}{$spot} = $word; |
70
|
|
|
|
|
|
|
$spot = ""; |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
my $chhdl = sub { |
73
|
|
|
|
|
|
|
$word .= $_[1]; |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $parser = XML::Parser->new(Handlers => { |
77
|
|
|
|
|
|
|
Start => \&$sthdl, |
78
|
|
|
|
|
|
|
End => \&$edhdl, |
79
|
|
|
|
|
|
|
Char => \&$chhdl |
80
|
|
|
|
|
|
|
}); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$parser->parse($info); |
83
|
|
|
|
|
|
|
delete $data{""}; |
84
|
|
|
|
|
|
|
delete $data{(keys %data)[0]}{''}; |
85
|
|
|
|
|
|
|
return %data; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
__END__ |