Skip to content

Commit

Permalink
= Added a new functionality that supports the new route. Tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
watzenare committed Jul 8, 2015
1 parent d3c7931 commit 4f0efb2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
30 changes: 30 additions & 0 deletions PushApi_Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 //
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions PushApi_ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4f0efb2

Please sign in to comment.