line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Launchpad::Client; |
2
|
|
|
|
|
|
|
# ABSTRACT: Launchpad.net Client |
3
|
|
|
|
|
|
|
$Net::Launchpad::Client::VERSION = '1.03'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
15567
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
6858
|
|
|
1
|
|
|
|
|
6
|
|
6
|
1
|
|
|
1
|
|
602
|
use Mojo::JSON; |
|
1
|
|
|
|
|
41228
|
|
|
1
|
|
|
|
|
44
|
|
7
|
1
|
|
|
1
|
|
498
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
174532
|
|
|
1
|
|
|
|
|
10
|
|
8
|
1
|
|
|
1
|
|
33
|
use Mojo::Parameters; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
9
|
1
|
|
|
1
|
|
605
|
use Class::Load ':all'; |
|
1
|
|
|
|
|
22036
|
|
|
1
|
|
|
|
|
827
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'consumer_key' => ''; |
12
|
|
|
|
|
|
|
has 'access_token' => ''; |
13
|
|
|
|
|
|
|
has 'access_token_secret' => ''; |
14
|
|
|
|
|
|
|
has 'staging' => 0; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'json' => sub { |
17
|
|
|
|
|
|
|
my $self = shift; |
18
|
|
|
|
|
|
|
return Mojo::JSON->new; |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'ua' => sub { |
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
my $ua = Mojo::UserAgent->new; |
24
|
|
|
|
|
|
|
$ua->transactor->name("Net::Launchpad/0.99"); |
25
|
|
|
|
|
|
|
return $ua; |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has 'nonce' => sub { |
29
|
|
|
|
|
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
my @a = ('A' .. 'Z', 'a' .. 'z', 0 .. 9); |
31
|
|
|
|
|
|
|
my $nonce = ''; |
32
|
|
|
|
|
|
|
for (0 .. 31) { |
33
|
|
|
|
|
|
|
$nonce .= $a[rand(scalar(@a))]; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
return $nonce; |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has 'authorization_header' => sub { |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
return join(",", |
41
|
|
|
|
|
|
|
'OAuth realm="https://api.launchpad.net"', |
42
|
|
|
|
|
|
|
'oauth_consumer_key=' . $self->consumer_key, |
43
|
|
|
|
|
|
|
'oauth_version=1.0', |
44
|
|
|
|
|
|
|
'oauth_signature_method=PLAINTEXT', |
45
|
|
|
|
|
|
|
'oauth_signature=' . '&' . $self->access_token_secret, |
46
|
|
|
|
|
|
|
'oauth_token=' . $self->access_token, |
47
|
|
|
|
|
|
|
'oauth_token_secret=' . $self->access_token_secret, |
48
|
|
|
|
|
|
|
'oauth_timestamp=' . time, |
49
|
|
|
|
|
|
|
'oauth_nonce=' . $self->nonce); |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub api_url { |
53
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
54
|
0
|
0
|
|
|
|
|
if ($self->staging) { |
55
|
0
|
|
|
|
|
|
return Mojo::URL->new('https://api.staging.launchpad.net/1.0/'); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
0
|
|
|
|
|
|
return Mojo::URL->new('https://api.launchpad.net/1.0/'); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub model { |
63
|
0
|
|
|
0
|
0
|
|
my ($self, $class) = @_; |
64
|
0
|
|
|
|
|
|
my $model = "Net::Launchpad::Model::$class"; |
65
|
0
|
|
|
|
|
|
return load_class($model)->new($self); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub __path_cons { |
69
|
0
|
|
|
0
|
|
|
my ($self, $path) = @_; |
70
|
0
|
0
|
|
|
|
|
if ($path =~ /^http.*api/) { |
71
|
0
|
|
|
|
|
|
return Mojo::URL->new($path); |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
return $self->api_url->path($path); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub get { |
77
|
0
|
|
|
0
|
1
|
|
my ($self, $resource) = @_; |
78
|
0
|
|
|
|
|
|
my $uri = $self->__path_cons($resource); |
79
|
0
|
|
|
|
|
|
my $tx = |
80
|
|
|
|
|
|
|
$self->ua->get( |
81
|
|
|
|
|
|
|
$uri->to_string => {'Authorization' => $self->authorization_header}); |
82
|
0
|
0
|
|
|
|
|
die $tx->res->body unless $tx->success; |
83
|
0
|
|
|
|
|
|
return $self->json->decode($tx->res->body); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub post { |
87
|
0
|
|
|
0
|
1
|
|
my ($self, $resource, $params) = @_; |
88
|
0
|
|
|
|
|
|
my $params_hash = Mojo::Parameters->new($params); |
89
|
0
|
|
|
|
|
|
my $uri = $self->__path_cons($resource); |
90
|
0
|
|
|
|
|
|
my $tx = |
91
|
|
|
|
|
|
|
$self->ua->post($uri->to_string => |
92
|
|
|
|
|
|
|
{'Authorization' => $self->authorization_header} => form => |
93
|
|
|
|
|
|
|
$params_hash->to_string); |
94
|
0
|
0
|
|
|
|
|
die $tx->res->message unless $tx->success; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |