line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::ConstructorIO; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20613
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
44
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
832
|
use Moo; |
|
1
|
|
|
|
|
14838
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
with 'WebService::Client'; |
8
|
1
|
|
|
1
|
|
1654
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
61
|
|
9
|
1
|
|
|
1
|
|
1045
|
use Method::Signatures; |
|
1
|
|
|
|
|
80835
|
|
|
1
|
|
|
|
|
7
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
WebService::ConstructorIO - A Perl client for the Constructor.io API. Constructor.io provides a lightning-fast, typo-tolerant autocomplete service that ranks your users' queries by popularity to let them find what they're looking for as quickly as possible. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.01 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has api_token => ( is => 'ro', required => 1 ); |
24
|
|
|
|
|
|
|
has autocomplete_key => ( is => 'ro', required => 1 ); |
25
|
|
|
|
|
|
|
has host => ( is => 'ro', default => "dev.ac.cnstrc.com" ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has '+base_url' => ( is => 'ro', default => |
28
|
|
|
|
|
|
|
method { |
29
|
|
|
|
|
|
|
#'http://localhost:10000' |
30
|
|
|
|
|
|
|
'https://dev.ac.cnstrc.com' |
31
|
|
|
|
|
|
|
#'http://192.168.59.103:8006/' |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 SYNOPSIS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use WebService::ConstructorIO; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $constructorio = WebService::ConstructorIO->new(); |
40
|
|
|
|
|
|
|
$constructor_io->add(item_name => "item", autocomplete_section => "standard"); |
41
|
|
|
|
|
|
|
$constructor_io->modify(item_name => "item", new_item_name => "new item", |
42
|
|
|
|
|
|
|
autocomplete_section => "standard"); |
43
|
|
|
|
|
|
|
$constructor_io->remove(item_name => "new item"); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
1
|
|
|
1
|
|
163497
|
|
|
0
|
|
|
0
|
|
|
|
47
|
0
|
|
|
|
|
|
method BUILD(...) { |
48
|
0
|
|
|
|
|
|
$self->ua->default_headers->authorization_basic($self->api_token); |
49
|
|
|
|
|
|
|
$self->ua->ssl_opts( verify_hostname => 0 ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 METHODS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 add( item_name => $item_name, autocomplete_section => $autocomplete_section [, suggested_score => $suggested_score, keywords => $keywords, url => $url] ) |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
1
|
0
|
0
|
1
|
|
8814
|
|
|
0
|
0
|
0
|
0
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
method add(Str :$item_name!, Str :$autocomplete_section!, Int :$suggested_score, ArrayRef :$keywords, Str :$url) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $response = $self->post("/v1/item?autocomplete_key=" . $self->autocomplete_key, { |
60
|
|
|
|
|
|
|
item_name => $item_name, |
61
|
|
|
|
|
|
|
autocomplete_section => $autocomplete_section, |
62
|
|
|
|
|
|
|
($suggested_score ? (suggested_score => $suggested_score) : ()), |
63
|
|
|
|
|
|
|
($keywords ? (keywords => $keywords) : ()), |
64
|
|
|
|
|
|
|
($url ? (url => $url) : ()), |
65
|
|
|
|
|
|
|
}); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 remove( item_name => $item_name, autocomplete_section => $autocomplete_section ) |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
1
|
0
|
0
|
1
|
|
4541
|
|
|
0
|
0
|
0
|
0
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
method remove(Str :$item_name!, Str :$autocomplete_section!) { |
73
|
|
|
|
|
|
|
my $data = { |
74
|
|
|
|
|
|
|
item_name => $item_name, |
75
|
|
|
|
|
|
|
autocomplete_section => $autocomplete_section, |
76
|
0
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
my $path = "/v1/item?autocomplete_key=" . $self->autocomplete_key; |
78
|
0
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $headers = $self->_headers(\%args); |
80
|
0
|
|
|
|
|
|
my $url = $self->_url($path); |
81
|
|
|
|
|
|
|
my %content = $self->_content($data, %args); |
82
|
|
|
|
|
|
|
my $req = HTTP::Request->new( |
83
|
0
|
|
|
|
|
|
'DELETE', $url, [%$headers], $content{content} |
84
|
0
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
$self->req($req, %args); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 modiy( item_name => $item_name, new_item_name => $new_item_name, autocomplete_section => $autocomplete_section [, suggested_score => $suggested_score, keywords => $keywords, url => $url] ) |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
1
|
0
|
0
|
1
|
|
8944
|
|
|
0
|
0
|
0
|
0
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
method modify(Str :$item_name!, Str :$new_item_name!, Str :$autocomplete_section!, Int :$suggested_score, ArrayRef :$keywords, Str :$url) { |
93
|
|
|
|
|
|
|
my $response = $self->put("/v1/item?autocomplete_key=" . $self->autocomplete_key, { |
94
|
|
|
|
|
|
|
item_name => $item_name, |
95
|
|
|
|
|
|
|
new_item_name => $new_item_name, |
96
|
|
|
|
|
|
|
autocomplete_section => $autocomplete_section |
97
|
|
|
|
|
|
|
}); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 track_search( term => $term [, num_results => $num_results ] ) |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
1
|
0
|
0
|
1
|
|
4559
|
|
|
0
|
0
|
0
|
0
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
method track_search(Str :$term!, Str :$num_results) { |
105
|
|
|
|
|
|
|
my $response = $self->post("/v1/search?autocomplete_key=" . $self->autocomplete_key, { |
106
|
|
|
|
|
|
|
term => $term, |
107
|
|
|
|
|
|
|
($num_results ? (num_results => $num_results) : ()), |
108
|
|
|
|
|
|
|
}); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 track_click_through( term => $term, autocomplete_section => $autocomplete_section [, item => $item ] ) |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
1
|
0
|
0
|
1
|
|
5521
|
|
|
0
|
0
|
0
|
0
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
method track_click_through(Str :$term!, Str :$autocomplete_section!, Str :$item) { |
116
|
|
|
|
|
|
|
my $response = $self->post("/v1/search?autocomplete_key=" . $self->autocomplete_key, { |
117
|
|
|
|
|
|
|
term => $term, |
118
|
|
|
|
|
|
|
autocomplete_section => $autocomplete_section, |
119
|
|
|
|
|
|
|
($item ? (item => $item) : ()), |
120
|
|
|
|
|
|
|
}); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 track_conversion( term => $term, autocomplete_section => $autocomplete_section [, item => $item, revenue => $revenue ] ) |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
1
|
0
|
0
|
1
|
|
6493
|
|
|
0
|
0
|
0
|
0
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
method track_conversion(Str :$term!, Str :$autocomplete_section!, Str :$item, Int :$revenue) { |
|
|
0
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my $response = $self->post("/v1/search?autocomplete_key=" . $self->autocomplete_key, { |
129
|
|
|
|
|
|
|
term => $term, |
130
|
|
|
|
|
|
|
autocomplete_section => $autocomplete_section, |
131
|
|
|
|
|
|
|
($item ? (item => $item) : ()), |
132
|
|
|
|
|
|
|
($revenue ? (revenue => $revenue) : ()), |
133
|
|
|
|
|
|
|
}); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Dan McCormick, C<< <dan at constructor.io> >> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 BUGS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-webservice-constructorio at rt.cpan.org>, or through |
143
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WebService-ConstructorIO>. I will be notified, and then you'll |
144
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 SUPPORT |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
perldoc WebService::ConstructorIO |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
You can also look for information at: |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over 4 |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WebService-ConstructorIO> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L<http://annocpan.org/dist/WebService-ConstructorIO> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * CPAN Ratings |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/WebService-ConstructorIO> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * Search CPAN |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/WebService-ConstructorIO/> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=back |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Copyright 2015 Constructor.io |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
187
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
188
|
|
|
|
|
|
|
copy of the full license at: |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
L<http://www.perlfoundation.org/artistic_license_2_0> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
193
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
194
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
195
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
198
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
199
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
202
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
205
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
206
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
207
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
208
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
209
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
210
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
211
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
214
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
215
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
216
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
217
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
218
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
219
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
220
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
1; # End of WebService::ConstructorIO |