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