line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Launchpad; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1004
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
9852
|
|
|
1
|
|
|
|
|
12
|
|
4
|
1
|
|
|
1
|
|
1717
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
368053
|
|
|
1
|
|
|
|
|
17
|
|
5
|
1
|
|
|
1
|
|
54
|
use Mojo::JSON; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
6
|
1
|
|
|
1
|
|
7
|
use Mojo::URL; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
32
|
use Mojo::Parameters; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
8
|
|
|
|
|
|
|
use Function::Parameters { |
9
|
1
|
|
|
|
|
12
|
func => 'function_strict', |
10
|
|
|
|
|
|
|
method => 'method_strict' |
11
|
1
|
|
|
1
|
|
902
|
}; |
|
1
|
|
|
|
|
3291
|
|
12
|
|
|
|
|
|
|
our $VERSION = '1.0.1'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'staging' => 0; |
15
|
|
|
|
|
|
|
has 'consumer_key'; |
16
|
|
|
|
|
|
|
has 'callback_uri'; |
17
|
|
|
|
|
|
|
has 'json' => method { Mojo::JSON->new }; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'ua' => method { |
20
|
|
|
|
|
|
|
my $ua = Mojo::UserAgent->new; |
21
|
|
|
|
|
|
|
$ua->transactor->name("Net::Salesforce/$VERSION"); |
22
|
|
|
|
|
|
|
return $ua; |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 'nonce' => method { |
26
|
|
|
|
|
|
|
my @a = ('A' .. 'Z', 'a' .. 'z', 0 .. 9); |
27
|
|
|
|
|
|
|
my $nonce = ''; |
28
|
|
|
|
|
|
|
for (0 .. 31) { |
29
|
|
|
|
|
|
|
$nonce .= $a[rand(scalar(@a))]; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
return $nonce; |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has 'params' => method { |
35
|
|
|
|
|
|
|
return { |
36
|
|
|
|
|
|
|
oauth_callback => $self->callback_uri, |
37
|
|
|
|
|
|
|
oauth_consumer_key => $self->consumer_key, |
38
|
|
|
|
|
|
|
oauth_version => '1.0a', |
39
|
|
|
|
|
|
|
oauth_signature_method => 'PLAINTEXT', |
40
|
|
|
|
|
|
|
oauth_signature => '&', |
41
|
|
|
|
|
|
|
oauth_token => undef, |
42
|
|
|
|
|
|
|
oauth_token_secret => undef, |
43
|
|
|
|
|
|
|
oauth_timestamp => time, |
44
|
|
|
|
|
|
|
oauth_nonce => $self->nonce |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
0
|
1
|
|
method api_host { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
return Mojo::URL->new('https://launchpad.net/') unless $self->staging; |
50
|
0
|
|
|
|
|
|
return Mojo::URL->new('https://staging.launchpad.net'); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
0
|
1
|
|
method request_token_path { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $self->api_host->path('+request-token'); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
0
|
1
|
|
method access_token_path { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $self->api_host->path('+access-token'); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
0
|
1
|
|
method authorize_token_path { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $self->api_host->path('+authorize-token'); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
0
|
1
|
|
method request_token { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $tx = |
67
|
|
|
|
|
|
|
$self->ua->post( |
68
|
|
|
|
|
|
|
$self->request_token_path->to_string => form => $self->params); |
69
|
0
|
0
|
|
|
|
|
die $tx->res->body unless $tx->success; |
70
|
0
|
|
|
|
|
|
my $params = Mojo::Parameters->new($tx->res->body); |
71
|
0
|
|
|
|
|
|
my $token = $params->param('oauth_token'); |
72
|
0
|
|
|
|
|
|
my $secret = $params->param('oauth_token_secret'); |
73
|
0
|
|
|
|
|
|
return ($token, $secret); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
0
|
0
|
|
method authorize_token($token, $token_secret) { |
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$self->params->{oauth_token} = $token; |
78
|
0
|
|
|
|
|
|
$self->params->{oauth_token_secret} = $token_secret; |
79
|
0
|
|
|
|
|
|
my $url = $self->authorize_token_path->query($self->params); |
80
|
0
|
|
|
|
|
|
return $url->to_string; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
0
|
1
|
|
method access_token($token, $secret) { |
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$self->params->{oauth_token} = $token; |
85
|
0
|
|
|
|
|
|
$self->params->{oauth_token_secret} = $secret; |
86
|
0
|
|
|
|
|
|
$self->params->{oauth_signature} = |
87
|
|
|
|
|
|
|
'&' . $secret; |
88
|
0
|
|
|
|
|
|
my $tx = |
89
|
|
|
|
|
|
|
$self->ua->post( |
90
|
|
|
|
|
|
|
$self->access_token_path->to_string => form => $self->params); |
91
|
0
|
0
|
|
|
|
|
die $tx->res->body unless $tx->success; |
92
|
0
|
|
|
|
|
|
my $params = Mojo::Parameters->new($tx->res->body); |
93
|
0
|
|
|
|
|
|
return ($params->param('oauth_token'), $params->param('oauth_token_secret')); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |