line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SMS::CDYNE; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
786
|
use 5.008_001; |
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.14'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
775
|
use Any::Moose; |
|
1
|
|
|
|
|
35724
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
577
|
use Any::Moose 'X::NonMoose'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
11403
|
use XML::Simple; |
|
1
|
|
|
|
|
13910
|
|
|
1
|
|
|
|
|
11
|
|
9
|
1
|
|
|
1
|
|
117
|
use Carp qw/croak cluck/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
65
|
|
10
|
1
|
|
|
1
|
|
782
|
use Net::SMS::CDYNE::Response; |
|
1
|
|
|
|
|
101
|
|
|
1
|
|
|
|
|
549
|
|
11
|
1
|
|
|
1
|
|
2897
|
use Encode; |
|
1
|
|
|
|
|
16323
|
|
|
1
|
|
|
|
|
1933
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
extends 'REST::Client'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'debug' => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
isa => 'Bool', |
18
|
|
|
|
|
|
|
default => 0, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'api_key' => ( |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
isa => 'Str', |
24
|
|
|
|
|
|
|
required => 1, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub do_cdyne_request { |
28
|
0
|
|
|
0
|
0
|
|
my ($self, $method, $uri, $args, $body) = @_; |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
croak "URI is required" unless $uri; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
0
|
|
|
|
$args ||= {}; |
33
|
0
|
|
0
|
|
|
|
$args->{LicenseKey} ||= $self->api_key; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# build request |
36
|
0
|
|
|
|
|
|
my $headers = {}; |
37
|
0
|
0
|
0
|
|
|
|
my $args_encoded = $args && %$args ? $self->buildQuery($args) : ''; |
38
|
0
|
|
|
|
|
|
$args_encoded =~ s/^(\?)//; |
39
|
0
|
0
|
|
|
|
|
if (lc $method eq 'get') { |
40
|
0
|
|
|
|
|
|
$uri .= '?' . $args_encoded; |
41
|
|
|
|
|
|
|
} else { |
42
|
0
|
|
|
|
|
|
$headers->{'Content-Type'} = 'text/xml'; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# encode body |
46
|
0
|
0
|
|
|
|
|
$body = encode_utf8($body) |
47
|
|
|
|
|
|
|
if defined $body; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
warn "Request: $uri\n" if $self->debug; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$self->request($method, $uri, $body, $headers); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $response_code = $self->responseCode; |
54
|
0
|
|
|
|
|
|
my $content = $self->responseContent; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
0
|
|
|
|
if (! $response_code || index($response_code, '2') != 0) { |
57
|
0
|
|
|
|
|
|
warn "CDYNEv2 request ($uri) failed with code $response_code: " . $content . |
58
|
|
|
|
|
|
|
"\n\nRequest body was: $body\n"; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# return empty response |
61
|
0
|
|
|
|
|
|
return Net::SMS::CDYNE::Response->new(response_code => $response_code); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
warn "\nResponse: $content\n" if $self->debug; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# attempt to parse response XML |
67
|
0
|
|
|
|
|
|
my $resp_obj = eval { XMLin($content) }; |
|
0
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
warn "Failed parsing response: $content ($@)" unless $resp_obj; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# if we do an advanced send, we get an array of responses. |
71
|
|
|
|
|
|
|
# since we only handle sending one message at a time, we can just grab the first response. |
72
|
0
|
0
|
|
|
|
|
$resp_obj = $resp_obj->{SMSResponse} if $resp_obj->{SMSResponse}; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $ret = { |
75
|
|
|
|
|
|
|
response_code => $response_code, |
76
|
|
|
|
|
|
|
%$resp_obj, |
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return bless $ret, 'Net::SMS::CDYNE::Response'; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# takes a phone number, returns a structure of info |
83
|
|
|
|
|
|
|
sub phone_verify { |
84
|
0
|
|
|
0
|
0
|
|
my ($self, $phone_number) = @_; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $uri = 'http://ws.cdyne.com/phoneverify/phoneverify.asmx/CheckPhoneNumber'; |
87
|
0
|
|
|
|
|
|
return $self->do_cdyne_request('GET', $uri, { PhoneNumber => $phone_number }); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
# $ curl 'http://ws.cdyne.com/phoneverify/phoneverify.asmx/CheckPhoneNumber?PhoneNumber=17575449510&LicenseKey=XXXXX' |
90
|
|
|
|
|
|
|
# |
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
# LEVEL 3 COMM - VA |
93
|
|
|
|
|
|
|
# true |
94
|
|
|
|
|
|
|
# |
95
|
|
|
|
|
|
|
# VA |
96
|
|
|
|
|
|
|
# NRFOLKZON2 |
97
|
|
|
|
|
|
|
# 8825 |
98
|
|
|
|
|
|
|
# 17575449510 |
99
|
|
|
|
|
|
|
# 7575449510 |
100
|
|
|
|
|
|
|
# CHSKVAAY0MD |
101
|
|
|
|
|
|
|
# |
102
|
|
|
|
|
|
|
# United States |
103
|
|
|
|
|
|
|
# CHSKVAAYDS0 |
104
|
|
|
|
|
|
|
# CLEC - (Competitive Local Exchange Carrier) |
105
|
|
|
|
|
|
|
# 252 |
106
|
|
|
|
|
|
|
# CLEC - (Competitive Local Exchange Carrier) |
107
|
|
|
|
|
|
|
# |
108
|
|
|
|
|
|
|
# 05/24/2001 |
109
|
|
|
|
|
|
|
# PARKSLEY |
110
|
|
|
|
|
|
|
# |
111
|
|
|
|
|
|
|
# VA |
112
|
|
|
|
|
|
|
# 23421 |
113
|
|
|
|
|
|
|
# EST |
114
|
|
|
|
|
|
|
# 37.7790 |
115
|
|
|
|
|
|
|
# -75.6343 |
116
|
|
|
|
|
|
|
# false |
117
|
|
|
|
|
|
|
# 7576559199 |
118
|
|
|
|
|
|
|
# |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub simple_sms_send_with_postback { |
121
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
my $uri = 'https://sms2.cdyne.com/sms.svc/SecureREST/SimpleSMSsendWithPostback'; |
124
|
0
|
|
|
|
|
|
return $self->do_cdyne_request('GET', $uri, \%args); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub simple_sms_send { |
128
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
my $uri = 'https://sms2.cdyne.com/sms.svc/SecureREST/SimpleSMSsend'; |
131
|
0
|
|
|
|
|
|
return $self->do_cdyne_request('GET', $uri, \%args); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# takes AssignedDID |
135
|
|
|
|
|
|
|
sub advanced_sms_send { |
136
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
my $uri = 'https://sms2.cdyne.com/sms.svc/SecureREST/AdvancedSMSsend'; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
0
|
|
|
|
$args{LicenseKey} ||= $self->api_key; |
141
|
0
|
|
|
|
|
|
my $nums = delete $args{PhoneNumbers}; |
142
|
0
|
0
|
|
|
|
|
$nums = [delete $args{PhoneNumber}] if $args{PhoneNumber}; |
143
|
0
|
|
0
|
|
|
|
my $refid = delete $args{ReferenceID} || ''; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
my @subdoc = (); |
146
|
0
|
|
|
|
|
|
foreach my $num (@$nums){ |
147
|
0
|
|
|
|
|
|
push(@subdoc, |
148
|
|
|
|
|
|
|
{ |
149
|
|
|
|
|
|
|
string => [ |
150
|
|
|
|
|
|
|
{ |
151
|
|
|
|
|
|
|
xmlns => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays', |
152
|
|
|
|
|
|
|
content => $num, |
153
|
|
|
|
|
|
|
}, |
154
|
|
|
|
|
|
|
] |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $doc = { |
160
|
|
|
|
|
|
|
SMSAdvancedRequest => { |
161
|
|
|
|
|
|
|
xmlns => 'http://schemas.datacontract.org/2004/07/SmsWS', |
162
|
|
|
|
|
|
|
LicenseKey => [ delete $args{LicenseKey} ], |
163
|
|
|
|
|
|
|
SMSRequests => [ |
164
|
|
|
|
|
|
|
{ |
165
|
|
|
|
|
|
|
SMSRequest => [ |
166
|
|
|
|
|
|
|
{ |
167
|
|
|
|
|
|
|
xmlns => "http://sms2.cdyne.com", |
168
|
|
|
|
|
|
|
Message => [ delete $args{Message} ], |
169
|
|
|
|
|
|
|
AssignedDID => [ delete $args{AssignedDID} ], |
170
|
0
|
|
|
|
|
|
StatusPostBackURL => [ delete $args{StatusPostBackURL} ], |
171
|
|
|
|
|
|
|
ReferenceID => [ $refid ], |
172
|
|
|
|
|
|
|
PhoneNumbers => \@subdoc |
173
|
|
|
|
|
|
|
}, |
174
|
|
|
|
|
|
|
], |
175
|
|
|
|
|
|
|
}, |
176
|
|
|
|
|
|
|
], |
177
|
|
|
|
|
|
|
}, |
178
|
|
|
|
|
|
|
}; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
my $body = XML::Simple::XMLout($doc, KeepRoot => 1, ContentKey => 'content'); |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
return $self->do_cdyne_request('POST', $uri, \%args, $body); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub get_unread_incoming_messages { |
186
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
my $uri = 'https://sms2.cdyne.com/sms.svc/SecureREST/GetUnreadIncomingMessages'; |
189
|
0
|
|
|
|
|
|
return $self->do_cdyne_request('GET', $uri, \%args); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub get_message_status_by_reference_id { |
193
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
my $uri = 'https://sms2.cdyne.com/sms.svc/SecureREST/GetMessageStatusByReferenceID'; |
196
|
0
|
|
|
|
|
|
return $self->do_cdyne_request('GET', $uri, \%args); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub get_message_status { |
200
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
my $uri = 'https://sms2.cdyne.com/sms.svc/SecureREST/GetMessageStatus'; |
203
|
0
|
|
|
|
|
|
return $self->do_cdyne_request('GET', $uri, \%args); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub cancel_message { |
207
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
my $uri = 'https://sms2.cdyne.com/sms.svc/SecureREST/CancelMessage'; |
210
|
0
|
|
|
|
|
|
return $self->do_cdyne_request('GET', $uri, \%args); |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
1; |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
__END__ |