line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Riya; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
54868
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
74
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
65
|
|
5
|
2
|
|
|
2
|
|
10
|
use base qw(Class::Accessor::Fast); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
1885
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
23486
|
use HTTP::Request::Common; |
|
2
|
|
|
|
|
94669
|
|
|
2
|
|
|
|
|
171
|
|
8
|
2
|
|
|
2
|
|
2198
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
61267
|
|
|
2
|
|
|
|
|
70
|
|
9
|
2
|
|
|
2
|
|
21
|
use URI; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
44
|
|
10
|
2
|
|
|
2
|
|
1816
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $API_ROOT = 'http://www.riya.com/rest'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/user_name password api_key errstr status debug/); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
|
|
|
|
|
|
my($class, %opt) = @_; |
20
|
|
|
|
|
|
|
my $self = bless { |
21
|
|
|
|
|
|
|
user_name => $opt{user_name}, |
22
|
|
|
|
|
|
|
password => $opt{password}, |
23
|
|
|
|
|
|
|
api_key => $opt{api_key}, |
24
|
|
|
|
|
|
|
}, $class; |
25
|
|
|
|
|
|
|
$self->{ua} = LWP::UserAgent->new; |
26
|
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get_auth_token { |
30
|
|
|
|
|
|
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return $self->{token} if $self->{token}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $uri = URI->new($API_ROOT); |
35
|
|
|
|
|
|
|
$uri->query_form( |
36
|
|
|
|
|
|
|
user_name => $self->user_name, |
37
|
|
|
|
|
|
|
password => $self->password, |
38
|
|
|
|
|
|
|
api_key => $self->api_key, |
39
|
|
|
|
|
|
|
method => 'riya.auth.GetToken', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
my $response = $self->{ua}->get($uri->as_string); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $xml = XML::LibXML->new(); |
44
|
|
|
|
|
|
|
my $doc = $xml->parse_string($response->content); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->{token} = $doc->findvalue("//*[local-name()='token']"); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$self->errstr($doc->findvalue("//*[local-name()='error']/\@code")) |
49
|
|
|
|
|
|
|
unless $self->{token}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return $self->{token}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub call_method { |
55
|
|
|
|
|
|
|
my($self, $method, $opt) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $uri = URI->new($API_ROOT); |
58
|
|
|
|
|
|
|
my $req_param; |
59
|
|
|
|
|
|
|
$opt->{user_name} = $self->user_name; |
60
|
|
|
|
|
|
|
$opt->{password} = $self->password; |
61
|
|
|
|
|
|
|
$opt->{api_key} = $self->api_key; |
62
|
|
|
|
|
|
|
$opt->{auth_token} = $self->get_auth_token(); |
63
|
|
|
|
|
|
|
$opt->{method} = $method; |
64
|
|
|
|
|
|
|
if (lc $method eq 'riya.photos.upload.uploadphoto') { |
65
|
|
|
|
|
|
|
$req_param = POST($API_ROOT, Content_Type => 'form-data', Content => [%$opt]); |
66
|
|
|
|
|
|
|
} else { |
67
|
|
|
|
|
|
|
$uri->query_form($opt); |
68
|
|
|
|
|
|
|
$req_param = GET($uri->as_string); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
my $response = $self->{ua}->request($req_param); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
warn $uri->as_string if $self->debug; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
return '' unless $response->content; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $xml = XML::LibXML->new(); |
77
|
|
|
|
|
|
|
my $doc = $xml->parse_string($response->content); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$self->errstr($doc->findvalue("//*[local-name()='error']/\@code")); |
80
|
|
|
|
|
|
|
$self->status($self->errstr() ? 0 : 1); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
return $response->content; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
__END__ |