line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Yotpo; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
70041
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
27
|
use 5.008_005; |
|
1
|
|
|
|
|
4
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
8
|
1
|
|
|
1
|
|
672
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
50072
|
|
|
1
|
|
|
|
|
38
|
|
9
|
1
|
|
|
1
|
|
699
|
use JSON; |
|
1
|
|
|
|
|
10281
|
|
|
1
|
|
|
|
|
6
|
|
10
|
1
|
|
|
1
|
|
167
|
use HTTP::Request; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
11
|
1
|
|
|
1
|
|
5
|
use vars qw/$errstr/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
471
|
|
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
0
|
0
|
|
sub errstr { $errstr } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
17
|
0
|
0
|
|
|
|
|
my %args = @_ % 2 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
$args{client_id} or croak 'client_id is required.'; |
20
|
0
|
0
|
|
|
|
|
$args{client_secret} or croak 'client_secret is required.'; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
0
|
|
|
|
$args{ua} ||= LWP::UserAgent->new; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
return bless \%args, $class; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub oauth_token { |
28
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
29
|
0
|
0
|
|
|
|
|
my %params = @_ % 2 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$self->request('oauth/token', 'POST', { |
31
|
|
|
|
|
|
|
"client_id" => $self->{client_id}, |
32
|
|
|
|
|
|
|
"client_secret" => $self->{client_secret}, |
33
|
0
|
|
|
|
|
|
"grant_type" => "client_credentials" |
34
|
|
|
|
|
|
|
}); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub mass_create { |
38
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
39
|
0
|
0
|
|
|
|
|
my %params = @_ % 2 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$self->request('apps/' . $self->{client_id} . '/purchases/mass_create', 'POST', { |
41
|
|
|
|
|
|
|
Content => encode_json(\%params), |
42
|
|
|
|
|
|
|
utoken => $params{utoken} |
43
|
0
|
|
|
|
|
|
}); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub purchases { |
47
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
48
|
0
|
0
|
|
|
|
|
my %params = @_ % 2 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$self->request('apps/' . $self->{client_id} . '/purchases', 'GET', \%params); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub request { |
53
|
0
|
|
|
0
|
0
|
|
my ($self, $url, $method, $params) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$url = 'https://api.yotpo.com/' . $url; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
0
|
|
|
|
$params ||= {}; |
58
|
0
|
|
|
|
|
|
my $content = delete $params->{Content}; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $uri = URI->new($url); |
61
|
0
|
0
|
|
|
|
|
$uri->query_form($params) if keys %$params; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new($method, $uri); |
64
|
0
|
0
|
|
|
|
|
if ($content) { |
65
|
0
|
|
|
|
|
|
$req->content($content); |
66
|
0
|
|
|
|
|
|
$req->content_type('application/json'); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
my $res = $self->{ua}->request($req); |
69
|
|
|
|
|
|
|
# print Dumper(\$res); use Data::Dumper; |
70
|
0
|
0
|
|
|
|
|
if (not $res->header('Content-Type') =~ /json/) { |
71
|
0
|
|
|
|
|
|
$errstr = $res->status_line; |
72
|
0
|
|
|
|
|
|
return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return decode_json($res->decoded_content); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
__END__ |