line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Yummly; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: get search and get a recipe from Yummly |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
3994
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
100
|
|
6
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
90
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
2169
|
use URL::Encode; |
|
3
|
|
|
|
|
15588
|
|
|
3
|
|
|
|
|
129
|
|
9
|
3
|
|
|
3
|
|
1366
|
use WebService::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Data::Dumper; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
|
|
|
|
|
|
my ($class, $APP_ID, $APP_KEY, $id) = @_ ; |
16
|
|
|
|
|
|
|
my $obj = bless {}, $class ; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $string = "" ; |
19
|
|
|
|
|
|
|
if (defined $id) { |
20
|
|
|
|
|
|
|
$string = "recipe/$id" ; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Simple use case |
24
|
|
|
|
|
|
|
$obj->{wss} = WebService::Simple->new |
25
|
|
|
|
|
|
|
( |
26
|
|
|
|
|
|
|
base_url => "http://api.yummly.com/v1/api/" . $string, |
27
|
|
|
|
|
|
|
response_parser => 'JSON', |
28
|
|
|
|
|
|
|
param => |
29
|
|
|
|
|
|
|
{ |
30
|
|
|
|
|
|
|
_app_id => $APP_ID, |
31
|
|
|
|
|
|
|
_app_key => $APP_KEY, |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
return $obj ; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub search { |
38
|
|
|
|
|
|
|
my ($self, $search) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $wss = $self->{wss}; |
41
|
|
|
|
|
|
|
my $ret = $wss-> |
42
|
|
|
|
|
|
|
get( "recipes", { q => $search } ) ; |
43
|
|
|
|
|
|
|
my $json = $ret->parse_response; |
44
|
|
|
|
|
|
|
return $json; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_recipe { |
49
|
|
|
|
|
|
|
my $self = shift; |
50
|
|
|
|
|
|
|
my $wss = $self->{wss}; |
51
|
|
|
|
|
|
|
my $ret = $wss->get() ; |
52
|
|
|
|
|
|
|
my $json = $ret->parse_response; |
53
|
|
|
|
|
|
|
return $json; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |