File Coverage

blib/lib/WebService/Mocean.pm
Criterion Covered Total %
statement 24 28 85.7
branch n/a
condition n/a
subroutine 8 9 88.8
pod n/a
total 32 37 86.4


line stmt bran cond sub pod time code
1             package WebService::Mocean;
2              
3 11     11   683425 use namespace::clean;
  11         168940  
  11         68  
4 11     11   7502 use strictures 2;
  11         17382  
  11         459  
5 11     11   2147 use utf8;
  11         24  
  11         74  
6              
7 11     11   330 use Module::Runtime qw(require_module);
  11         22  
  11         60  
8 11     11   6464 use Moo;
  11         73661  
  11         53  
9 11     11   21465 use Types::Standard qw(Str InstanceOf);
  11         826581  
  11         124  
10              
11 11     11   15274 use WebService::Mocean::Client;
  11         63  
  11         5009  
12              
13             our $VERSION = '0.04';
14              
15             has api_key => (
16             isa => Str,
17             is => 'rw',
18             required => 1
19             );
20              
21             has api_secret => (
22             isa => Str,
23             is => 'rw',
24             required => 1
25             );
26              
27             has api_url => (
28             isa => Str,
29             is => 'rw',
30             default => sub { 'https://rest.moceanapi.com/rest/1' },
31             );
32              
33             has client => (
34             is => 'lazy',
35             isa => InstanceOf['WebService::Mocean::Client'],
36             );
37              
38             sub _build_client {
39 2     2   112 my $self = shift;
40              
41 2         36 my $client = WebService::Mocean::Client->new(
42             api_key => $self->api_key,
43             api_secret => $self->api_secret,
44             api_url => $self->api_url,
45             );
46              
47 2         36 return $client;
48             }
49              
50             has sms => (
51             is => 'lazy',
52             default => sub { _delegate(shift, 'Sms') },
53             );
54              
55             has account => (
56             is => 'lazy',
57             default => sub { _delegate(shift, 'Account') },
58             );
59              
60             has report => (
61             is => 'lazy',
62             default => sub { _delegate(shift, 'Report') },
63             );
64              
65             sub _delegate {
66 0     0     my ($self, $module) = @_;
67              
68 0           my $package = __PACKAGE__ . "::$module";
69 0           require_module $package;
70              
71 0           return $package->new(client => $self->client);
72             }
73              
74             1;
75             __END__
76              
77             =encoding utf-8
78              
79             =head1 NAME
80              
81             WebService::Mocean - Perl library for integration with MoceanSMS gateway,
82             https://moceanapi.com.
83              
84             =head1 SYNOPSIS
85              
86             use WebService::Mocean;
87             my $mocean_api = WebService::Mocean->new(api_key => 'foo', api_secret => 'bar');
88              
89             =head1 DESCRIPTION
90              
91             WebService::Mocean is Perl library for integration with MoceanSMS gateway,
92             https://moceanapi.com.
93              
94             =head1 DEVELOPMENT
95              
96             Source repo at L<https://github.com/kianmeng/webservice-mocean|https://github.com/kianmeng/webservice-mocean>.
97              
98             =head2 Docker
99              
100             If you have Docker installed, you can build your Docker container for this
101             project.
102              
103             $ docker build -t webservice-mocean .
104             $ docker run -it -v $(pwd):/root webservice-mocean bash
105             # cpanm --installdeps --notest .
106              
107             =head2 Milla
108              
109             Setting up the required packages.
110              
111             $ milla authordeps --missing | cpanm
112             $ milla listdeps --missing | cpanm
113              
114             Check you code coverage.
115              
116             $ milla cover
117              
118             Several ways to run the test.
119              
120             $ milla test
121             $ milla test --author --release
122             $ AUTHOR_TESTING=1 RELEASE_TESTING=1 milla test
123             $ AUTHOR_TESTING=1 RELEASE_TESTING=1 milla run prove t/01_instantiation.t
124             $ LOGGING=1 milla run prove t/t/02_request.t
125              
126             Release the module.
127              
128             $ milla build
129             $ milla release
130              
131             =head1 METHODS
132              
133             =head2 new($api_key, $api_secret, [%$args])
134              
135             Construct a new WebService::Mocean instance. The api_key and api_secret is
136             compulsory fields. Optionally takes additional hash or hash reference.
137              
138             # Instantiate the class.
139             my $mocean_api = WebService::Mocean->new(api_key => 'foo', api_secret => 'bar');
140              
141             # Alternative way.
142             my $mocean_api = WebService::Mocean->new({api_key => 'foo', api_secret => 'bar'});
143              
144             =head3 api_url
145              
146             The URL of the API resource.
147              
148             # Instantiate the class by setting the URL of the API endpoints.
149             my $mocean_api = WebService::Mocean->new({api_url => 'http://example.com/api/'});
150              
151             # Alternative way.
152             my $mocean_api = WebService::Mocean->new(api_key => 'foo', api_secret => 'bar');
153             $mocean_api->api_url('http://example.com/api/');
154              
155             =head2 sms->send($params)
156              
157             Send Mobile Terminated (MT) message, which means the message is sent from
158             mobile SMS provider and terminated at the to the mobile phone.
159              
160             # Send sample SMS.
161             my $response = $mocean_api->sms->send({
162             'mocean-to' => '0123456789',
163             'mocean-from' => 'ACME Ltd.',
164             'mocean-text' => 'Hello'
165             });
166              
167             =head2 sms->send_verification_code($params)
168              
169             Send a random code for verification to a mobile number.
170              
171             my $response = $mocean_api->sms->send_verification_code({
172             'mocean-to' => '0123456789',
173             'mocean-brand' => 'ACME Ltd.',
174             });
175              
176             =head2 sms->check_verification_code($params)
177              
178             Check the verfication code received from your user.
179              
180             my $response = $mocean_api->sms->check_verification_code({
181             'mocean-reqid' => '395935',
182             'mocean-code' => '234839',
183             });
184              
185             =head2 account->get_balance()
186              
187             Get your Mocean account balance.
188              
189             my $response = $mocean_api->account->get_balance();
190              
191             =head2 account->get_pricing()
192              
193             Get your Mocean account pricing and supported destination.
194              
195             my $response = $mocean_api->account->get_pricing();
196              
197             =head2 report->get_message_status($params)
198              
199             Get the outbound SMS current status.
200              
201             my $response = $mocean_api->report->get_message_status({
202             'mocean-msgid' => 123456
203             });
204              
205             =head1 COPYRIGHT AND LICENSE
206              
207             This software is Copyright (c) 2018-2019 by Kian Meng, Ang.
208              
209             This is free software, licensed under:
210              
211             The Artistic License 2.0 (GPL Compatible)
212              
213             =head1 AUTHOR
214              
215             Kian Meng, Ang E<lt>kianmeng@users.noreply.github.comE<gt>