File tree 5 files changed +105
-2
lines changed
5 files changed +105
-2
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ public function send($message)
34
34
$ message = $ this ->createMessageFromArray ($ message );
35
35
}
36
36
37
- $ params = $ message ->getRequestData ();
37
+ $ params = $ message ->getRequestData (false );
38
38
39
39
$ request = new Request (
40
40
\Nexmo \Client::BASE_REST . '/sms/json '
@@ -59,6 +59,14 @@ public function send($message)
59
59
switch ($ part ['status ' ]){
60
60
case '0 ' :
61
61
continue ; //all okay
62
+ case '1 ' :
63
+ if (preg_match ('#\[\s+(\d+)\s+\]# ' , $ part ['error-text ' ], $ match )){
64
+ usleep ($ match [1 ] + 1 );
65
+ } else {
66
+ sleep (1 );
67
+ }
68
+
69
+ return $ this ->send ($ message );
62
70
case '5 ' :
63
71
$ e = new Exception \Server ($ part ['error-text ' ], $ part ['status ' ]);
64
72
$ e ->setEntity ($ message );
Original file line number Diff line number Diff line change 13
13
use Nexmo \Entity \Psr7Trait ;
14
14
use Nexmo \Entity \RequestArrayTrait ;
15
15
16
- class Verification implements VerificationInterface, \ArrayAccess
16
+ class Verification implements VerificationInterface, \ArrayAccess, \Serializable
17
17
{
18
18
use Psr7Trait;
19
19
use RequestArrayTrait;
@@ -559,4 +559,38 @@ protected function getReadOnlyException($offset)
559
559
$ offset
560
560
));
561
561
}
562
+
563
+ public function serialize ()
564
+ {
565
+ $ data = [
566
+ 'requestData ' => $ this ->requestData
567
+ ];
568
+
569
+ if ($ request = $ this ->getRequest ()){
570
+ $ data ['request ' ] = \Zend \Diactoros \Request \Serializer::toString ($ request );
571
+ }
572
+
573
+ if ($ response = $ this ->getResponse ()){
574
+ $ data ['response ' ] = \Zend \Diactoros \Response \Serializer::toString ($ response );
575
+ }
576
+
577
+ return serialize ($ data );
578
+ }
579
+
580
+ public function unserialize ($ serialized )
581
+ {
582
+ $ data = unserialize ($ serialized );
583
+
584
+ $ this ->requestData = $ data ['requestData ' ];
585
+
586
+ if (isset ($ data ['request ' ])){
587
+ $ this ->request = \Zend \Diactoros \Request \Serializer::fromString ($ data ['request ' ]);
588
+ }
589
+
590
+ if (isset ($ data ['response ' ])){
591
+ $ this ->response = \Zend \Diactoros \Response \Serializer::fromString ($ data ['response ' ]);
592
+ }
593
+ }
594
+
595
+
562
596
}
Original file line number Diff line number Diff line change @@ -160,6 +160,28 @@ public function testCanSearchBySingleInboundId()
160
160
$ this ->assertSame ($ response , $ message ->getResponse ());
161
161
}
162
162
163
+ public function testRateLimitRetires ()
164
+ {
165
+ $ rate = $ this ->getResponse ('ratelimit ' );
166
+ $ success = $ this ->getResponse ('success ' );
167
+
168
+ $ args = [
169
+ 'to ' => '14845551345 ' ,
170
+ 'from ' => '1105551334 ' ,
171
+ 'text ' => 'test message '
172
+ ];
173
+
174
+ $ this ->nexmoClient ->send (Argument::that (function (Request $ request ) use ($ args ){
175
+ $ this ->assertRequestJsonBodyContains ('to ' , $ args ['to ' ], $ request );
176
+ $ this ->assertRequestJsonBodyContains ('from ' , $ args ['from ' ], $ request );
177
+ $ this ->assertRequestJsonBodyContains ('text ' , $ args ['text ' ], $ request );
178
+ return true ;
179
+ }))->willReturn ($ rate , $ rate , $ success );
180
+
181
+ $ message = $ this ->messageClient ->send (new Text ($ args ['to ' ], $ args ['from ' ], $ args ['text ' ]));
182
+ $ this ->assertEquals ($ success , $ message ->getResponse ());
183
+ }
184
+
163
185
/**
164
186
* Get the API response we'd expect for a call to the API. Message API currently returns 200 all the time, so only
165
187
* change between success / fail is body of the message.
Original file line number Diff line number Diff line change
1
+ {
2
+ "message-count" : " 1" ,
3
+ "messages" : [
4
+ {
5
+ "to" : " 14843472194" ,
6
+ "status" : " 1" ,
7
+ "error-text" : " Throughput Rate Exceeded - please wait [ 97 ] and retry" ,
8
+ "network" : " 310260"
9
+ }
10
+ ]
11
+ }
Original file line number Diff line number Diff line change @@ -253,6 +253,34 @@ public function testExceptionForCheckFail()
253
253
$ this ->exsisting ->check ('4321 ' );
254
254
}
255
255
256
+ /**
257
+ * @dataProvider getSerializeResponses
258
+ */
259
+ public function testSerialize ($ response )
260
+ {
261
+ $ this ->exsisting ->setResponse ($ response );
262
+ $ this ->exsisting ->getResponse ()->getBody ()->rewind ();
263
+ $ this ->exsisting ->getResponse ()->getBody ()->getContents ();
264
+ $ serialized = serialize ($ this ->exsisting );
265
+ /* @var $unserialized Verification */
266
+ $ unserialized = unserialize ($ serialized );
267
+
268
+ $ this ->assertInstanceOf (get_class ($ this ->exsisting ), $ unserialized );
269
+
270
+ $ this ->assertEquals ($ this ->exsisting ->getAccountId (), $ unserialized ->getAccountId ());
271
+ $ this ->assertEquals ($ this ->exsisting ->getStatus (), $ unserialized ->getStatus ());
272
+
273
+ $ this ->assertEquals ($ this ->exsisting ->getResponseData (), $ unserialized ->getResponseData ());
274
+ }
275
+
276
+ public function getSerializeResponses ()
277
+ {
278
+ return [
279
+ [$ this ->getResponse ('search ' )],
280
+ [$ this ->getResponse ('start ' )],
281
+ ];
282
+ }
283
+
256
284
/**
257
285
* @dataProvider getClientProxyMethods
258
286
*/
You can’t perform that action at this time.
0 commit comments