line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package NetDNA; |
2
|
1
|
|
|
1
|
|
36469
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
75
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
647
|
use JSON; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Net::OAuth; |
6
|
|
|
|
|
|
|
use LWP::UserAgent; |
7
|
|
|
|
|
|
|
use URI; |
8
|
|
|
|
|
|
|
use Data::Dumper; |
9
|
|
|
|
|
|
|
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; |
10
|
|
|
|
|
|
|
my $base_url = "https://rws.netdna.com/"; |
11
|
|
|
|
|
|
|
my $debug; |
12
|
|
|
|
|
|
|
my $VERSION = '0.1'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
BEGIN { |
15
|
|
|
|
|
|
|
use Exporter (); |
16
|
|
|
|
|
|
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
17
|
|
|
|
|
|
|
$VERSION = '0.01'; |
18
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
19
|
|
|
|
|
|
|
#Give a hoot don't pollute, do not export more than needed by default |
20
|
|
|
|
|
|
|
@EXPORT = qw(); |
21
|
|
|
|
|
|
|
@EXPORT_OK = qw(); |
22
|
|
|
|
|
|
|
%EXPORT_TAGS = (); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#################### subroutine header begin #################### |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 sample_function |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Usage : How to use this function/method |
31
|
|
|
|
|
|
|
Purpose : What it does |
32
|
|
|
|
|
|
|
Returns : What it returns |
33
|
|
|
|
|
|
|
Argument : What it wants to know |
34
|
|
|
|
|
|
|
Throws : Exceptions and other anomolies |
35
|
|
|
|
|
|
|
Comment : This is a sample subroutine header. |
36
|
|
|
|
|
|
|
: It is polite to include more pod and fewer comments. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
See Also : |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#################### subroutine header end #################### |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Constructor |
45
|
|
|
|
|
|
|
sub new { |
46
|
|
|
|
|
|
|
my $class = shift; |
47
|
|
|
|
|
|
|
my $self = { |
48
|
|
|
|
|
|
|
_myalias => shift, |
49
|
|
|
|
|
|
|
_consumer_key => shift, |
50
|
|
|
|
|
|
|
_consumer_secret => shift, |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
# Print all the values just for clarification. |
53
|
|
|
|
|
|
|
#print "My Alias is $self->{_myalias}\n"; |
54
|
|
|
|
|
|
|
#print "My Consumer Key is $self->{_consumer_key}\n"; |
55
|
|
|
|
|
|
|
#print "My Consumer Secret is $self->{_consumer_secret}\n"; |
56
|
|
|
|
|
|
|
bless $self, $class; |
57
|
|
|
|
|
|
|
return $self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Set the Alias |
61
|
|
|
|
|
|
|
sub setAlias { |
62
|
|
|
|
|
|
|
my ( $self, $alias ) = @_; |
63
|
|
|
|
|
|
|
$self->{_myalias} = $alias if defined($alias); |
64
|
|
|
|
|
|
|
return $self->{_myalias}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Set the Consumer Key |
68
|
|
|
|
|
|
|
sub setKey { |
69
|
|
|
|
|
|
|
my ( $self, $alias ) = @_; |
70
|
|
|
|
|
|
|
$self->{_myalias} = $alias if defined($alias); |
71
|
|
|
|
|
|
|
return $self->{_consumer_key}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Set the Consumer Secret |
75
|
|
|
|
|
|
|
sub setSecret { |
76
|
|
|
|
|
|
|
my ( $self, $secret ) = @_; |
77
|
|
|
|
|
|
|
$self->{_myalias} = $secret if defined($secret); |
78
|
|
|
|
|
|
|
return $self->{_consumer_secret}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Get the Alias |
82
|
|
|
|
|
|
|
sub getAlias { |
83
|
|
|
|
|
|
|
my( $self ) = @_; |
84
|
|
|
|
|
|
|
return $self->{_myalias}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Get the Consumer Key |
88
|
|
|
|
|
|
|
sub getKey { |
89
|
|
|
|
|
|
|
my( $self ) = @_; |
90
|
|
|
|
|
|
|
return $self->{_consumer_key}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Get the Consumer Secret |
94
|
|
|
|
|
|
|
sub getSecret { |
95
|
|
|
|
|
|
|
my( $self ) = @_; |
96
|
|
|
|
|
|
|
return $self->{_consumer_secret}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Override helper function |
100
|
|
|
|
|
|
|
sub get { |
101
|
|
|
|
|
|
|
my( $self, $address, $debug ) = @_; |
102
|
|
|
|
|
|
|
$address = $base_url . $self->{_myalias} . $address; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
if($debug){ |
105
|
|
|
|
|
|
|
print "Making GET request to " . $address . "\n"; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $url = shift; |
109
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Create request |
112
|
|
|
|
|
|
|
my $request = Net::OAuth->request("request token")->new( |
113
|
|
|
|
|
|
|
consumer_key => $self->{_consumer_key}, |
114
|
|
|
|
|
|
|
consumer_secret => $self->{_consumer_secret}, |
115
|
|
|
|
|
|
|
request_url => $address, |
116
|
|
|
|
|
|
|
request_method => 'GET', |
117
|
|
|
|
|
|
|
signature_method => 'HMAC-SHA1', |
118
|
|
|
|
|
|
|
timestamp => time, |
119
|
|
|
|
|
|
|
nonce => '', |
120
|
|
|
|
|
|
|
callback => '', |
121
|
|
|
|
|
|
|
); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Sign request |
124
|
|
|
|
|
|
|
$request->sign; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Get message to the Service Provider |
127
|
|
|
|
|
|
|
my $res = $ua->get($request->to_url); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Decode JSON |
130
|
|
|
|
|
|
|
my $decoded_json = decode_json($res->content); |
131
|
|
|
|
|
|
|
if($decoded_json->{code} == 200) { |
132
|
|
|
|
|
|
|
if($debug){ |
133
|
|
|
|
|
|
|
print Dumper $decoded_json->{data}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
return $decoded_json->{data}; |
136
|
|
|
|
|
|
|
} else { |
137
|
|
|
|
|
|
|
if($debug){ |
138
|
|
|
|
|
|
|
print Dumper $decoded_json->{error}; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
return $decoded_json->{error}; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
#################### main pod documentation begin ################### |
148
|
|
|
|
|
|
|
## Below is the stub of documentation for your module. |
149
|
|
|
|
|
|
|
## You better edit it! |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 NAME |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
NetDNA - Login and access information on NetDNA's Rest Interface |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 SYNOPSIS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
use NetDNA; |
159
|
|
|
|
|
|
|
blah blah blah |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 DESCRIPTION |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Stub documentation for this module was created by ExtUtils::ModuleMaker. |
165
|
|
|
|
|
|
|
It looks like the author of the extension was negligent enough |
166
|
|
|
|
|
|
|
to leave the stub unedited. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Blah blah blah. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 USAGE |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 BUGS |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 SUPPORT |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 AUTHOR |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Michael Bastos |
186
|
|
|
|
|
|
|
CPAN ID: MBASTOS |
187
|
|
|
|
|
|
|
NetDNA |
188
|
|
|
|
|
|
|
bastosmichael@gmail.com |
189
|
|
|
|
|
|
|
https://github.com/netdna/ |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 COPYRIGHT |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
This program is free software; you can redistribute |
194
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
The full text of the license can be found in the |
197
|
|
|
|
|
|
|
LICENSE file included with this module. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 SEE ALSO |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
perl(1). |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
#################### main pod documentation end ################### |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
1; |
210
|
|
|
|
|
|
|
# The preceding line will help the module return a true value |
211
|
|
|
|
|
|
|
|