| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Buscape::API; |
|
2
|
|
|
|
|
|
|
$Buscape::API::VERSION = '0.000003'; |
|
3
|
3
|
|
|
3
|
|
298307
|
use Moo; |
|
|
3
|
|
|
|
|
57797
|
|
|
|
3
|
|
|
|
|
19
|
|
|
4
|
3
|
|
|
3
|
|
15682
|
use URI; |
|
|
3
|
|
|
|
|
21106
|
|
|
|
3
|
|
|
|
|
296
|
|
|
5
|
3
|
|
|
3
|
|
29
|
use Carp; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
249
|
|
|
6
|
3
|
|
|
3
|
|
3144
|
use Const::Fast; |
|
|
3
|
|
|
|
|
3571
|
|
|
|
3
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
6302
|
use List::MoreUtils qw{ any }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
const our %METHODS => ( |
|
11
|
|
|
|
|
|
|
'find_category_list' => 'findCategoryList', |
|
12
|
|
|
|
|
|
|
'find_product_list' => 'findProductList', |
|
13
|
|
|
|
|
|
|
'find_offer_list' => 'findOfferList', |
|
14
|
|
|
|
|
|
|
'top_products' => 'topProducts', |
|
15
|
|
|
|
|
|
|
'view_user_ratings' => 'viewUserRatings', |
|
16
|
|
|
|
|
|
|
'view_product_details' => 'viewProductDetails', |
|
17
|
|
|
|
|
|
|
'view_seller_details' => 'viewSellerDetails', |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
const our %COUNTRIES => ( |
|
21
|
|
|
|
|
|
|
'BR' => 'Brasil', |
|
22
|
|
|
|
|
|
|
'AR' => 'Argentina', |
|
23
|
|
|
|
|
|
|
'CO' => 'Colômbia', |
|
24
|
|
|
|
|
|
|
'CL' => 'Chile', |
|
25
|
|
|
|
|
|
|
'MX' => 'México', |
|
26
|
|
|
|
|
|
|
'PE' => 'Peru', |
|
27
|
|
|
|
|
|
|
'VE' => 'Venezuela', |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
const our %SERVICES => ( |
|
31
|
|
|
|
|
|
|
'business' => 'bws.buscape.com', |
|
32
|
|
|
|
|
|
|
'sandbox' => 'sandbox.buscape.com', |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has 'app_id' => ( |
|
36
|
|
|
|
|
|
|
'is' => 'ro', |
|
37
|
|
|
|
|
|
|
'required' => 1, |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'source_id' => ( |
|
41
|
|
|
|
|
|
|
'is' => 'ro', |
|
42
|
|
|
|
|
|
|
'required' => 1, |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has 'env' => ( |
|
46
|
|
|
|
|
|
|
'is' => 'ro', |
|
47
|
|
|
|
|
|
|
'isa' => sub { |
|
48
|
|
|
|
|
|
|
Carp::croak '"env" precisa ser "business" ou "sandbox"' |
|
49
|
|
|
|
|
|
|
unless $_[0] =~ m{business|sandbox}; |
|
50
|
|
|
|
|
|
|
}, |
|
51
|
|
|
|
|
|
|
'default' => sub { 'sandbox' }, |
|
52
|
|
|
|
|
|
|
'lazy' => 1, |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
); |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has 'country' => ( |
|
57
|
|
|
|
|
|
|
'is' => 'ro', |
|
58
|
|
|
|
|
|
|
'isa' => sub { |
|
59
|
|
|
|
|
|
|
my ($current) = @_; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my @keys = sort keys %COUNTRIES; |
|
62
|
|
|
|
|
|
|
my $values = join ', ', map { qq{"$_"} } @keys; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Carp::croak '"country" precisa ser um dos valores: ' . $values |
|
65
|
|
|
|
|
|
|
unless any { $_ eq $current } @keys; |
|
66
|
|
|
|
|
|
|
}, |
|
67
|
|
|
|
|
|
|
'default' => sub { 'BR' }, |
|
68
|
|
|
|
|
|
|
'lazy' => 1, |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
has 'service' => ( |
|
73
|
|
|
|
|
|
|
'is' => 'ro', |
|
74
|
|
|
|
|
|
|
'builder' => sub { $SERVICES{ shift->env }; }, |
|
75
|
|
|
|
|
|
|
'lazy' => 1, |
|
76
|
|
|
|
|
|
|
); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
has 'format' => ( |
|
79
|
|
|
|
|
|
|
'is' => 'ro', |
|
80
|
|
|
|
|
|
|
'lazy' => 1, |
|
81
|
|
|
|
|
|
|
'default' => sub { 'json' }, |
|
82
|
|
|
|
|
|
|
); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
has 'ua' => ( |
|
85
|
|
|
|
|
|
|
'is' => 'ro', |
|
86
|
|
|
|
|
|
|
'default' => sub { |
|
87
|
|
|
|
|
|
|
require LWP::UserAgent; |
|
88
|
|
|
|
|
|
|
return LWP::UserAgent->new; |
|
89
|
|
|
|
|
|
|
}, |
|
90
|
|
|
|
|
|
|
); |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub query { |
|
93
|
|
|
|
|
|
|
my ( $self, %args ) = @_; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $service = $self->service; |
|
96
|
|
|
|
|
|
|
my $method = $METHODS{ delete $args{method} }; |
|
97
|
|
|
|
|
|
|
my $app_id = $self->app_id; |
|
98
|
|
|
|
|
|
|
my $source_id = $self->source_id; |
|
99
|
|
|
|
|
|
|
my $country = $self->country; |
|
100
|
|
|
|
|
|
|
my $ua = $self->ua; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$args{'sourceId'} = $source_id; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $uri = URI->new("http://$service/service/$method/$app_id/$country"); |
|
105
|
|
|
|
|
|
|
$uri->query_form(%args); |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
return $ua->get($uri); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# ABSTRACT: Wrapper em torno da API do Buscape |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |