| 1 | package SMS::OVH; | ||
| 2 | |||
| 3 | 1 | ▶ | use 5.006; |
|
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 | |||
| 7 | 1 | ▶ | use OvhApi; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | |||
| 11 | has [qw( app_key app_secret cons_key serviceName sender )] => ( | ||
| 12 | isa => 'Str', | ||
| 13 | is => 'ro', | ||
| 14 | required => 1 | ||
| 15 | ); | ||
| 16 | |||
| 17 | has 'receivers' => ( | ||
| 18 | is => 'rw', | ||
| 19 | isa => 'ArrayRef', | ||
| 20 | required => 1, | ||
| 21 | lazy => 1, | ||
| 22 | default => sub { [] } | ||
| 23 | ); | ||
| 24 | |||
| 25 | has 'message' => ( | ||
| 26 | isa => 'Str', | ||
| 27 | is => 'rw', | ||
| 28 | required => 1, | ||
| 29 | lazy => 1, | ||
| 30 | default => '' | ||
| 31 | ); | ||
| 32 | |||
| 33 | has '_api' => ( | ||
| 34 | is => 'ro', | ||
| 35 | lazy => 1, | ||
| 36 | default => sub { | ||
| 37 | my $self = shift; | ||
| 38 | my $api = OvhApi->new( | ||
| 39 | type => OvhApi::OVH_API_EU, | ||
| 40 | applicationKey => $self->app_key, | ||
| 41 | applicationSecret => $self->app_secret, | ||
| 42 | consumerKey => $self->cons_key | ||
| 43 | ); | ||
| 44 | return $api; | ||
| 45 | } | ||
| 46 | ); | ||
| 47 | |||
| 48 | =head1 NAME | ||
| 49 | |||
| 50 | SMS::OVH - Send SMS using OVH API (https://api.ovh.com/) | ||
| 51 | |||
| 52 | =head1 VERSION | ||
| 53 | |||
| 54 | Version 0.02 | ||
| 55 | |||
| 56 | =cut | ||
| 57 | |||
| 58 | our $VERSION = '0.02'; | ||
| 59 | |||
| 60 | =head1 SYNOPSIS | ||
| 61 | |||
| 62 | This is just a little module that use OvhApi.pm to send SMS using the french provider API. | ||
| 63 | You'll need the OvhApi.pm module provided by OVH at: | ||
| 64 | |||
| 65 | https://eu.api.ovh.com/wrappers/OvhApi-perl-1.1.zip | ||
| 66 | |||
| 67 | use SMS::OVH; | ||
| 68 | |||
| 69 | my $sms = SMS::OVH->new( | ||
| 70 | app_key => 'your-key', | ||
| 71 | app_secret => 'your-secret', | ||
| 72 | cons_key => 'your-cons-key', | ||
| 73 | serviceName => 'a-service-name', | ||
| 74 | sender => 'a-sender-name', | ||
| 75 | receivers => ['+33123123123'], | ||
| 76 | message => 'This is a test text message.' | ||
| 77 | ); | ||
| 78 | |||
| 79 | $sms->send(); | ||
| 80 | |||
| 81 | =head1 METHODS | ||
| 82 | |||
| 83 | =head2 send | ||
| 84 | |||
| 85 | This is the only method. It just tries to complete the API request. | ||
| 86 | It takes no arguments, just uses the parameters set when the instance is created. | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | sub send { | ||
| 91 | my $self = shift; | ||
| 92 | my $url = "/sms/" . $self->serviceName . "/jobs"; | ||
| 93 | my %body = ( | ||
| 94 | message => $self->message, | ||
| 95 | sender => $self->sender, | ||
| 96 | noStopClause => 'true', | ||
| 97 | receivers => $self->receivers | ||
| 98 | ); | ||
| 99 | return $self->_api->rawCall( | ||
| 100 | path => $url, | ||
| 101 | method => 'post', | ||
| 102 | body => \%body | ||
| 103 | ); | ||
| 104 | } | ||
| 105 | |||
| 106 | =head1 AUTHOR | ||
| 107 | |||
| 108 | Paco Esteban, C<< <paco at onna.be> >> | ||
| 109 | |||
| 110 | =head1 BUGS | ||
| 111 | |||
| 112 | Please report any bugs or feature requests to C<bug-sms-ovh at rt.cpan.org>, or through | ||
| 113 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SMS-OVH>. I will be notified, and then you'll | ||
| 114 | automatically be notified of progress on your bug as I make changes. | ||
| 115 | |||
| 116 | |||
| 117 | |||
| 118 | |||
| 119 | =head1 SUPPORT | ||
| 120 | |||
| 121 | You can find documentation for this module with the perldoc command. | ||
| 122 | |||
| 123 | perldoc SMS::OVH | ||
| 124 | |||
| 125 | |||
| 126 | You can also look for information at: | ||
| 127 | |||
| 128 | =over 4 | ||
| 129 | |||
| 130 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 131 | |||
| 132 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SMS-OVH> | ||
| 133 | |||
| 134 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 135 | |||
| 136 | L<http://annocpan.org/dist/SMS-OVH> | ||
| 137 | |||
| 138 | =item * CPAN Ratings | ||
| 139 | |||
| 140 | L<http://cpanratings.perl.org/d/SMS-OVH> | ||
| 141 | |||
| 142 | =item * Search CPAN | ||
| 143 | |||
| 144 | L<http://search.cpan.org/dist/SMS-OVH/> | ||
| 145 | |||
| 146 | =back | ||
| 147 | |||
| 148 | |||
| 149 | =head1 ACKNOWLEDGEMENTS | ||
| 150 | |||
| 151 | |||
| 152 | =head1 LICENSE AND COPYRIGHT | ||
| 153 | |||
| 154 | Copyright 2015 Paco Esteban. | ||
| 155 | |||
| 156 | This program is distributed under the (Revised) BSD License: | ||
| 157 | L<http://www.opensource.org/licenses/BSD-3-Clause> | ||
| 158 | |||
| 159 | Redistribution and use in source and binary forms, with or without | ||
| 160 | modification, are permitted provided that the following conditions | ||
| 161 | are met: | ||
| 162 | |||
| 163 | * Redistributions of source code must retain the above copyright | ||
| 164 | notice, this list of conditions and the following disclaimer. | ||
| 165 | |||
| 166 | * Redistributions in binary form must reproduce the above copyright | ||
| 167 | notice, this list of conditions and the following disclaimer in the | ||
| 168 | documentation and/or other materials provided with the distribution. | ||
| 169 | |||
| 170 | * Neither the name of Paco Esteban's Organization | ||
| 171 | nor the names of its contributors may be used to endorse or promote | ||
| 172 | products derived from this software without specific prior written | ||
| 173 | permission. | ||
| 174 | |||
| 175 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 176 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 177 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 178 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 179 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 180 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 181 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 182 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 183 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 184 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 185 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 186 | |||
| 187 | |||
| 188 | =cut | ||
| 189 | |||
| 190 | 1; # End of SMS::OVH | ||