@@ -15,108 +15,113 @@ class Client
1515 /* @var string $apiKey */
1616 private $ apiKey ;
1717
18+ /* @var string $sendWith */
19+ private $ sendWith ;
20+
1821 const BASE_URI = 'https://gateway.sms77.io/api ' ;
1922
20- public function __construct ($ apiKey )
23+ public function __construct ($ apiKey, $ sendWith = ' php-api ' )
2124 {
2225 $ this ->apiKey = $ apiKey ;
26+ $ this ->sendWith = $ sendWith ;
2327 }
2428
25- function balance ()
29+ public function balance ()
2630 {
27- return $ this ->request (" balance " , $ this ->buildOptions ([]));
31+ return $ this ->request (' balance ' , $ this ->buildOptions ([]));
2832 }
2933
30- function contacts ($ action , array $ extra = [])
34+ public function contacts ($ action , array $ extra = [])
3135 {
3236 $ options = $ this ->buildOptions ([
33- " action " => $ action ,
37+ ' action ' => $ action ,
3438 ], $ extra );
3539
3640 (new ContactsValidator ($ options ))->validate ();
3741
38- return $ this ->request (" contacts " , $ options );
42+ return $ this ->request (' contacts ' , $ options );
3943 }
4044
41- function lookup ($ type , $ number , array $ extra = [])
45+ public function lookup ($ type , $ number , array $ extra = [])
4246 {
4347 $ options = $ this ->buildOptions ([
44- " type " => $ type ,
45- " number " => $ number ,
48+ ' type ' => $ type ,
49+ ' number ' => $ number ,
4650 ], $ extra );
4751
4852 (new LookupValidator ($ options ))->validate ();
4953
50- return $ this ->request (" lookup " , $ options );
54+ return $ this ->request (' lookup ' , $ options );
5155 }
5256
53- function pricing (array $ extra = [])
57+ public function pricing (array $ extra = [])
5458 {
5559 $ options = $ this ->buildOptions ([], $ extra );
5660
5761 (new PricingValidator ($ options ))->validate ();
5862
59- return $ this ->request (" pricing " , $ options );
63+ return $ this ->request (' pricing ' , $ options );
6064 }
6165
62- function sms ($ to , $ text , array $ extra = [])
66+ public function sms ($ to , $ text , array $ extra = [])
6367 {
6468 $ options = $ this ->buildOptions ([
65- " to " => $ to ,
66- " text " => $ text
69+ ' to ' => $ to ,
70+ ' text ' => $ text
6771 ], $ extra );
6872
6973 (new SmsValidator ($ options ))->validate ();
7074
71- return $ this ->request (" sms " , $ options );
75+ return $ this ->request (' sms ' , $ options );
7276 }
7377
74- function status ($ msgId )
78+ public function status ($ msgId )
7579 {
7680 $ options = $ this ->buildOptions ([
77- " msg_id " => $ msgId ,
81+ ' msg_id ' => $ msgId ,
7882 ]);
7983
8084 (new StatusValidator ($ options ))->validate ();
8185
82- return $ this ->request (" status " , $ options );
86+ return $ this ->request (' status ' , $ options );
8387 }
8488
85- function validateForVoice ($ number , array $ extra = [])
89+ public function validateForVoice ($ number , array $ extra = [])
8690 {
8791 $ options = $ this ->buildOptions ([
88- " number " => $ number ,
92+ ' number ' => $ number ,
8993 ], $ extra );
9094
9195 (new ValidateForVoiceValidator ($ options ))->validate ();
9296
93- return $ this ->request (" validate_for_voice " , $ options );
97+ return $ this ->request (' validate_for_voice ' , $ options );
9498 }
9599
96- function voice ($ to , $ text , array $ extra = [])
100+ public function voice ($ to , $ text , array $ extra = [])
97101 {
98102 $ options = $ this ->buildOptions ([
99- " to " => $ to ,
100- " text " => $ text
103+ ' to ' => $ to ,
104+ ' text ' => $ text
101105 ], $ extra );
102106
103107 (new VoiceValidator ($ options ))->validate ();
104108
105- return $ this ->request (" voice " , $ options );
109+ return $ this ->request (' voice ' , $ options );
106110 }
107111
108112 private function buildOptions (array $ required , array $ extra = [])
109113 {
110114 $ required = array_merge ($ required , [
111- "p " => $ this ->apiKey
115+ 'p ' => $ this ->apiKey ,
116+ 'sendwith ' => '' === $ this ->sendWith ? 'unknown ' : $ this ->sendWith
112117 ]);
113118
114119 return array_merge ($ required , $ extra );
115120 }
116121
117122 private function request ($ path , $ options = [])
118123 {
119- $ curl_get_contents = function ($ url ) {
124+ $ curl_get_contents = static function ($ url ) {
120125 $ ch = curl_init ();
121126 curl_setopt ($ ch , CURLOPT_URL , $ url );
122127 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
@@ -125,6 +130,6 @@ private function request($path, $options = [])
125130 return $ output ;
126131 };
127132
128- return $ curl_get_contents (self ::BASE_URI . " / " . $ path . " ? " . http_build_query ($ options ));
133+ return $ curl_get_contents (self ::BASE_URI . ' / ' . $ path . ' ? ' . http_build_query ($ options ));
129134 }
130135}
0 commit comments