From 4f0efb2032d99e97c96cfe6d25f3616e081daab6 Mon Sep 17 00:00:00 2001 From: Eloi Watzenare Date: Wed, 8 Jul 2015 14:42:05 +0200 Subject: [PATCH] = Added a new functionality that supports the new route. Tests updated --- PushApi_Client.php | 30 ++++++++++++++++++++++++++++++ PushApi_ClientTest.php | 10 ++++++++++ 2 files changed, 40 insertions(+) diff --git a/PushApi_Client.php b/PushApi_Client.php index a791ca5..1f310e1 100644 --- a/PushApi_Client.php +++ b/PushApi_Client.php @@ -32,6 +32,7 @@ * @method deleteUser($idUser) Deletes an specific $idUser * @method getUsers() Retrieves information about all registered users * @method createUsers($params) Creates multiple users given its emails + * @method getUserSmartphones($idUser) Retrives the smartphones that user has registered * * User Subscriptions: * @method getUserSubscription($idUser, $idChannel) Gets the specific $idUser subscription given a specific $idChannel @@ -349,6 +350,16 @@ public function createUsers($params) return $this->users(self::POST, $params); } + /** + * Retrives the smartphones that user has registered + * @param integer $idUser User identification value + * @return array Response key => value array + */ + public function getUserSmartphones($idUser) + { + return $this->userSmartphones(self::GET, $idUser); + } + ////////////////////////////// // CHANNEL CALLS // @@ -743,6 +754,25 @@ private function user($method, $idUser, $params = []) } } + /** + * Prepares the API call given the different possibilities (depending on the $method) + * @param string $method HTTP method of the request + * @param integer $idUser User identification value + * @return array Response key => value array + * + * @throws Exception If [There aren't required ids set] + */ + private function userSmartphones($method, $idUser) + { + $url = "user/$idUser/smartphones"; + $request = $this->getRequestManager(); + try { + return $request->sendRequest($method, $url); + } catch (Exception $e) { + throw new Exception($e->getMessage(), $e->getCode()); + } + } + /** * Prepares the API call given the different possibilities (depending on the $method) * @param string $method HTTP method of the request diff --git a/PushApi_ClientTest.php b/PushApi_ClientTest.php index b7620a2..16b1c7b 100644 --- a/PushApi_ClientTest.php +++ b/PushApi_ClientTest.php @@ -9,6 +9,8 @@ * Client tester that checks if the requests done by the Client contain the right values. It simulates the calls * that the Client can do and cheks the fake response. Also it is checked if the Client throws exceptions when * the RequestManager throw. + * + * phpunit --bootstrap vendor/autoload.php PushApi_ClientTest.php */ class PushApi_ClientTest extends PHPUnit_Framework_TestCase { @@ -128,6 +130,14 @@ public function testDeleteUserRequests() $this->assertDeleteRequest($result, $url); } + public function testGetUserSmartphonesRequests() + { + $url = "user/" . self::$id . "/smartphones"; + + $result = self::$client->getUserSmartphones(self::$id); + $this->assertGetRequest($result, $url); + } + /** * @expectedException Exception * @expectedExceptionMessage I'm a Dummmy Exception