blib/lib/WWW/TextMarks.pm

filter: Statementstmt 39.0% 16 / 41 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 36.5% 23 / 63 CC 5 SCAR 21.8
CC
5
Cov
32%
send
20.0
new
6.0
BEGIN
1.0
CRAP 8.8
↑ Summary
1 package WWW::TextMarks;
2  
3 1 ▶use 5.008000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use LWP::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '0.01';
10  
11 =head1 NAME
12  
13 WWW::TextMarks - Provides access to the TextMarks SMS Service V2 API
14  
15 =head1 SYNOPSIS
16  
17 use WWW::TextMarks;
18 my $tm = WWW::TextMarks->new(
19 apik => 'example_com_12345678',
20 user => '5556781234',
21 pass => 'y0ur$ekretPassword',
22 tm => 'yourtextmark',
23 );
24 my $res = $tm->send('5559994321', 'Hey, pick up your dry cleaning.');
25 if ($res->{success})
26 {
27 print "Yippie.\n";
28 }
29 else
30 {
31 print "Error: $res->{error}\n";
32 }
33  
34 =head1 DESCRIPTION
35  
36 WWW::TextMarks provides access to the TextMarks SMS Service V2 API.
37  
38 Currently, it only allows you to send text messages to individual subscribers.
39 Eventually, it'll also allow you to maintain your subscriber list and perform
40 the full set of tasks made available by the TextMarks API.
41  
42 Patches are welcome in case you get to it before I do. :-)
43  
44 =head1 METHODS
45  
46 =head2 new
47  
48 See SYNOPSIS above for an example.
49  
50 Required: apik, user, pass, tm.
51 Optional: url
52  
53 Setting the C<url> is not recommended unless the embedded URL in this module
54 fails to work properly or if you require an alternate URL provided by TextMarks.
55  
56 The C<apik> is created by registering for an API key at:
57 L<http://www.textmarks.com/dev/api/reg/?ref=devapi>
58  
59 The C<user> and C<pass> is your TextMarks website login username and password.
60 Your username is most likely your cell phone number.
61  
62 =cut
63  
64 sub new
65 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
66 0 my $self = bless({}, shift);
67 0 my %opts = @_;
68 0 ▶ $self->{url} = $opts{url} || 'http://dev1.api.textmarks.com/Messaging/sendText/?apik=%%apik%%&auth_user=%%user%%&auth_pass=%%pass%%&tm=%%tm%%&to=%%phone%%&msg=%%message%%';
Condition0%0/2
$opts{'url'} || 'http://dev1.api.textmarks.com/Messaging/sendText/?apik=%%apik%%&auth_user=%%user%%&auth_pass=%%pass%%&tm=%%tm%%&to=%%phone%%&msg=%%message%%'
l!l
00
MC/DC0%0/1
$opts{'url'} || 'http://dev1.api.textmarks.com/Messaging/sendText/?apik=%%apik%%&auth_user=%%user%%&auth_pass=%%pass%%&tm=%%tm%%&to=%%phone%%&msg=%%message%%'
$opts{'url'}
Truth table0%0/2
A
A= $opts{'url'}
Aresult
11
00
69 0 $self->{apik} = $opts{apik}; # http://www.textmarks.com/dev/api/reg/?ref=devapi
70 0 $self->{user} = $opts{user}; # textmarks username
71 0 $self->{pass} = $opts{pass}; # textmarks password
72 0 $self->{tm} = $opts{tm}; # textmark
73 0 return $self;
74 }
75  
76 =head2 send
77  
78 See SYNOPSIS above for an example.
79  
80 The first argument is the SMS recipient's phone number. The second argument is
81 the message to send. There are no other arguments.
82  
83 If you wish to send to many recipients, just call C<send> multiple times, once
84 per recipient.
85  
86 =cut
87  
88 sub send
89 0 ▶{
Subroutine send: not called CC=4 SCAR=30.0
Pod documented
90 0 my $self = shift;
91 0 my $phone = shift;
92 0 my $message = shift;
93 0 $message =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
94 0 my $url = $self->{url};
95 0 ▶ $url =~ s/(%%([^%]+)%%)/$self->{$2}||$1/eg;
Condition0%0/3
$self->{$2} || $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{$2} || $1
$self->{$2} $1
Truth table0%0/3
A || B
A= $self->{$2}B= $1
ABresult
1X1
011
000
96 0 $url =~ s/%%phone%%/$phone/g;
97 0 $url =~ s/%%message%%/$message/g;
98 0 my $response = get($url);
99 0 my $resxml = {
100 error => 'Response parser error',
101 response => $response,
102 };
103 eval
104 0 {
105 0 $resxml = XMLin($response);
106 };
107 0 ▶ $resxml->{success} = ($resxml->{TMHead}->{ResMsg} eq 'Success' || 0);
Condition0%0/2
$resxml->{'TMHead'}{'ResMsg'} eq 'Success' || 0
l!l
00
MC/DC0%0/1
$resxml->{'TMHead'}{'ResMsg'} eq 'Success' || 0
$resxml->{'TMHead'}{'ResMsg'} eq 'Success'
Truth table0%0/2
A
A= $resxml->{'TMHead'}{'ResMsg'} eq 'Success'
Aresult
11
00
108 0 ▶ $resxml->{error} = $resxml->{TMHead}->{ResMsg} unless $resxml->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $resxml->{"success"} 0 0 0
109 0 return $resxml;
110 }
111  
112 =head1 COPYRIGHT AND LICENSE
113  
114 Copyright (C) 2009 by Dusty Wilson, E<lt>dusty@megagram.comE<gt>
115  
116 This library is free software; you can redistribute it and/or modify
117 it under the same terms as Perl itself, either Perl version 5.8.0 or,
118 at your option, any later version of Perl 5 you may have available.
119 =cut
120  
121 1 1;
↑ Summary