File Coverage

blib/lib/WebService/Yummly.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


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   1885 use strict;
  3         3  
  3         75  
6 3     3   9 use warnings;
  3         3  
  3         64  
7              
8 3     3   950 use URL::Encode;
  3         9206  
  3         101  
9 3     3   556 use WebService::Simple;
  0            
  0            
10             use Data::Dumper;
11              
12             our $VERSION = '1.3';
13              
14              
15             sub new {
16             my ($class, $APP_ID, $APP_KEY, $id) = @_ ;
17             my $obj = bless {}, $class ;
18              
19             my $string = "" ;
20             if (defined $id) {
21             $string = "recipe/$id" ;
22             }
23              
24             # Simple use case
25             $obj->{wss} = WebService::Simple->new
26             (
27             base_url => "http://api.yummly.com/v1/api/" . $string,
28             response_parser => 'JSON',
29             param =>
30             {
31             _app_id => $APP_ID,
32             _app_key => $APP_KEY,
33             }
34             );
35             return $obj ;
36             }
37              
38             sub search {
39             my ($self, $search) = @_;
40              
41             my $wss = $self->{wss};
42             my $ret = $wss->
43             get( "recipes", { q => $search } ) ;
44             my $json = $ret->parse_response;
45             return $json;
46             }
47              
48              
49             sub get_recipe {
50             my $self = shift;
51             my $wss = $self->{wss};
52             my $ret = $wss->get() ;
53             my $json = $ret->parse_response;
54             return $json;
55             }
56              
57             1;
58              
59             =pod
60              
61             =head1 NAME
62              
63             WebService::Yummly - Simple interface to the search and recipe interface to Yummly
64              
65             =head1 SYNOPSIS
66              
67             use WebService::Yummly;
68              
69             # use your ID/key here
70             my $APP_ID = "2f6cfcff";
71             my $APP_KEY = "a3cec319936cdf2fb03f4b0f5dfdaf4e";
72             my $y = WebService::Yummly->new($APP_ID, $APP_KEY);
73             my $recipes = $y->search("lamb shank");
74              
75             my $r = WebService::Yummly->new($APP_ID, $APP_KEY, "Sunday-Supper_-Curried-Lamb-Shanks-Serious-Eats-42000");
76             ok($r,"new yummly");
77              
78             my $recipe = $r->get_recipe ;
79              
80             =head1 DESCRIPTION
81              
82             Search and retrieve recipe from Yummly
83              
84             =head1 FUNCTIONS
85              
86             =head2 new
87              
88             my $y = WebService::Yummly->new($APP_ID, $APP_KEY);
89              
90             Create a new Yummly object passing in credentials.
91              
92             =head2 search
93              
94             $recipes = $y->search("lamb shank") ;
95              
96             Return a JSON structure containing matching recipes.
97              
98             =head2 get_recipe
99              
100             my $r = WebService::Yummly->new($APP_ID, $APP_KEY, "Sunday-Supper_-Curried-Lamb-Shanks-Serious-Eats-42000");
101             my $recipe = $r->get_recipe ;
102              
103             Return a JSON data structure with recipe information.
104              
105             =head1 DIAGNOSTICS
106              
107             =head1 SUPPORT
108              
109             =head2 BUGS
110              
111             Please report any bugs by email to C<bug-webservice-yummly at rt.cpan.org>, or
112             through the web interface at L<http://rt.cpan.org/Public/Dist/Display.html?Name=WebService-Yummly>.
113             You will be automatically notified of any progress on the request by the system.
114              
115             =head2 SOURCE CODE
116              
117             This is open source software. The code repository is available for public
118             review and contribution under the terms of the license.
119              
120             L<https://github.com/davehodg/Webservice-Yummly/>
121              
122             git clone https://github.com/davehodg/Webservice-Yummly
123              
124             =head1 AUTHOR
125              
126             Dave Hodgkinson C<davehodg@cpan.org>
127              
128             =head1 COPYRIGHT
129              
130             Copyright 2014 by Dave Hodgkinson
131              
132             This library is under the Artistic License.
133