| 1 | package SMS::MessageBird::API::Verify; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use parent 'SMS::MessageBird::API'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | SMS::MessageBird::API::Verify - Sub-module for the SMS::MessageBird distribution. | ||||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||
| 14 | |||||||||||
| 15 | This is a sub-module which is part of the SMS::MessageBird distribution. | ||||||||||
| 16 | |||||||||||
| 17 | While this module can be used directly, it's designed to be used via | ||||||||||
| 18 | L<SMS::MessageBird> | ||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||
| 22 | |||||||||||
| 23 | This module provides the interface to the Verify methods of the MessageBird | ||||||||||
| 24 | JSON API. | ||||||||||
| 25 | |||||||||||
| 26 | The methods implmented acceept the paramteres as named in the MessageBird API | ||||||||||
| 27 | documentation which can be found at the L<MessageBird Developer Documentation|https://www.messagebird.com/en-gb/developers>. | ||||||||||
| 28 | If you're using this distribution you should be familiar with the API | ||||||||||
| 29 | documentation. | ||||||||||
| 30 | |||||||||||
| 31 | =head2 Response Data | ||||||||||
| 32 | |||||||||||
| 33 | Every method returns a standardised hashref containin the following keys: | ||||||||||
| 34 | |||||||||||
| 35 | =over | ||||||||||
| 36 | |||||||||||
| 37 | =item ok | ||||||||||
| 38 | |||||||||||
| 39 | Value of 0 or 1. Indicates if the request was completed successfully or not. | ||||||||||
| 40 | This value is based on LWP::UserAgent's is_success() method. | ||||||||||
| 41 | |||||||||||
| 42 | =item code | ||||||||||
| 43 | |||||||||||
| 44 | This is the HTTP code returned by the API. In the event of ok => 0 - it's | ||||||||||
| 45 | possible that the request was a 401 etc. So this is provided for sanity | ||||||||||
| 46 | checking. | ||||||||||
| 47 | |||||||||||
| 48 | =item content | ||||||||||
| 49 | |||||||||||
| 50 | This is a Perl hashref data structure decoded from the API's response JSON | ||||||||||
| 51 | as-is. | ||||||||||
| 52 | |||||||||||
| 53 | Please see the L<MessageBird Developer Documentation|https://www.messagebird.com/en-gb/developers> | ||||||||||
| 54 | for more information on the expected structure. | ||||||||||
| 55 | |||||||||||
| 56 | =back | ||||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | =head1 METHODS | ||||||||||
| 60 | |||||||||||
| 61 | =head2 request | ||||||||||
| 62 | |||||||||||
| 63 | In: %params - Hash of params accepted by the MessageBird API. | ||||||||||
| 64 | Out: $response - Hashref of response data. See "Response Data" above. | ||||||||||
| 65 | |||||||||||
| 66 | This method implements the POST /verify route of the API. | ||||||||||
| 67 | |||||||||||
| 68 | Requests creation and sending of a verification link to the supplied MSISDN. | ||||||||||
| 69 | |||||||||||
| 70 | Accepted parameters are listed in the MessageBird API documentation. | ||||||||||
| 71 | |||||||||||
| 72 | Require parameters are as follows: | ||||||||||
| 73 | |||||||||||
| 74 | =over | ||||||||||
| 75 | |||||||||||
| 76 | =item recipient | ||||||||||
| 77 | |||||||||||
| 78 | The MSISDN formatted telephone number to do send the verification link to. | ||||||||||
| 79 | |||||||||||
| 80 | =back | ||||||||||
| 81 | |||||||||||
| 82 | All other parameters are optional. | ||||||||||
| 83 | |||||||||||
| 84 | Please see the L<MessageBird Developer Documentation|https://www.messagebird.com/en-gb/developers> | ||||||||||
| 85 | for more information. | ||||||||||
| 86 | |||||||||||
| 87 | =cut | ||||||||||
| 88 | |||||||||||
| 89 | sub request { | ||||||||||
| 90 | 0 | ▶ | my ($self, %params) = @_; | ||||||||
|
Subroutine
request: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 91 | |||||||||||
| 92 | 0 | ▶ | return $self->_no_param_supplied('recipient') if !exists $params{recipient}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | |||||||||||
| 94 | 0 | return $self->_api_request( | |||||||||
| 95 | post => "/verify", | ||||||||||
| 96 | \%params, | ||||||||||
| 97 | ); | ||||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | |||||||||||
| 101 | =head2 verify | ||||||||||
| 102 | |||||||||||
| 103 | In: $verification_id - The verification ID returned by the request call. | ||||||||||
| 104 | In: $token - The token to attempt to verify. | ||||||||||
| 105 | Out: $response - Hashref of response data. See "Response Data" above. | ||||||||||
| 106 | |||||||||||
| 107 | This method implements the GET /verify/{verification_id}?token={token} route of | ||||||||||
| 108 | the API. | ||||||||||
| 109 | |||||||||||
| 110 | Attempts to verify a sent verification token. | ||||||||||
| 111 | |||||||||||
| 112 | Please see the L<MessageBird API Documentation|https://www.messagebird.com/en-gb/developers> | ||||||||||
| 113 | for more information. | ||||||||||
| 114 | |||||||||||
| 115 | =cut | ||||||||||
| 116 | |||||||||||
| 117 | sub verify { | ||||||||||
| 118 | 0 | ▶ | my ($self, $verify_id, $token) = @_; | ||||||||
|
Subroutine
verify: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 119 | |||||||||||
| 120 | 0 | ▶ | return $self->_no_param_supplied('verify_id') if !$verify_id; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 121 | 0 | ▶ | return $self->_no_param_supplied('verification token') if !$token; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | |||||||||||
| 123 | 0 | return $self->_api_request( | |||||||||
| 124 | get => "/verify/$verify_id", | ||||||||||
| 125 | token => $token, | ||||||||||
| 126 | ); | ||||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | |||||||||||
| 130 | =head2 get | ||||||||||
| 131 | |||||||||||
| 132 | In: $verification_id - The verification ID returned by the request call. | ||||||||||
| 133 | Out: $response - Hashref of response data. See "Response Data" above. | ||||||||||
| 134 | |||||||||||
| 135 | This method implements the GET /verify/{verification_id} route of the API. | ||||||||||
| 136 | |||||||||||
| 137 | Returns the existing verification object identified by $verification_id. | ||||||||||
| 138 | |||||||||||
| 139 | =cut | ||||||||||
| 140 | |||||||||||
| 141 | sub get { | ||||||||||
| 142 | 0 | ▶ | my ($self, $verify_id) = @_; | ||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 143 | |||||||||||
| 144 | 0 | ▶ | return $self->_no_param_supplied('verify_id') if !$verify_id; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 145 | |||||||||||
| 146 | 0 | return $self->_api_request( | |||||||||
| 147 | get => "/verify/$verify_id" | ||||||||||
| 148 | ); | ||||||||||
| 149 | } | ||||||||||
| 150 | |||||||||||
| 151 | |||||||||||
| 152 | =head2 remove | ||||||||||
| 153 | |||||||||||
| 154 | In: $verification_id - The verification ID returned by the request call. | ||||||||||
| 155 | Out: $response - Hashref of response data. See "Response Data" above. | ||||||||||
| 156 | |||||||||||
| 157 | This method implements the DELETE /verify/{verification_id} route of the API. | ||||||||||
| 158 | |||||||||||
| 159 | Deletes an existing verification object identified by $verification_id. | ||||||||||
| 160 | |||||||||||
| 161 | =cut | ||||||||||
| 162 | |||||||||||
| 163 | sub remove { | ||||||||||
| 164 | 0 | ▶ | my ($self, $verify_id) = @_; | ||||||||
|
Subroutine
remove: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 165 | |||||||||||
| 166 | 0 | ▶ | return $self->_no_param_supplied('verify ID') if !$verify_id; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 167 | |||||||||||
| 168 | 0 | my $response = $self->_api_request( delete => "/verify/$verify_id" ); | |||||||||
| 169 | 0 | ▶ | $response->{ok} = 1 if $response->{code} == 204; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 170 | |||||||||||
| 171 | 0 | return $response; | |||||||||
| 172 | } | ||||||||||
| 173 | |||||||||||
| 174 | |||||||||||
| 175 | =head2 del | ||||||||||
| 176 | |||||||||||
| 177 | Synonym for the L<remove()|/"remove"> method. | ||||||||||
| 178 | |||||||||||
| 179 | =cut | ||||||||||
| 180 | |||||||||||
| 181 | sub del { | ||||||||||
| 182 | 0 | ▶ | my ($self, $verify_id) = @_; | ||||||||
|
Subroutine
del: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 183 | |||||||||||
| 184 | 0 | return $self->remove($verify_id); | |||||||||
| 185 | } | ||||||||||
| 186 | |||||||||||
| 187 | |||||||||||
| 188 | =head1 AUTHOR | ||||||||||
| 189 | |||||||||||
| 190 | James Ronan, C<< <james at ronanweb.co.uk> >> | ||||||||||
| 191 | |||||||||||
| 192 | =head1 BUGS | ||||||||||
| 193 | |||||||||||
| 194 | Please report any bugs or feature requests to C<bug-sms-messagebird at rt.cpan.org>, | ||||||||||
| 195 | or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SMS-MessageBird>. | ||||||||||
| 196 | I will be notified, and then you'll automatically be notified of progress on your | ||||||||||
| 197 | bug as I make changes. | ||||||||||
| 198 | |||||||||||
| 199 | Alternatively you can raise an issue on the source code which is available on | ||||||||||
| 200 | L<GitHub|https://github.com/jamesronan/SMS-MessageBird>. | ||||||||||
| 201 | |||||||||||
| 202 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 203 | |||||||||||
| 204 | Copyright 2016 James Ronan. | ||||||||||
| 205 | |||||||||||
| 206 | This library is free software; you can redistribute it and/or modify it under | ||||||||||
| 207 | the same terms as Perl itself. | ||||||||||
| 208 | |||||||||||
| 209 | =cut | ||||||||||
| 210 | |||||||||||
| 211 | 2 | 1; | |||||||||
| 212 | |||||||||||