File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 2828 */
2929class Client
3030{
31+ const VERSION = '1.0.0-beta1 ' ;
32+
3133 const BASE_API = 'https://api.nexmo.com ' ;
3234 const BASE_REST = 'https://rest.nexmo.com ' ;
3335
34-
3536 /**
3637 * API Credentials
3738 * @var CredentialsInterface
@@ -221,6 +222,13 @@ public function send(\Psr\Http\Message\RequestInterface $request)
221222 }
222223 }
223224
225+ //set the user-agent
226+ $ request = $ request ->withHeader ('user-agent ' , implode ('/ ' , [
227+ 'nexmo-php ' ,
228+ self ::VERSION ,
229+ 'PHP- ' . implode ('. ' , [PHP_MAJOR_VERSION , PHP_MINOR_VERSION ])
230+ ]));
231+
224232 $ response = $ this ->client ->sendRequest ($ request );
225233 return $ response ;
226234 }
Original file line number Diff line number Diff line change @@ -239,6 +239,36 @@ public function testNamespaceFactory()
239239 $ this ->assertSame ($ api , $ client ->sms ());
240240 }
241241
242+ public function testUserAgentString ()
243+ {
244+ $ version = Client::VERSION ;
245+ $ php = 'PHP- ' . implode ('. ' , [
246+ PHP_MAJOR_VERSION ,
247+ PHP_MINOR_VERSION
248+ ]);
249+
250+ //get a mock response to test
251+ $ response = new Response ();
252+ $ response ->getBody ()->write ('test response ' );
253+ $ this ->http ->addResponse ($ response );
254+
255+ $ client = new Client (new Basic ('key ' , 'secret ' ), [], $ this ->http );
256+ $ request = $ this ->getRequest ();
257+
258+ //api client should simply pass back the http response
259+ $ client ->send ($ request );
260+
261+ //useragent should match the expected format
262+ $ agent = $ this ->http ->getRequests ()[0 ]->getHeaderLine ('user-agent ' );
263+ $ expected = implode ('/ ' , [
264+ 'nexmo-php ' ,
265+ $ version ,
266+ $ php
267+ ]);
268+
269+ $ this ->assertEquals ($ expected , $ agent );
270+ }
271+
242272 /**
243273 * Allow tests to check that the API client is correctly forming the HTTP request before sending it to the HTTP
244274 * client.
You can’t perform that action at this time.
0 commit comments