| 1 | package WWW::Yotpo; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use 5.008_005; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.02'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use JSON; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use HTTP::Request; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use vars qw/$errstr/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 0 | ▶ | sub errstr { $errstr } | ||||||||||||||||||
|
Subroutine
errstr: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | sub new { | ||||||||||||||||||||
| 16 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 17 | 0 | ▶ | my %args = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 0 | ▶ | $args{client_id} or croak 'client_id is required.'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | 0 | ▶ | $args{client_secret} or croak 'client_secret is required.'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 0 | ▶ | $args{ua} ||= LWP::UserAgent->new; | ||||||||||||||||||
|
Condition0%0/3
$args{"ua"} ||= "LWP::UserAgent"->new
MC/DC0%0/2
$args{"ua"} ||= "LWP::UserAgent"->new
$args{"ua"}
"LWP::UserAgent"->new
Truth table0%0/3
A ||= B
A= $args{"ua"}B= "LWP::UserAgent"->new
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 0 | return bless \%args, $class; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | sub oauth_token { | ||||||||||||||||||||
| 28 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
oauth_token: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 29 | 0 | ▶ | my %params = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
mass_create: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 39 | 0 | ▶ | my %params = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
purchases: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 48 | 0 | ▶ | my %params = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | $self->request('apps/' . $self->{client_id} . '/purchases', 'GET', \%params); | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | sub request { | ||||||||||||||||||||
| 53 | 0 | ▶ | my ($self, $url, $method, $params) = @_; | ||||||||||||||||||
|
Subroutine
request: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | $url = 'https://api.yotpo.com/' . $url; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | ▶ | $params ||= {}; | ||||||||||||||||||
|
Condition0%0/2
$params ||= {}
MC/DC0%0/1
$params ||= {}
$params
Truth table0%0/2
A
A= $params
| |||||||||||||||||||||
| 58 | 0 | my $content = delete $params->{Content}; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | my $uri = URI->new($url); | |||||||||||||||||||
| 61 | 0 | ▶ | $uri->query_form($params) if keys %$params; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | my $req = HTTP::Request->new($method, $uri); | |||||||||||||||||||
| 64 | 0 | ▶ | if ($content) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | ▶ | if (not $res->header('Content-Type') =~ /json/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | 0 | $errstr = $res->status_line; | |||||||||||||||||||
| 72 | 0 | return; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 0 | return decode_json($res->decoded_content); | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 1 | 1; | |||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||