1package Net::YAP;
2
3$VERSION = 0.6;
4
5use strict;
6use base qw(Net::OAuth::Simple);
7
8use JSON::Any;
9
10our $AUTH_URL = "https://api.login.yahoo.com/oauth/v2/request_auth";
11our $REQ_URL  = "https://api.login.yahoo.com/oauth/v2/get_request_token";
12our $ACC_URL  = "https://api.login.yahoo.com/oauth/v2/get_token";
13
14=head1 NAME
15
16Net::YAP - Module used as a conduit to communicate with the Yahoo!
17Application Platform
18
19=head1 FUNCTIONS
20
21=cut
22
23=head1 PUBLIC METHODS
24
25=head2 new
26
27Creates a new Net::YAP object. The following arguments must be passed
28to the constructor in order to ensure access is gained to the Yahoo! user's
29details (location, age, etc).
30
31  KEY                   VALUE
32  -----------           --------------------
33  consumer_key          This key is defined in the YAP dashboard
34  consumer_secret       This key is defined in the YAP dashboard
35  access_token          Contained in the incoming request arguments
36  access_token_secret   Contained in the incoming request arguments
37
38The consumer_key and consumer_secret are both unique to a YAP project.
39
40=cut
41
42sub new {
43	my $class  = shift;
44    my %tokens = @_;
45    return $class->SUPER::new( tokens => \%tokens,
46                               protocol_version => '1.0a',
47                               urls   => {
48                                        authorization_url => $AUTH_URL,
49                                        request_token_url => $REQ_URL,
50                                        access_token_url  => $ACC_URL,
51                               });
52}
53
54
55
56=head2 get_user_guid
57
58This method returns the guid of the Yahoo! user who has made a request to the
59YAP application.
60
61=cut
62
63
64sub get_user_guid {
65    my $self   = shift;
66    my %params = @_;
67    my $url    = URI->new('http://social.yahooapis.com/v1/me/guid');
68    my $res = $self->make_restricted_request("$url", 'GET', format => 'json');
69    my $data = eval { JSON::Any->new->from_json($res->content) };
70
71    return $data->{guid}->{value};
72}
73
74
75=head2 get_user_profile
76
77This method returns the profile data of the Yahoo! user who has made a request
78to the YAP application.
79
80The data is returned as a hash reference.
81
82=cut
83
84
85sub get_user_profile {
86    my $self   = shift;
87    my $guid = shift;
88    my %params = @_;
89    my $url = "http://social.yahooapis.com/v1/user/$guid/profile";
90    $url    = URI->new( $url );
91    my $res = $self->make_restricted_request("$url", 'GET', format => 'json');
92    my $data = eval { JSON::Any->new->from_json($res->content) };
93
94    return $data->{profile};
95}
96
97
98=head1 AUTHOR
99
100The code for this module is largely adapted from Simon Wistow's L<Net::FireEagle>.
101
102Rewritten and packaged by Alistair Francis <opensource@alizta.com>
103
104
105=head1 SEE ALSO
106
107L<Net::OAuth>, L<Net::OAuth::Simple>
108
109=cut
110
111
1121;
113