| 1 | package Net::YAP; | ||
| 2 | |||
| 3 | $VERSION = 0.6; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use base qw(Net::OAuth::Simple); | ||
| 7 | |||
| 8 | use JSON::Any; | ||
| 9 | |||
| 10 | our $AUTH_URL = "https://api.login.yahoo.com/oauth/v2/request_auth"; | ||
| 11 | our $REQ_URL = "https://api.login.yahoo.com/oauth/v2/get_request_token"; | ||
| 12 | our $ACC_URL = "https://api.login.yahoo.com/oauth/v2/get_token"; | ||
| 13 | |||
| 14 | =head1 NAME | ||
| 15 | |||
| 16 | Net::YAP - Module used as a conduit to communicate with the Yahoo! | ||
| 17 | Application Platform | ||
| 18 | |||
| 19 | =head1 FUNCTIONS | ||
| 20 | |||
| 21 | =cut | ||
| 22 | |||
| 23 | =head1 PUBLIC METHODS | ||
| 24 | |||
| 25 | =head2 new | ||
| 26 | |||
| 27 | Creates a new Net::YAP object. The following arguments must be passed | ||
| 28 | to the constructor in order to ensure access is gained to the Yahoo! user's | ||
| 29 | details (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 | |||
| 38 | The consumer_key and consumer_secret are both unique to a YAP project. | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | sub 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 | |||
| 58 | This method returns the guid of the Yahoo! user who has made a request to the | ||
| 59 | YAP application. | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | |||
| 64 | sub 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 | |||
| 77 | This method returns the profile data of the Yahoo! user who has made a request | ||
| 78 | to the YAP application. | ||
| 79 | |||
| 80 | The data is returned as a hash reference. | ||
| 81 | |||
| 82 | =cut | ||
| 83 | |||
| 84 | |||
| 85 | sub 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 | |||
| 100 | The code for this module is largely adapted from Simon Wistow's L<Net::FireEagle>. | ||
| 101 | |||
| 102 | Rewritten and packaged by Alistair Francis <opensource@alizta.com> | ||
| 103 | |||
| 104 | |||
| 105 | =head1 SEE ALSO | ||
| 106 | |||
| 107 | L<Net::OAuth>, L<Net::OAuth::Simple> | ||
| 108 | |||
| 109 | =cut | ||
| 110 | |||
| 111 | |||
| 112 | 1; |