From b3deacfab08781cf9610967a1d2840940ecd26f2 Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Sun, 20 Nov 2016 16:30:08 -0600 Subject: [PATCH 01/14] Update rate limit parser to fail gracefully when no headers returned --- src/Client.php | 10 ++++++++-- tests/src/UberTest.php | 27 +++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index ec7749f..48705aa 100644 --- a/src/Client.php +++ b/src/Client.php @@ -3,6 +3,7 @@ use GuzzleHttp\Client as HttpClient; use GuzzleHttp\Exception\ClientException as HttpClientException; use GuzzleHttp\Psr7\Response; +use ReflectionClass; class Client { @@ -368,11 +369,16 @@ private function parseConfiguration($configuration = []) */ private function parseRateLimitFromResponse(Response $response) { - $this->rate_limit = new RateLimit( + $rateLimitHeaders = array_filter([ $response->getHeader('X-Rate-Limit-Limit'), $response->getHeader('X-Rate-Limit-Remaining'), $response->getHeader('X-Rate-Limit-Reset') - ); + ]); + + if (count($rateLimitHeaders) == 3) { + $rateLimitClass = new ReflectionClass(RateLimit::class); + $this->rate_limit = $rateLimitClass->newInstanceArgs($rateLimitHeaders); + } } /** diff --git a/tests/src/UberTest.php b/tests/src/UberTest.php index 18e1c5a..f472a2f 100644 --- a/tests/src/UberTest.php +++ b/tests/src/UberTest.php @@ -251,11 +251,32 @@ public function test_Get_History() $history = $this->client->getHistory($params); } - public function test_Get_Profile() + public function test_Get_Profile_with_Rate_Limit_Headers() { + $rateLimitHeaders = [1000, 955, strtotime("+1 day")]; $getResponse = m::mock('GuzzleHttp\Psr7\Response'); $getResponse->shouldReceive('getBody')->times(1)->andReturn('{"first_name": "Uber","last_name": "Developer","email": "developer@uber.com","picture": "https://...","promo_code": "teypo","uuid": "91d81273-45c2-4b57-8124-d0165f8240c0"}'); - $getResponse->shouldReceive('getHeader')->times(3)->andReturnValues([1000, 955, strtotime("+1 day")]); + $getResponse->shouldReceive('getHeader')->times(3)->andReturnValues($rateLimitHeaders); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('get') + ->with($this->client->getUrlFromPath('/me'), ['headers' => $this->client->getHeaders()]) + ->times(1)->andReturn($getResponse); + + $this->client->setHttpClient($http_client); + + $profile = $this->client->getProfile(); + $rateLimit = $this->client->getRateLimit(); + $this->assertEquals($rateLimit->getLimit(), $rateLimitHeaders[0]); + $this->assertEquals($rateLimit->getRemaining(), $rateLimitHeaders[1]); + $this->assertEquals($rateLimit->getReset(), $rateLimitHeaders[2]); + } + + public function test_Get_Profile_without_Rate_Limit_Headers() + { + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); + $getResponse->shouldReceive('getBody')->times(1)->andReturn('{"first_name": "Uber","last_name": "Developer","email": "developer@uber.com","picture": "https://...","promo_code": "teypo","uuid": "91d81273-45c2-4b57-8124-d0165f8240c0"}'); + $getResponse->shouldReceive('getHeader')->times(3)->andReturnValues([null, null, null]); $http_client = m::mock('GuzzleHttp\Client'); $http_client->shouldReceive('get') @@ -265,6 +286,8 @@ public function test_Get_Profile() $this->client->setHttpClient($http_client); $profile = $this->client->getProfile(); + $rateLimit = $this->client->getRateLimit(); + $this->assertNull($rateLimit); } public function test_Get_Request_Estimate() From 46fa6b6bac09b434481ce9e0c363850b25e00ef9 Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Sun, 20 Nov 2016 16:35:48 -0600 Subject: [PATCH 02/14] Update default api version to v1.2 --- src/Client.php | 2 +- tests/src/UberTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 48705aa..bd4f3d5 100644 --- a/src/Client.php +++ b/src/Client.php @@ -353,7 +353,7 @@ private function parseConfiguration($configuration = []) 'access_token' => null, 'server_token' => null, 'use_sandbox' => false, - 'version' => 'v1', + 'version' => 'v1.2', 'locale' => 'en_US', ); diff --git a/tests/src/UberTest.php b/tests/src/UberTest.php index f472a2f..2fc526d 100644 --- a/tests/src/UberTest.php +++ b/tests/src/UberTest.php @@ -38,6 +38,17 @@ public function test_Configuration() $this->assertEquals($client->getLocale(), getenv('UBER_LOCALE')); } + public function test_Configuration_Defaults() + { + $client = new Uber(); + + $this->assertEquals(null, $client->getAccessToken()); + $this->assertEquals(null, $client->getServerToken()); + $this->assertEquals(false, $client->getUseSandbox()); + $this->assertEquals('v1.2', $client->getVersion()); + $this->assertEquals('en_US', $client->getLocale()); + } + /** * @expectedException Stevenmaguire\Uber\Exception */ From 83686bc8b093c6a24189b1d65621681dc1fbcb9a Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Sun, 20 Nov 2016 16:46:57 -0600 Subject: [PATCH 03/14] Add profile patch support --- README.md | 12 ++++++++++++ src/Client.php | 12 ++++++++++++ tests/src/UberTest.php | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/README.md b/README.md index 50f7c0a..fe9b0fd 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,18 @@ $history = $client->getHistory(array( $profile = $client->getProfile(); ``` +[https://developer.uber.com/v1/endpoints/#user-profile](https://developer.uber.com/v1/endpoints/#user-profile) + +### Update User Profile + +```php +$attributes = ['applied_promotion_codes' => 'PROMO_CODE']; +$profileResponse = $client->setProfile($attributes); +``` + +[https://developer.uber.com/docs/riders/references/api/v1.2/me-patch](https://developer.uber.com/docs/riders/references/api/v1.2/me-patch) + + [https://developer.uber.com/v1/endpoints/#user-profile](https://developer.uber.com/v1/endpoints/#user-profile) ### Request A Ride diff --git a/src/Client.php b/src/Client.php index bd4f3d5..c6e5d6f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -448,6 +448,18 @@ public function setProduct($product_id, $attributes = []) return $this->request('put', 'sandbox/products/'.$product_id, $attributes); } + /** + * Set profile properties + * + * @param array $attributes + * + * @return stdClass + */ + public function setProfile($attributes = []) + { + return $this->request('put', 'me', $attributes); + } + /** * Set request properties for sandbox responses * diff --git a/tests/src/UberTest.php b/tests/src/UberTest.php index 2fc526d..c6d6abc 100644 --- a/tests/src/UberTest.php +++ b/tests/src/UberTest.php @@ -468,6 +468,24 @@ public function test_Set_Product() $request = $this->client->setProduct($product_id, $request_body); } + public function test_Set_Profile() + { + $request_body = ['applied_promotion_codes' => uniqid()]; + + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); + $getResponse->shouldReceive('getBody')->times(1)->andReturn('{"promotion_code": "'.$request_body['applied_promotion_codes'].'","description": "$20.00 has been applied to your account."}'); + $getResponse->shouldReceive('getHeader')->times(3)->andReturn(null); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('put') + ->with($this->client->getUrlFromPath('/me'), ['headers' => $this->client->getHeaders(), 'json' => $request_body]) + ->times(1)->andReturn($getResponse); + + $this->client->setHttpClient($http_client); + + $request = $this->client->setProfile($request_body); + } + /** * @expectedException Stevenmaguire\Uber\Exception */ From 8320b3b8fe7edf299f338a6eaa7f8ec14b322170 Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Sun, 20 Nov 2016 16:53:58 -0600 Subject: [PATCH 04/14] Add payment methods list support --- README.md | 8 ++++++-- src/Client.php | 36 ++++++++++++++++++++++++------------ tests/src/UberTest.php | 16 ++++++++++++++++ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index fe9b0fd..e8eab14 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,6 @@ $history = $client->getHistory(array( ``` [https://developer.uber.com/v1/endpoints/#user-activity-v1-1](https://developer.uber.com/v1/endpoints/#user-activity-v1-1) -[https://developer.uber.com/v1/endpoints/#user-activity-v1-2](https://developer.uber.com/v1/endpoints/#user-activity-v1-2) ### Get User Profile @@ -123,8 +122,13 @@ $profileResponse = $client->setProfile($attributes); [https://developer.uber.com/docs/riders/references/api/v1.2/me-patch](https://developer.uber.com/docs/riders/references/api/v1.2/me-patch) +### Get Payment Methods -[https://developer.uber.com/v1/endpoints/#user-profile](https://developer.uber.com/v1/endpoints/#user-profile) +```php +$paymentMethods = $client->getPaymentMethods(); +``` + +[https://developer.uber.com/docs/riders/references/api/v1.2/payment-methods-get](https://developer.uber.com/docs/riders/references/api/v1.2/payment-methods-get) ### Request A Ride diff --git a/src/Client.php b/src/Client.php index c6e5d6f..564ad9d 100644 --- a/src/Client.php +++ b/src/Client.php @@ -167,6 +167,18 @@ public function getHistory($attributes = []) return $this->request('get', 'history', $attributes); } + /** + * The Payment Methods endpoint allows retrieving the list of the user’s + * available payment methods. These can be leveraged in order to supply a + * payment_method_id to the POST /requests endpoint. + * + * @return stdClass The JSON response from the request + */ + public function getPaymentMethods() + { + return $this->request('get', 'payment-methods'); + } + /** * The Price Estimates endpoint returns an estimated price range for each * product offered at a given location. The price estimate is provided as @@ -182,6 +194,18 @@ public function getPriceEstimates($attributes = []) return $this->request('get', 'estimates/price', $attributes); } + /** + * Get a single product + * + * @param string $product_id Product id + * + * @return stdClass The JSON response from the request + */ + public function getProduct($product_id) + { + return $this->request('get', 'products/'.$product_id); + } + /** * The Products endpoint returns information about the Uber products * offered at a given location. The response includes the display name and @@ -200,18 +224,6 @@ public function getProducts($attributes = []) return $this->request('get', 'products', $attributes); } - /** - * Get a single product - * - * @param string $product_id Product id - * - * @return stdClass The JSON response from the request - */ - public function getProduct($product_id) - { - return $this->request('get', 'products/'.$product_id); - } - /** * The User Profile endpoint returns information about the Uber user that * has authorized with the application. diff --git a/tests/src/UberTest.php b/tests/src/UberTest.php index c6d6abc..85fc12e 100644 --- a/tests/src/UberTest.php +++ b/tests/src/UberTest.php @@ -130,6 +130,22 @@ public function test_Headers_Include_Empty_AcceptLanguage_When_Locale_Not_Provid $this->assertEmpty($headers['Accept-Language']); } + public function test_Get_Payment_Methods() + { + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); + $getResponse->shouldReceive('getBody')->times(1)->andReturn('{"payment_methods": [{"payment_method_id": "5f384f7d-8323-4207-a297-51c571234a8c","type": "baidu_wallet","description": "***53",},{"payment_method_id": "f33847de-8113-4587-c307-51c2d13a823c","type": "alipay","description": "ga***@uber.com",},{"payment_method_id": "f43847de-8113-4587-c307-51c2d13a823c","type": "visa","description": "***23"},{"payment_method_id": "517a6c29-3a2b-45cb-94a3-35d679909a71","type": "american_express","description": "***05"},{"payment_method_id": "f53847de-8113-4587-c307-51c2d13a823c","type": "business_account","description": "Late Night Ride"}],"last_used": "f53847de-8113-4587-c307-51c2d13a823c"}'); + $getResponse->shouldReceive('getHeader')->times(3)->andReturn(null); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('get') + ->with($this->client->getUrlFromPath('/payment-methods'), ['headers' => $this->client->getHeaders()]) + ->times(1)->andReturn($getResponse); + + $this->client->setHttpClient($http_client); + + $product = $this->client->getPaymentMethods(); + } + public function test_Get_Products() { $params = [ From 37c6786736f8310d2dedbdffc3dcd836c663830e Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Sun, 20 Nov 2016 17:00:12 -0600 Subject: [PATCH 05/14] Add place detail support --- README.md | 10 ++++++++++ src/Client.php | 15 +++++++++++++++ tests/src/UberTest.php | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/README.md b/README.md index e8eab14..3dfc714 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,16 @@ $paymentMethods = $client->getPaymentMethods(); [https://developer.uber.com/docs/riders/references/api/v1.2/payment-methods-get](https://developer.uber.com/docs/riders/references/api/v1.2/payment-methods-get) +### Get Place + +```php +$placeId = 'home'; + +$place = $client->getPlace($placeId); +``` + +[https://developer.uber.com/docs/riders/references/api/v1.2/places-place_id-get](https://developer.uber.com/docs/riders/references/api/v1.2/places-place_id-get) + ### Request A Ride ```php diff --git a/src/Client.php b/src/Client.php index 564ad9d..f7f7d7e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -179,6 +179,21 @@ public function getPaymentMethods() return $this->request('get', 'payment-methods'); } + /** + * The Places endpoint allows retrieving the home and work addresses from + * an Uber user's profile. + * + * The name of the place to retrieve. Only home and work are acceptable. + * + * @param string $place_id Place id + * + * @return stdClass The JSON response from the request + */ + public function getPlace($place_id) + { + return $this->request('get', 'places/'.$place_id); + } + /** * The Price Estimates endpoint returns an estimated price range for each * product offered at a given location. The price estimate is provided as diff --git a/tests/src/UberTest.php b/tests/src/UberTest.php index 85fc12e..d2eb368 100644 --- a/tests/src/UberTest.php +++ b/tests/src/UberTest.php @@ -146,6 +146,24 @@ public function test_Get_Payment_Methods() $product = $this->client->getPaymentMethods(); } + public function test_Get_Place() + { + $place_id = 'mock_place_id'; + + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); + $getResponse->shouldReceive('getBody')->times(1)->andReturn('{"address": "685 Market St, San Francisco, CA 94103, USA"'); + $getResponse->shouldReceive('getHeader')->times(3)->andReturn(null); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('get') + ->with($this->client->getUrlFromPath('/places/'.$place_id), ['headers' => $this->client->getHeaders()]) + ->times(1)->andReturn($getResponse); + + $this->client->setHttpClient($http_client); + + $product = $this->client->getPlace($place_id); + } + public function test_Get_Products() { $params = [ From 9e41ec86100a76256a36ee3afc3dcafd7cdec7a2 Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Sun, 20 Nov 2016 17:10:22 -0600 Subject: [PATCH 06/14] Add update place support --- README.md | 11 +++++++++++ src/Client.php | 16 ++++++++++++++++ src/GetSetTrait.php | 5 ++++- tests/src/UberTest.php | 19 +++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3dfc714..8957e39 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,17 @@ $place = $client->getPlace($placeId); [https://developer.uber.com/docs/riders/references/api/v1.2/places-place_id-get](https://developer.uber.com/docs/riders/references/api/v1.2/places-place_id-get) +### Update a Place + +```php +$placeId = 'home'; +$attributes = ['address' => '685 Market St, San Francisco, CA 94103, USA']; + +$place = $client->setPlace($placeId, $attributes); +``` + +[https://developer.uber.com/docs/riders/references/api/v1.2/places-place_id-put](https://developer.uber.com/docs/riders/references/api/v1.2/places-place_id-put) + ### Request A Ride ```php diff --git a/src/Client.php b/src/Client.php index f7f7d7e..768a498 100644 --- a/src/Client.php +++ b/src/Client.php @@ -462,6 +462,22 @@ public function setHttpClient(HttpClient $client) return $this; } + /** + * The Places endpoint allows updating the home and work addresses from an + * Uber user's profile. + * + * Only home and work are acceptable. + * + * @param string $place_id + * @param array $attributes + * + * @return stdClass + */ + public function setPlace($place_id, $attributes = []) + { + return $this->request('put', 'places/'.$place_id, $attributes); + } + /** * Set product properties for sandbox responses * diff --git a/src/GetSetTrait.php b/src/GetSetTrait.php index e287db9..7bc7a63 100644 --- a/src/GetSetTrait.php +++ b/src/GetSetTrait.php @@ -22,7 +22,10 @@ public function __call($method, $parameters) } elseif ($this->isSetMethod($method)) { $property = $this->convertMethodToProperty($method); - return $this->updateAttribute($property, $parameters[0]); + if (property_exists($this, $property)) { + return $this->updateAttribute($property, $parameters[0]); + } + } // @codeCoverageIgnore throw new Exception('Method not implemented'); diff --git a/tests/src/UberTest.php b/tests/src/UberTest.php index d2eb368..81e7440 100644 --- a/tests/src/UberTest.php +++ b/tests/src/UberTest.php @@ -483,6 +483,25 @@ public function test_Set_Request() $request = $this->client->setRequest($request_id, $request_body); } + public function test_Set_Place() + { + $placeId = 'home'; + $request_body = ['address' => uniqid()]; + + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); + $getResponse->shouldReceive('getBody')->times(1)->andReturn('{"address": "'.$request_body['address'].'"}'); + $getResponse->shouldReceive('getHeader')->times(3)->andReturn(null); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('put') + ->with($this->client->getUrlFromPath('/places/'.$placeId), ['headers' => $this->client->getHeaders(), 'json' => $request_body]) + ->times(1)->andReturn($getResponse); + + $this->client->setHttpClient($http_client); + + $request = $this->client->setPlace($placeId, $request_body); + } + public function test_Set_Product() { $product_id = 'mock_request_id'; From 7cce41ffe05beb65c38f7e6087817a6e3d3060ff Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Sun, 20 Nov 2016 17:21:08 -0600 Subject: [PATCH 07/14] Add current ride request detail support --- README.md | 8 ++++++++ src/Client.php | 26 ++++++++++++++++++++++++++ src/GetSetTrait.php | 2 +- tests/src/UberTest.php | 16 ++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8957e39..ca5cbc8 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,14 @@ try { [https://developer.uber.com/v1/endpoints/#request](https://developer.uber.com/v1/endpoints/#request) +### Get Current Ride Details + +```php +$request = $client->getCurrentRequest(); +``` + +[https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-get](https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-get) + ### Get Ride Details ```php diff --git a/src/Client.php b/src/Client.php index 768a498..ee3add1 100644 --- a/src/Client.php +++ b/src/Client.php @@ -148,6 +148,32 @@ public function getHeaders() ]; } + /** + * The Ride Request endpoint allows retrieving real-time details for an + * ongoing trip. + * + * This endpoint behaves similarly to the GET /requests/{request_id} + * endpoint, except you do not need to provide a request_id. If there is + * no trip in progress the endpoint will result in a 404 not found error. + * This endpoint will only work for trips requested through your app unless + * you have the all_trips scope. + * + * By default, only details about trips your app requested will be returned. + * If your app has all_trips scope, however, trip details will be returned + * for all trips irrespective of which application initiated them. + * + * See the Ride Request tutorial for a step-by-step guide to requesting + * rides on behalf of an Uber user. Please review the Sandbox documentation + * on how to develop and test against these endpoints without making + * real-world Ride Requests and being charged. + * + * @return stdClass The JSON response from the request + */ + public function getCurrentRequest() + { + return $this->request('get', 'requests/current'); + } + /** * The User Activity endpoint returns a limited amount of data about a * user's lifetime activity with Uber. The response will include pickup and diff --git a/src/GetSetTrait.php b/src/GetSetTrait.php index 7bc7a63..1077abb 100644 --- a/src/GetSetTrait.php +++ b/src/GetSetTrait.php @@ -28,7 +28,7 @@ public function __call($method, $parameters) } // @codeCoverageIgnore - throw new Exception('Method not implemented'); + throw new Exception($method . ' method not implemented'); } /** diff --git a/tests/src/UberTest.php b/tests/src/UberTest.php index 81e7440..b9cc1ca 100644 --- a/tests/src/UberTest.php +++ b/tests/src/UberTest.php @@ -385,6 +385,22 @@ public function test_Request_Ride() $request = $this->client->requestRide($params); } + public function test_Get_Current_Request() + { + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); + $getResponse->shouldReceive('getBody')->times(1)->andReturn('{"request_id": "","status": "processing","vehicle": null,"driver": null,"location": null,"eta": 5,"surge_multiplier": null}'); + $getResponse->shouldReceive('getHeader')->times(3)->andReturn(null); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('get') + ->with($this->client->getUrlFromPath('/requests/current'), ['headers' => $this->client->getHeaders()]) + ->times(1)->andReturn($getResponse); + + $this->client->setHttpClient($http_client); + + $request = $this->client->getCurrentRequest(); + } + public function test_Get_Request() { $request_id = 'mock_request_id'; From a7f92c058412a22c856f0cba980b3eb10fbf95d6 Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Sun, 20 Nov 2016 17:30:43 -0600 Subject: [PATCH 08/14] Add update current ride request support --- README.md | 16 ++++++++++++++++ src/Client.php | 19 +++++++++++++++++++ tests/src/UberTest.php | 18 ++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/README.md b/README.md index ca5cbc8..e9886fc 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,22 @@ $request = $client->getRequest($request_id); [https://developer.uber.com/v1/endpoints/#request-details](https://developer.uber.com/v1/endpoints/#request-details) +### Update Current Ride Details + +```php +$requestDetails = array( + 'end_address' => '685 Market St, San Francisco, CA 94103, USA', + 'end_nickname' => 'da crib', + 'end_place_id' => 'home', + 'end_latitude' => '41.87499492', + 'end_longitude' => '-87.67126465' +); + +$updateRequest = $client->setCurrentRequest($requestDetails); +``` + +[https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-patch](https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-patch) + ### Get Ride Estimate ```php diff --git a/src/Client.php b/src/Client.php index ee3add1..8da7955 100644 --- a/src/Client.php +++ b/src/Client.php @@ -475,6 +475,25 @@ public function requestRide($attributes = []) return $this->request('post', 'requests', $attributes); } + /** + * The Ride Request endpoint allows updating an ongoing request’s + * destination. + * + * This endpoint behaves similarly to the PATCH /v1.2/requests/{request_id} + * endpoint, except you do not need to provide a request_id. If there is no + * trip in progress the endpoint will result in a 404 not found error. This + * endpoint will only work for trips requested through your app unless you + * have the all_trips scope. + * + * @param array $attributes + * + * @return stdClass + */ + public function setCurrentRequest($attributes = []) + { + return $this->request('put', 'requests/current', $attributes); + } + /** * Set Http Client * diff --git a/tests/src/UberTest.php b/tests/src/UberTest.php index b9cc1ca..4084f75 100644 --- a/tests/src/UberTest.php +++ b/tests/src/UberTest.php @@ -480,6 +480,24 @@ public function test_Get_Existing_Properties() $this->assertEquals($locale, getenv('UBER_LOCALE')); } + public function test_Set_Current_Request() + { + $request_body = ['status' => uniqid()]; + + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); + $getResponse->shouldReceive('getBody')->times(1)->andReturn(null); + $getResponse->shouldReceive('getHeader')->times(3)->andReturnValues([1000, 955, strtotime("+1 day")]); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('put') + ->with($this->client->getUrlFromPath('/requests/current'), ['headers' => $this->client->getHeaders(), 'json' => $request_body]) + ->times(1)->andReturn($getResponse); + + $this->client->setHttpClient($http_client); + + $request = $this->client->setCurrentRequest($request_body); + } + public function test_Set_Request() { $request_id = 'mock_request_id'; From 42d65988bb69e740cfce94f9e2b17a5120078c46 Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Sun, 20 Nov 2016 17:37:01 -0600 Subject: [PATCH 09/14] Update sandbox method names to include intent --- README.md | 12 ++++++++++-- src/Client.php | 26 ++++++++++++++++++-------- tests/src/UberTest.php | 20 ++++++++++++++++++-- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e9886fc..e68778d 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,14 @@ $receipt = $client->getRequestReceipt($request_id); [https://developer.uber.com/v1/endpoints/#request-receipt](https://developer.uber.com/v1/endpoints/#request-receipt) +### Cancel Current Ride + +```php +$request = $client->cancelCurrentRequest(); +``` + +[https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-delete](https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-delete) + ### Cancel Ride ```php @@ -287,7 +295,7 @@ $request = $client->requestRide(array( 'end_longitude' => '-87.67126465' )); -$updateRequest = $client->setRequest($request->request_id, ['status' => 'accepted']); +$updateRequest = $client->setSandboxRequest($request->request_id, ['status' => 'accepted']); ``` [https://developer.uber.com/v1/sandbox/#request](https://developer.uber.com/v1/sandbox/#request) @@ -296,7 +304,7 @@ Simulate the possible responses the Request endpoint will return when requesting ```php $product = $client->getProduct($product_id); -$updateProduct = $client->setProduct($product_id, ['surge_multiplier' => 2.2, 'drivers_available' => false]); +$updateProduct = $client->setSandboxProduct($product_id, ['surge_multiplier' => 2.2, 'drivers_available' => false]); ``` [https://developer.uber.com/v1/sandbox/#product-types](https://developer.uber.com/v1/sandbox/#product-types) diff --git a/src/Client.php b/src/Client.php index 8da7955..645c75b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -84,6 +84,16 @@ private function applyConfiguration($configuration = []) }); } + /** + * Cancel the current request + * + * @return stdClass The JSON response from the request + */ + public function cancelCurrentRequest() + { + return $this->request('delete', 'requests/current'); + } + /** * Cancel a single request * @@ -524,28 +534,28 @@ public function setPlace($place_id, $attributes = []) } /** - * Set product properties for sandbox responses + * Set profile properties * - * @param string $product_id * @param array $attributes * * @return stdClass */ - public function setProduct($product_id, $attributes = []) + public function setProfile($attributes = []) { - return $this->request('put', 'sandbox/products/'.$product_id, $attributes); + return $this->request('put', 'me', $attributes); } /** - * Set profile properties + * Set product properties for sandbox responses * + * @param string $product_id * @param array $attributes * * @return stdClass */ - public function setProfile($attributes = []) + public function setSandboxProduct($product_id, $attributes = []) { - return $this->request('put', 'me', $attributes); + return $this->request('put', 'sandbox/products/'.$product_id, $attributes); } /** @@ -556,7 +566,7 @@ public function setProfile($attributes = []) * * @return stdClass */ - public function setRequest($request_id, $attributes = []) + public function setSandboxRequest($request_id, $attributes = []) { return $this->request('put', 'sandbox/requests/'.$request_id, $attributes); } diff --git a/tests/src/UberTest.php b/tests/src/UberTest.php index 4084f75..c8eac95 100644 --- a/tests/src/UberTest.php +++ b/tests/src/UberTest.php @@ -455,6 +455,22 @@ public function test_Get_Request_Map() $map = $this->client->getRequestMap($request_id); } + public function test_Cancel_Current_Request() + { + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); + $getResponse->shouldReceive('getBody')->times(1)->andReturn(null); + $getResponse->shouldReceive('getHeader')->times(3)->andReturnValues([1000, 955, strtotime("+1 day")]); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('delete') + ->with($this->client->getUrlFromPath('/requests/current'), ['headers' => $this->client->getHeaders()]) + ->times(1)->andReturn($getResponse); + + $this->client->setHttpClient($http_client); + + $cancel_request = $this->client->cancelCurrentRequest(); + } + public function test_Cancel_Request() { $request_id = 'mock_request_id'; @@ -514,7 +530,7 @@ public function test_Set_Request() $this->client->setHttpClient($http_client); - $request = $this->client->setRequest($request_id, $request_body); + $request = $this->client->setSandboxRequest($request_id, $request_body); } public function test_Set_Place() @@ -552,7 +568,7 @@ public function test_Set_Product() $this->client->setHttpClient($http_client); - $request = $this->client->setProduct($product_id, $request_body); + $request = $this->client->setSandboxProduct($product_id, $request_body); } public function test_Set_Profile() From 5ad72b51f45e33f588c3ae787973fe9f00809140 Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Sun, 20 Nov 2016 17:39:42 -0600 Subject: [PATCH 10/14] Add update specific request support --- README.md | 17 +++++++++++++++++ src/Client.php | 14 ++++++++++++++ tests/src/UberTest.php | 23 +++++++++++++++++++++-- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e68778d..6efac95 100644 --- a/README.md +++ b/README.md @@ -217,6 +217,23 @@ $updateRequest = $client->setCurrentRequest($requestDetails); [https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-patch](https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-patch) +### Update Ride Details + +```php +$requestId = '4bfc6c57-98c0-424f-a72e-c1e2a1d49939' +$requestDetails = array( + 'end_address' => '685 Market St, San Francisco, CA 94103, USA', + 'end_nickname' => 'da crib', + 'end_place_id' => 'home', + 'end_latitude' => '41.87499492', + 'end_longitude' => '-87.67126465' +); + +$updateRequest = $client->setRequest($requestId, $requestDetails); +``` + +[https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-patch](https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-patch) + ### Get Ride Estimate ```php diff --git a/src/Client.php b/src/Client.php index 645c75b..7b11819 100644 --- a/src/Client.php +++ b/src/Client.php @@ -545,6 +545,20 @@ public function setProfile($attributes = []) return $this->request('put', 'me', $attributes); } + /** + * The Ride Request endpoint allows updating an ongoing request’s + * destination using the Ride Request endpoint. + * + * @param string $request_id + * @param array $attributes + * + * @return stdClass + */ + public function setRequest($request_id, $attributes = []) + { + return $this->request('put', 'requests/'.$request_id, $attributes); + } + /** * Set product properties for sandbox responses * diff --git a/tests/src/UberTest.php b/tests/src/UberTest.php index c8eac95..6d1ea15 100644 --- a/tests/src/UberTest.php +++ b/tests/src/UberTest.php @@ -514,7 +514,7 @@ public function test_Set_Current_Request() $request = $this->client->setCurrentRequest($request_body); } - public function test_Set_Request() + public function test_Set_Sandbox_Request() { $request_id = 'mock_request_id'; $request_body = ['status' => uniqid()]; @@ -533,6 +533,25 @@ public function test_Set_Request() $request = $this->client->setSandboxRequest($request_id, $request_body); } + public function test_Set_Request() + { + $request_id = 'mock_request_id'; + $request_body = ['status' => uniqid()]; + + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); + $getResponse->shouldReceive('getBody')->times(1)->andReturn(null); + $getResponse->shouldReceive('getHeader')->times(3)->andReturn(null); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('put') + ->with($this->client->getUrlFromPath('/requests/'.$request_id), ['headers' => $this->client->getHeaders(), 'json' => $request_body]) + ->times(1)->andReturn($getResponse); + + $this->client->setHttpClient($http_client); + + $request = $this->client->setRequest($request_id, $request_body); + } + public function test_Set_Place() { $placeId = 'home'; @@ -552,7 +571,7 @@ public function test_Set_Place() $request = $this->client->setPlace($placeId, $request_body); } - public function test_Set_Product() + public function test_Set_Sandbox_Product() { $product_id = 'mock_request_id'; $request_body = ['surge_multiplier' => uniqid()]; From e4773810199206710ad55dc3286dfad8730df432 Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Sun, 20 Nov 2016 18:15:37 -0600 Subject: [PATCH 11/14] Add crud support for reminders api --- CONTRIBUTING.md | 9 +++- README.md | 67 +++++++++++++++++++++++++++ src/Client.php | 54 +++++++++++++++++++++- src/GetSetTrait.php | 1 - tests/src/UberTest.php | 102 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 230 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a1fc86e..381781a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,7 +25,14 @@ We accept contributions via Pull Requests on [Github](https://github.com/stevenm ## Running Tests ``` bash -$ phpunit +$ ./vendor/bin/phpunit +``` + + +## Running PHP Code Sniffer + +``` bash +$ ./vendor/bin/phpcs src --standard=psr2 -sp ``` diff --git a/README.md b/README.md index 6efac95..cc6adda 100644 --- a/README.md +++ b/README.md @@ -280,6 +280,73 @@ $request = $client->cancelRequest($request_id); [https://developer.uber.com/v1/endpoints/#request-cancel](https://developer.uber.com/v1/endpoints/#request-cancel) +### Create Reminder + +```php +$attributes = [ + 'reminder_time' => '1429294463', + 'phone_number' => '555-555-5555', + 'event' => [ + 'time' => '1429294463', + 'name' => 'Frisbee with friends', + 'location' => 'Dolores Park', + 'latitude' => '37.759773', + 'longitude' => '-122.427063', + ], + 'product_id' => 'a1111c8c-c720-46c3-8534-2fcdd730040d', + 'trip_branding' => [ + 'link_text' => 'View team roster', + 'partner_deeplink' => 'partner://team/9383', + ] +]; +$reminder = $client->createReminder($attributes); +``` + +[https://developer.uber.com/docs/riders/references/api/v1.2/reminders-post](https://developer.uber.com/docs/riders/references/api/v1.2/reminders-post) + +### Get Reminder + +```php +$reminderId = '4bfc6c57-98c0-424f-a72e-c1e2a1d49939'; +$reminder = $client->getReminder($reminderId); +``` + +[https://developer.uber.com/docs/riders/references/api/v1.2/reminders-reminder_id-get](https://developer.uber.com/docs/riders/references/api/v1.2/reminders-reminder_id-get) + +### Update Reminder + +```php +$reminderId = '4bfc6c57-98c0-424f-a72e-c1e2a1d49939'; +$attributes = [ + 'reminder_time' => '1429294463', + 'phone_number' => '555-555-5555', + 'event' => [ + 'time' => '1429294463', + 'name' => 'Frisbee with friends', + 'location' => 'Dolores Park', + 'latitude' => '37.759773', + 'longitude' => '-122.427063', + ], + 'product_id' => 'a1111c8c-c720-46c3-8534-2fcdd730040d', + 'trip_branding' => [ + 'link_text' => 'View team roster', + 'partner_deeplink' => 'partner://team/9383', + ] +]; +$reminder = $client->setReminder($reminderId, $attributes); +``` + +[https://developer.uber.com/docs/riders/references/api/v1.2/reminders-reminder_id-patch](https://developer.uber.com/docs/riders/references/api/v1.2/reminders-reminder_id-patch) + +### Cancel Reminder + +```php +$reminderId = '4bfc6c57-98c0-424f-a72e-c1e2a1d49939'; +$reminder = $client->cancelReminder($reminderId); +``` + +[https://developer.uber.com/docs/riders/references/api/v1.2/reminders-reminder_id-delete](https://developer.uber.com/docs/riders/references/api/v1.2/reminders-reminder_id-delete) + ### Rate Limiting Rate limiting is implemented on the basis of a specific client's secret token. By default, 1,000 requests per hour can be made per secret token. diff --git a/src/Client.php b/src/Client.php index 7b11819..b22b4ed 100644 --- a/src/Client.php +++ b/src/Client.php @@ -84,6 +84,19 @@ private function applyConfiguration($configuration = []) }); } + /** + * The Reminders endpoint allows developers to set a reminder for a future + * trip. + * + * @param array $attributes Query attributes + * + * @return stdClass The JSON response from the request + */ + public function createReminder($attributes) + { + return $this->request('post', 'reminders', $attributes); + } + /** * Cancel the current request * @@ -94,6 +107,19 @@ public function cancelCurrentRequest() return $this->request('delete', 'requests/current'); } + /** + * The Reminders endpoint allows you to remove any reminder in the pending + * state from being sent. + * + * @param string $reminder_id Reminder id + * + * @return stdClass The JSON response from the request + */ + public function cancelReminder($reminder_id) + { + return $this->request('delete', 'reminders/'.$reminder_id); + } + /** * Cancel a single request * @@ -219,7 +245,7 @@ public function getPaymentMethods() * The Places endpoint allows retrieving the home and work addresses from * an Uber user's profile. * - * The name of the place to retrieve. Only home and work are acceptable. + * Only home and work are acceptable. * * @param string $place_id Place id * @@ -300,6 +326,19 @@ public function getPromotions($attributes = []) return $this->request('get', 'promotions', $attributes); } + /** + * The Reminders endpoint allows you to get the status of an existing ride + * reminder. + * + * @param string $reminder_id Reminder id + * + * @return stdClass The JSON response from the request + */ + public function getReminder($reminder_id) + { + return $this->request('get', 'reminders/'.$reminder_id); + } + /** * The Request Estimate endpoint allows a ride to be estimated given the * desired product, start, and end locations. If the end location is @@ -545,6 +584,19 @@ public function setProfile($attributes = []) return $this->request('put', 'me', $attributes); } + /** + * The Reminders endpoint allows you to update an existing reminder. + * + * @param string $reminder_id + * @param array $attributes + * + * @return stdClass + */ + public function setReminder($reminder_id, $attributes = []) + { + return $this->request('put', 'reminders/'.$reminder_id, $attributes); + } + /** * The Ride Request endpoint allows updating an ongoing request’s * destination using the Ride Request endpoint. diff --git a/src/GetSetTrait.php b/src/GetSetTrait.php index 1077abb..75d57c9 100644 --- a/src/GetSetTrait.php +++ b/src/GetSetTrait.php @@ -25,7 +25,6 @@ public function __call($method, $parameters) if (property_exists($this, $property)) { return $this->updateAttribute($property, $parameters[0]); } - } // @codeCoverageIgnore throw new Exception($method . ' method not implemented'); diff --git a/tests/src/UberTest.php b/tests/src/UberTest.php index 6d1ea15..f58422a 100644 --- a/tests/src/UberTest.php +++ b/tests/src/UberTest.php @@ -229,6 +229,24 @@ public function test_Get_Price_Estimates() $estimates = $this->client->getPriceEstimates($params); } + public function test_Get_Reminder() + { + $reminder_id = 'mock_reminder_id'; + + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); + $getResponse->shouldReceive('getBody')->times(1)->andReturn('{"event": {"name": "Frisbee with friends","location": "Dolores Park","latitude": 37.759773,"longitude": -122.427063,"time": 1429294463},"product_id": "a1111c8c-c720-46c3-8534-2fcdd730040d","reminder_id": "def-456","reminder_time": 1429294463,"reminder_status": "pending","trip_branding": {"link_text": "View team roster","partner_deeplink": "partner://team/9383"}}'); + $getResponse->shouldReceive('getHeader')->times(3)->andReturn(null); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('get') + ->with($this->client->getUrlFromPath('/reminders/'.$reminder_id), ['headers' => $this->client->getHeaders()]) + ->times(1)->andReturn($getResponse); + + $this->client->setHttpClient($http_client); + + $reminder = $this->client->getReminder($reminder_id); + } + public function test_Get_Time_Estimates() { $params = [ @@ -385,6 +403,39 @@ public function test_Request_Ride() $request = $this->client->requestRide($params); } + public function test_Create_Reminder() + { + $params = [ + 'reminder_time' => '1429294463', + 'phone_number' => '555-555-5555', + 'event' => [ + 'time' => '1429294463', + 'name' => 'Frisbee with friends', + 'location' => 'Dolores Park', + 'latitude' => '37.759773', + 'longitude' => '-122.427063', + ], + 'product_id' => 'a1111c8c-c720-46c3-8534-2fcdd730040d', + 'trip_branding' => [ + 'link_text' => 'View team roster', + 'partner_deeplink' => 'partner://team/9383', + ] + ]; + + $postResponse = m::mock('GuzzleHttp\Psr7\Response'); + $postResponse->shouldReceive('getBody')->times(1)->andReturn('{"event": {"name": "Frisbee with friends","location": "Dolores Park","latitude": 37.759773,"longitude": -122.427063,"time": 1429294463},"product_id": "a1111c8c-c720-46c3-8534-2fcdd730040d","reminder_id": "def-456","reminder_time": 1429294463,"reminder_status": "pending","trip_branding": {"link_text": "View team roster","partner_deeplink": "partner://team/9383"}}'); + $postResponse->shouldReceive('getHeader')->times(3)->andReturn(null); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('post') + ->with($this->client->getUrlFromPath('/reminders'), ['headers' => $this->client->getHeaders(), 'json' => $params]) + ->times(1)->andReturn($postResponse); + + $this->client->setHttpClient($http_client); + + $reminder = $this->client->createReminder($params); + } + public function test_Get_Current_Request() { $getResponse = m::mock('GuzzleHttp\Psr7\Response'); @@ -471,6 +522,23 @@ public function test_Cancel_Current_Request() $cancel_request = $this->client->cancelCurrentRequest(); } + public function test_Cancel_Reminder() + { + $reminderId = uniqid(); + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); + $getResponse->shouldReceive('getBody')->times(1)->andReturn(null); + $getResponse->shouldReceive('getHeader')->times(3)->andReturn(null); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('delete') + ->with($this->client->getUrlFromPath('/reminders/'.$reminderId), ['headers' => $this->client->getHeaders()]) + ->times(1)->andReturn($getResponse); + + $this->client->setHttpClient($http_client); + + $cancel_reminder = $this->client->cancelReminder($reminderId); + } + public function test_Cancel_Request() { $request_id = 'mock_request_id'; @@ -514,6 +582,40 @@ public function test_Set_Current_Request() $request = $this->client->setCurrentRequest($request_body); } + public function test_Set_Reminder() + { + $reminderId = uniqid(); + $params = [ + 'reminder_time' => '1429294463', + 'phone_number' => '555-555-5555', + 'event' => [ + 'time' => '1429294463', + 'name' => 'Frisbee with friends', + 'location' => 'Dolores Park', + 'latitude' => '37.759773', + 'longitude' => '-122.427063', + ], + 'product_id' => 'a1111c8c-c720-46c3-8534-2fcdd730040d', + 'trip_branding' => [ + 'link_text' => 'View team roster', + 'partner_deeplink' => 'partner://team/9383', + ] + ]; + + $postResponse = m::mock('GuzzleHttp\Psr7\Response'); + $postResponse->shouldReceive('getBody')->times(1)->andReturn('{"event": {"name": "Frisbee with friends","location": "Dolores Park","latitude": 37.759773,"longitude": -122.427063,"time": 1429294463},"product_id": "a1111c8c-c720-46c3-8534-2fcdd730040d","reminder_id": "def-456","reminder_time": 1429294463,"reminder_status": "pending","trip_branding": {"link_text": "View team roster","partner_deeplink": "partner://team/9383"}}'); + $postResponse->shouldReceive('getHeader')->times(3)->andReturn(null); + + $http_client = m::mock('GuzzleHttp\Client'); + $http_client->shouldReceive('put') + ->with($this->client->getUrlFromPath('/reminders/'.$reminderId), ['headers' => $this->client->getHeaders(), 'json' => $params]) + ->times(1)->andReturn($postResponse); + + $this->client->setHttpClient($http_client); + + $reminder = $this->client->setReminder($reminderId, $params); + } + public function test_Set_Sandbox_Request() { $request_id = 'mock_request_id'; From 03847dd356ab346760d521463ef5a4decfe249c9 Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Mon, 21 Nov 2016 19:40:27 -0600 Subject: [PATCH 12/14] Update client and test case methods to use camel case, throw exceptions when attempting to use sandbox methods out of sandbox --- README.md | 24 +++++---- src/Client.php | 104 ++++++++++++++++++++++-------------- tests/src/UberTest.php | 118 ++++++++++++++++++++++++++--------------- 3 files changed, 150 insertions(+), 96 deletions(-) diff --git a/README.md b/README.md index cc6adda..809053b 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,7 @@ $request = $client->getCurrentRequest(); ### Get Ride Details ```php -$request = $client->getRequest($request_id); +$request = $client->getRequest($requestId); ``` [https://developer.uber.com/v1/endpoints/#request-details](https://developer.uber.com/v1/endpoints/#request-details) @@ -251,7 +251,7 @@ $requestEstimate = $client->getRequestEstimate(array( ### Get Ride Map ```php -$map = $client->getRequestMap($request_id); +$map = $client->getRequestMap($requestId); ``` [https://developer.uber.com/v1/endpoints/#request-map](https://developer.uber.com/v1/endpoints/#request-map) @@ -259,7 +259,7 @@ $map = $client->getRequestMap($request_id); ### Get Ride Receipt ```php -$receipt = $client->getRequestReceipt($request_id); +$receipt = $client->getRequestReceipt($requestId); ``` [https://developer.uber.com/v1/endpoints/#request-receipt](https://developer.uber.com/v1/endpoints/#request-receipt) @@ -275,7 +275,7 @@ $request = $client->cancelCurrentRequest(); ### Cancel Ride ```php -$request = $client->cancelRequest($request_id); +$request = $client->cancelRequest($requestId); ``` [https://developer.uber.com/v1/endpoints/#request-cancel](https://developer.uber.com/v1/endpoints/#request-cancel) @@ -354,13 +354,13 @@ Rate limiting is implemented on the basis of a specific client's secret token. B When consuming the service with this package, your rate limit status will be made available within the client. ```php -$product = $client->getProduct($product_id); +$product = $client->getProduct($productId); -$rate_limit = $client->getRateLimit(); +$rateLimit = $client->getRateLimit(); -$rate_limit->getLimit(); // Rate limit capacity per period -$rate_limit->getRemaining(); // Requests remaining in current period -$rate_limit->getReset(); // Timestamp in UTC time when the next period will begin +$rateLimit->getLimit(); // Rate limit capacity per period +$rateLimit->getRemaining(); // Requests remaining in current period +$rateLimit->getReset(); // Timestamp in UTC time when the next period will begin ``` These values will update after each request. `getRateLimit` will return null after the client is created and before the first successful request. @@ -370,6 +370,8 @@ These values will update after each request. `getRateLimit` will return null aft Modify the status of an ongoing sandbox Request. +> These methods will throw `Stevenmaguire\Uber\Exception` when invoked while the client is not in sandbox mode. The underlying API endpoints have no effect unless you are using the sandbox environment. + ```php $request = $client->requestRide(array( 'product_id' => '4bfc6c57-98c0-424f-a72e-c1e2a1d49939', @@ -386,9 +388,9 @@ $updateRequest = $client->setSandboxRequest($request->request_id, ['status' => ' Simulate the possible responses the Request endpoint will return when requesting a particular product, such as surge pricing, against the Sandbox. ```php -$product = $client->getProduct($product_id); +$product = $client->getProduct($productId); -$updateProduct = $client->setSandboxProduct($product_id, ['surge_multiplier' => 2.2, 'drivers_available' => false]); +$updateProduct = $client->setSandboxProduct($productId, ['surge_multiplier' => 2.2, 'drivers_available' => false]); ``` [https://developer.uber.com/v1/sandbox/#product-types](https://developer.uber.com/v1/sandbox/#product-types) diff --git a/src/Client.php b/src/Client.php index b22b4ed..5c0fe1b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -111,25 +111,25 @@ public function cancelCurrentRequest() * The Reminders endpoint allows you to remove any reminder in the pending * state from being sent. * - * @param string $reminder_id Reminder id + * @param string $reminderId Reminder id * * @return stdClass The JSON response from the request */ - public function cancelReminder($reminder_id) + public function cancelReminder($reminderId) { - return $this->request('delete', 'reminders/'.$reminder_id); + return $this->request('delete', 'reminders/'.$reminderId); } /** * Cancel a single request * - * @param string $request_id Request id + * @param string $requestId Request id * * @return stdClass The JSON response from the request */ - public function cancelRequest($request_id) + public function cancelRequest($requestId) { - return $this->request('delete', 'requests/'.$request_id); + return $this->request('delete', 'requests/'.$requestId); } /** @@ -207,7 +207,7 @@ public function getHeaders() */ public function getCurrentRequest() { - return $this->request('get', 'requests/current'); + return $this->getRequest('current'); } /** @@ -247,13 +247,13 @@ public function getPaymentMethods() * * Only home and work are acceptable. * - * @param string $place_id Place id + * @param string $placeId Place id * * @return stdClass The JSON response from the request */ - public function getPlace($place_id) + public function getPlace($placeId) { - return $this->request('get', 'places/'.$place_id); + return $this->request('get', 'places/'.$placeId); } /** @@ -274,13 +274,13 @@ public function getPriceEstimates($attributes = []) /** * Get a single product * - * @param string $product_id Product id + * @param string $productId Product id * * @return stdClass The JSON response from the request */ - public function getProduct($product_id) + public function getProduct($productId) { - return $this->request('get', 'products/'.$product_id); + return $this->request('get', 'products/'.$productId); } /** @@ -330,13 +330,13 @@ public function getPromotions($attributes = []) * The Reminders endpoint allows you to get the status of an existing ride * reminder. * - * @param string $reminder_id Reminder id + * @param string $reminderId Reminder id * * @return stdClass The JSON response from the request */ - public function getReminder($reminder_id) + public function getReminder($reminderId) { - return $this->request('get', 'reminders/'.$reminder_id); + return $this->request('get', 'reminders/'.$reminderId); } /** @@ -358,37 +358,37 @@ public function getRequestEstimate($attributes = []) /** * Get a single request * - * @param string $request_id Request id + * @param string $requestId Request id * * @return stdClass The JSON response from the request */ - public function getRequest($request_id) + public function getRequest($requestId) { - return $this->request('get', 'requests/'.$request_id); + return $this->request('get', 'requests/'.$requestId); } /** * Get the receipt information of the completed request. * - * @param string $request_id Request id + * @param string $requestId Request id * * @return stdClass The JSON response from the request */ - public function getRequestReceipt($request_id) + public function getRequestReceipt($requestId) { - return $this->request('get', 'requests/'.$request_id.'/receipt'); + return $this->request('get', 'requests/'.$requestId.'/receipt'); } /** * Get a single request map * - * @param string $request_id Request id + * @param string $requestId Request id * * @return stdClass The JSON response from the request */ - public function getRequestMap($request_id) + public function getRequestMap($requestId) { - return $this->request('get', 'requests/'.$request_id.'/map'); + return $this->request('get', 'requests/'.$requestId.'/map'); } /** @@ -540,7 +540,7 @@ public function requestRide($attributes = []) */ public function setCurrentRequest($attributes = []) { - return $this->request('put', 'requests/current', $attributes); + return $this->setRequest('current', $attributes); } /** @@ -562,14 +562,14 @@ public function setHttpClient(HttpClient $client) * * Only home and work are acceptable. * - * @param string $place_id + * @param string $placeId * @param array $attributes * * @return stdClass */ - public function setPlace($place_id, $attributes = []) + public function setPlace($placeId, $attributes = []) { - return $this->request('put', 'places/'.$place_id, $attributes); + return $this->request('put', 'places/'.$placeId, $attributes); } /** @@ -587,53 +587,75 @@ public function setProfile($attributes = []) /** * The Reminders endpoint allows you to update an existing reminder. * - * @param string $reminder_id + * @param string $reminderId * @param array $attributes * * @return stdClass */ - public function setReminder($reminder_id, $attributes = []) + public function setReminder($reminderId, $attributes = []) { - return $this->request('put', 'reminders/'.$reminder_id, $attributes); + return $this->request('put', 'reminders/'.$reminderId, $attributes); } /** * The Ride Request endpoint allows updating an ongoing request’s * destination using the Ride Request endpoint. * - * @param string $request_id + * @param string $requestId * @param array $attributes * * @return stdClass */ - public function setRequest($request_id, $attributes = []) + public function setRequest($requestId, $attributes = []) { - return $this->request('put', 'requests/'.$request_id, $attributes); + return $this->request('put', 'requests/'.$requestId, $attributes); } /** * Set product properties for sandbox responses * - * @param string $product_id + * @param string $productId * @param array $attributes * * @return stdClass */ - public function setSandboxProduct($product_id, $attributes = []) + public function setSandboxProduct($productId, $attributes = []) { - return $this->request('put', 'sandbox/products/'.$product_id, $attributes); + $this->enforceSandboxExpectation(); + + return $this->request('put', 'sandbox/products/'.$productId, $attributes); } /** * Set request properties for sandbox responses * - * @param string $request_id + * @param string $requestId * @param array $attributes * * @return stdClass */ - public function setSandboxRequest($request_id, $attributes = []) + public function setSandboxRequest($requestId, $attributes = []) { - return $this->request('put', 'sandbox/requests/'.$request_id, $attributes); + $this->enforceSandboxExpectation(); + + return $this->request('put', 'sandbox/requests/'.$requestId, $attributes); + } + + /** + * Throws exception when client is not configured sandbox use. Should only + * be utilized when attempting to do work against ephemeral sandbox API + * data. + * + * @see https://developer.uber.com/docs/riders/guides/sandbox + * @return void + * @throws Exception + */ + private function enforceSandboxExpectation($message = null) + { + if (!$this->use_sandbox) { + $message = $message ?: 'Attempted to invoke sandbox functionality '. + 'with production client; this is not recommended'; + throw new Exception($message); + } } } diff --git a/tests/src/UberTest.php b/tests/src/UberTest.php index f58422a..f1f59af 100644 --- a/tests/src/UberTest.php +++ b/tests/src/UberTest.php @@ -21,7 +21,7 @@ public function setUp() ]); } - public function test_Configuration() + public function testConfiguration() { $client = new Uber([ 'access_token' => getenv('UBER_ACCESS_TOKEN'), @@ -38,7 +38,7 @@ public function test_Configuration() $this->assertEquals($client->getLocale(), getenv('UBER_LOCALE')); } - public function test_Configuration_Defaults() + public function testConfigurationDefaults() { $client = new Uber(); @@ -52,7 +52,7 @@ public function test_Configuration_Defaults() /** * @expectedException Stevenmaguire\Uber\Exception */ - public function test_Configuration_Will_Not_Accept_Non_Property_Config() + public function testConfigurationWillNotAcceptNonPropertyConfig() { $client = new Uber([ 'non_existent_property' => 'test', @@ -61,7 +61,7 @@ public function test_Configuration_Will_Not_Accept_Non_Property_Config() $client->getNonExistentProperty(); } - public function test_Url_Includes_Version() + public function testUrlIncludesVersion() { $version = uniqid(); $this->client->setVersion($version); @@ -71,7 +71,7 @@ public function test_Url_Includes_Version() $this->assertContains($version, $url); } - public function test_Url_Omits_Version_When_Not_Provided() + public function testUrlOmitsVersionWhenNotProvided() { $this->client->setVersion(null); @@ -80,7 +80,7 @@ public function test_Url_Omits_Version_When_Not_Provided() $this->assertStringEndsNotWith('//', $url); } - public function test_Headers_Include_Bearer_When_Access_Token_Provided() + public function testHeadersIncludeBearerWhenAccessTokenProvided() { $access_token = uniqid(); $this->client->setAccessToken($access_token); @@ -91,7 +91,7 @@ public function test_Headers_Include_Bearer_When_Access_Token_Provided() $this->assertEquals('Bearer '.$access_token, $headers['Authorization']); } - public function test_Headers_Include_Token_When_Access_Token_Not_Provided() + public function testHeadersIncludeTokenWhenAccessTokenNotProvided() { $server_token = uniqid(); $this->client->setServerToken($server_token)->setAccessToken(null); @@ -102,7 +102,7 @@ public function test_Headers_Include_Token_When_Access_Token_Not_Provided() $this->assertEquals('Token '.$server_token, $headers['Authorization']); } - public function test_Headers_Include_Empty_Token_When_Access_And_Server_Token_Not_Provided() + public function testHeadersIncludeEmptyTokenWhenAccessAndServerTokenNotProvided() { $this->client->setServerToken(null)->setAccessToken(null); @@ -112,7 +112,7 @@ public function test_Headers_Include_Empty_Token_When_Access_And_Server_Token_No $this->assertEquals('Token', $headers['Authorization']); } - public function test_Headers_Include_AcceptLanguage_When_Locale_Provided() + public function testHeadersIncludeAcceptLanguageWhenLocaleProvided() { $locale = $this->client->getLocale(); @@ -122,7 +122,7 @@ public function test_Headers_Include_AcceptLanguage_When_Locale_Provided() $this->assertEquals($locale, $headers['Accept-Language']); } - public function test_Headers_Include_Empty_AcceptLanguage_When_Locale_Not_Provided() + public function testHeadersIncludeEmptyAcceptLanguageWhenLocaleNotProvided() { $headers = $this->client->setLocale(null)->getHeaders(); @@ -130,7 +130,7 @@ public function test_Headers_Include_Empty_AcceptLanguage_When_Locale_Not_Provid $this->assertEmpty($headers['Accept-Language']); } - public function test_Get_Payment_Methods() + public function testGetPaymentMethods() { $getResponse = m::mock('GuzzleHttp\Psr7\Response'); $getResponse->shouldReceive('getBody')->times(1)->andReturn('{"payment_methods": [{"payment_method_id": "5f384f7d-8323-4207-a297-51c571234a8c","type": "baidu_wallet","description": "***53",},{"payment_method_id": "f33847de-8113-4587-c307-51c2d13a823c","type": "alipay","description": "ga***@uber.com",},{"payment_method_id": "f43847de-8113-4587-c307-51c2d13a823c","type": "visa","description": "***23"},{"payment_method_id": "517a6c29-3a2b-45cb-94a3-35d679909a71","type": "american_express","description": "***05"},{"payment_method_id": "f53847de-8113-4587-c307-51c2d13a823c","type": "business_account","description": "Late Night Ride"}],"last_used": "f53847de-8113-4587-c307-51c2d13a823c"}'); @@ -146,7 +146,7 @@ public function test_Get_Payment_Methods() $product = $this->client->getPaymentMethods(); } - public function test_Get_Place() + public function testGetPlace() { $place_id = 'mock_place_id'; @@ -164,7 +164,7 @@ public function test_Get_Place() $product = $this->client->getPlace($place_id); } - public function test_Get_Products() + public function testGetProducts() { $params = [ 'latitude' => '41.85582993', @@ -188,7 +188,7 @@ public function test_Get_Products() $this->assertNull($this->client->getAccessToken()); } - public function test_Get_Product() + public function testGetProduct() { $product_id = 'mock_product_id'; @@ -206,7 +206,7 @@ public function test_Get_Product() $product = $this->client->getProduct($product_id); } - public function test_Get_Price_Estimates() + public function testGetPriceEstimates() { $params = [ 'start_latitude' => '41.85582993', @@ -229,7 +229,7 @@ public function test_Get_Price_Estimates() $estimates = $this->client->getPriceEstimates($params); } - public function test_Get_Reminder() + public function testGetReminder() { $reminder_id = 'mock_reminder_id'; @@ -247,7 +247,7 @@ public function test_Get_Reminder() $reminder = $this->client->getReminder($reminder_id); } - public function test_Get_Time_Estimates() + public function testGetTimeEstimates() { $params = [ 'start_latitude' => '41.85582993', @@ -268,7 +268,7 @@ public function test_Get_Time_Estimates() $estimates = $this->client->getTimeEstimates($params); } - public function test_Get_Promotions() + public function testGetPromotions() { $params = [ 'start_latitude' => '41.85582993', @@ -291,7 +291,7 @@ public function test_Get_Promotions() $promotions = $this->client->getPromotions($params); } - public function test_Get_History() + public function testGetHistory() { $params = [ 'limit' => 1, @@ -314,7 +314,7 @@ public function test_Get_History() $history = $this->client->getHistory($params); } - public function test_Get_Profile_with_Rate_Limit_Headers() + public function testGetProfilewithRateLimitHeaders() { $rateLimitHeaders = [1000, 955, strtotime("+1 day")]; $getResponse = m::mock('GuzzleHttp\Psr7\Response'); @@ -335,7 +335,7 @@ public function test_Get_Profile_with_Rate_Limit_Headers() $this->assertEquals($rateLimit->getReset(), $rateLimitHeaders[2]); } - public function test_Get_Profile_without_Rate_Limit_Headers() + public function testGetProfilewithoutRateLimitHeaders() { $getResponse = m::mock('GuzzleHttp\Psr7\Response'); $getResponse->shouldReceive('getBody')->times(1)->andReturn('{"first_name": "Uber","last_name": "Developer","email": "developer@uber.com","picture": "https://...","promo_code": "teypo","uuid": "91d81273-45c2-4b57-8124-d0165f8240c0"}'); @@ -353,7 +353,7 @@ public function test_Get_Profile_without_Rate_Limit_Headers() $this->assertNull($rateLimit); } - public function test_Get_Request_Estimate() + public function testGetRequestEstimate() { $params = [ 'product_id' => '4bfc6c57-98c0-424f-a72e-c1e2a1d49939', @@ -377,7 +377,7 @@ public function test_Get_Request_Estimate() $requestEstimate = $this->client->getRequestEstimate($params); } - public function test_Request_Ride() + public function testRequestRide() { $params = [ 'product_id' => '4bfc6c57-98c0-424f-a72e-c1e2a1d49939', @@ -403,7 +403,7 @@ public function test_Request_Ride() $request = $this->client->requestRide($params); } - public function test_Create_Reminder() + public function testCreateReminder() { $params = [ 'reminder_time' => '1429294463', @@ -436,7 +436,7 @@ public function test_Create_Reminder() $reminder = $this->client->createReminder($params); } - public function test_Get_Current_Request() + public function testGetCurrentRequest() { $getResponse = m::mock('GuzzleHttp\Psr7\Response'); $getResponse->shouldReceive('getBody')->times(1)->andReturn('{"request_id": "","status": "processing","vehicle": null,"driver": null,"location": null,"eta": 5,"surge_multiplier": null}'); @@ -452,7 +452,7 @@ public function test_Get_Current_Request() $request = $this->client->getCurrentRequest(); } - public function test_Get_Request() + public function testGetRequest() { $request_id = 'mock_request_id'; @@ -470,7 +470,7 @@ public function test_Get_Request() $request = $this->client->getRequest($request_id); } - public function test_Get_Request_Receipt() + public function testGetRequestReceipt() { $request_id = 'mock_request_id'; @@ -506,7 +506,7 @@ public function test_Get_Request_Map() $map = $this->client->getRequestMap($request_id); } - public function test_Cancel_Current_Request() + public function testCancelCurrentRequest() { $getResponse = m::mock('GuzzleHttp\Psr7\Response'); $getResponse->shouldReceive('getBody')->times(1)->andReturn(null); @@ -522,7 +522,7 @@ public function test_Cancel_Current_Request() $cancel_request = $this->client->cancelCurrentRequest(); } - public function test_Cancel_Reminder() + public function testCancelReminder() { $reminderId = uniqid(); $getResponse = m::mock('GuzzleHttp\Psr7\Response'); @@ -539,7 +539,7 @@ public function test_Cancel_Reminder() $cancel_reminder = $this->client->cancelReminder($reminderId); } - public function test_Cancel_Request() + public function testCancelRequest() { $request_id = 'mock_request_id'; @@ -557,14 +557,14 @@ public function test_Cancel_Request() $cancel_request = $this->client->cancelRequest($request_id); } - public function test_Get_Existing_Properties() + public function testGetExistingProperties() { $locale = $this->client->getLocale(); $this->assertEquals($locale, getenv('UBER_LOCALE')); } - public function test_Set_Current_Request() + public function testSetCurrentRequest() { $request_body = ['status' => uniqid()]; @@ -582,7 +582,7 @@ public function test_Set_Current_Request() $request = $this->client->setCurrentRequest($request_body); } - public function test_Set_Reminder() + public function testSetReminder() { $reminderId = uniqid(); $params = [ @@ -616,11 +616,13 @@ public function test_Set_Reminder() $reminder = $this->client->setReminder($reminderId, $params); } - public function test_Set_Sandbox_Request() + public function testSetSandboxRequestSucceedsInSandboxMode() { $request_id = 'mock_request_id'; $request_body = ['status' => uniqid()]; + $this->client->setUseSandbox(true); + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); $getResponse->shouldReceive('getBody')->times(1)->andReturn(null); $getResponse->shouldReceive('getHeader')->times(3)->andReturnValues([1000, 955, strtotime("+1 day")]); @@ -635,7 +637,20 @@ public function test_Set_Sandbox_Request() $request = $this->client->setSandboxRequest($request_id, $request_body); } - public function test_Set_Request() + /** + * @expectedException Stevenmaguire\Uber\Exception + */ + public function testSetSandboxRequestFailsOutOfSandboxMode() + { + $request_id = 'mock_request_id'; + $request_body = ['status' => uniqid()]; + + $this->client->setUseSandbox(false); + + $request = $this->client->setSandboxRequest($request_id, $request_body); + } + + public function testSetRequest() { $request_id = 'mock_request_id'; $request_body = ['status' => uniqid()]; @@ -654,7 +669,7 @@ public function test_Set_Request() $request = $this->client->setRequest($request_id, $request_body); } - public function test_Set_Place() + public function testSetPlace() { $placeId = 'home'; $request_body = ['address' => uniqid()]; @@ -673,11 +688,13 @@ public function test_Set_Place() $request = $this->client->setPlace($placeId, $request_body); } - public function test_Set_Sandbox_Product() + public function testSetSandboxProductSucceedsInSandboxMode() { $product_id = 'mock_request_id'; $request_body = ['surge_multiplier' => uniqid()]; + $this->client->setUseSandbox(true); + $getResponse = m::mock('GuzzleHttp\Psr7\Response'); $getResponse->shouldReceive('getBody')->times(1)->andReturn(null); $getResponse->shouldReceive('getHeader')->times(3)->andReturnValues([1000, 955, strtotime("+1 day")]); @@ -692,7 +709,20 @@ public function test_Set_Sandbox_Product() $request = $this->client->setSandboxProduct($product_id, $request_body); } - public function test_Set_Profile() + /** + * @expectedException Stevenmaguire\Uber\Exception + */ + public function testSetSandboxProductFailsOutOfSandboxMode() + { + $product_id = 'mock_request_id'; + $request_body = ['surge_multiplier' => uniqid()]; + + $this->client->setUseSandbox(false); + + $request = $this->client->setSandboxProduct($product_id, $request_body); + } + + public function testSetProfile() { $request_body = ['applied_promotion_codes' => uniqid()]; @@ -713,12 +743,12 @@ public function test_Set_Profile() /** * @expectedException Stevenmaguire\Uber\Exception */ - public function test_Get_Non_Existing_Properties() + public function testGetNonExistingProperties() { $result = $this->client->{'get'.rand(1111,9999)}(); } - public function test_Set_Existing_Properties() + public function testSetExistingProperties() { $var = uniqid(); $locale = $this->client->setLocale($var)->getLocale(); @@ -729,7 +759,7 @@ public function test_Set_Existing_Properties() /** * @expectedException Stevenmaguire\Uber\Exception */ - public function test_Set_Non_Existing_Properties() + public function testSetNonExistingProperties() { $result = $this->client->{'set'.rand(1111,9999)}(); } @@ -737,7 +767,7 @@ public function test_Set_Non_Existing_Properties() /** * @expectedException Stevenmaguire\Uber\Exception */ - public function test_Throws_Exception_On_Http_Errors() + public function testThrowsExceptionOnHttpErrors() { $params = []; $responseCode = 429; @@ -754,7 +784,7 @@ public function test_Throws_Exception_On_Http_Errors() $this->client->getProducts($params); } - public function test_Http_Exceptions_Include_Meta_From_Uber() + public function testHttpExceptionsIncludeMetaFromUber() { $params = []; $responseCode = 409; @@ -784,7 +814,7 @@ public function test_Http_Exceptions_Include_Meta_From_Uber() } } - public function test_Client_Exceptions_Throw_Uber_Exception() + public function testClientExceptionsThrowUberException() { $params = []; $exception = new HttpClientException( From 9d94d01a904c0635381628fbbeb0470b937777b4 Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Mon, 21 Nov 2016 19:54:48 -0600 Subject: [PATCH 13/14] Update changelog and code style --- CHANGELOG.md | 31 +++++++++++++++++++++++++++++++ README.md | 4 +++- src/Client.php | 4 +++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adf461f..df9ffc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,37 @@ # Changelog All Notable changes to `uber-php` will be documented in this file +## 1.5.0 - 2016-11-21 + +### Added +- Update rate limit parser to fail gracefully when no headers returned, as is expected in Uber API v1.2 +- Update default api version to v1.2 +- Add profile patch support +- Add payment methods list support +- Add place detail support +- Add update place support +- Add current ride request detail support +- Add update current ride request support +- Update sandbox method names to include intent +- Add update specific request support +- Add create reminder support +- Add fetch reminder support +- Add update reminder support +- Add cancel reminder support +- Add raised exception when invoking sandbox methods on non-sandbox client + +### Deprecated +- Removed `setProduct` method, replaced with `setSandboxProduct` + +### Fixed +- Nothing + +### Removed +- Nothing + +### Security +- Nothing + ## 1.4.0 - 2015-07-08 ### Added diff --git a/README.md b/README.md index 809053b..42a0bcd 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ $client = new Stevenmaguire\Uber\Client(array( 'access_token' => 'YOUR ACCESS TOKEN', 'server_token' => 'YOUR SERVER TOKEN', 'use_sandbox' => true, // optional, default false - 'version' => 'v1', // optional, default 'v1' + 'version' => 'v1.2', // optional, default 'v1.2' 'locale' => 'en_US', // optional, default 'en_US' )); ``` @@ -349,6 +349,8 @@ $reminder = $client->cancelReminder($reminderId); ### Rate Limiting +> This feature is only supported for `v1` version of the API. + Rate limiting is implemented on the basis of a specific client's secret token. By default, 1,000 requests per hour can be made per secret token. When consuming the service with this package, your rate limit status will be made available within the client. diff --git a/src/Client.php b/src/Client.php index 5c0fe1b..49559d5 100644 --- a/src/Client.php +++ b/src/Client.php @@ -104,7 +104,7 @@ public function createReminder($attributes) */ public function cancelCurrentRequest() { - return $this->request('delete', 'requests/current'); + return $this->cancelRequest('current'); } /** @@ -618,6 +618,7 @@ public function setRequest($requestId, $attributes = []) * @param array $attributes * * @return stdClass + * @throws Exception */ public function setSandboxProduct($productId, $attributes = []) { @@ -633,6 +634,7 @@ public function setSandboxProduct($productId, $attributes = []) * @param array $attributes * * @return stdClass + * @throws Exception */ public function setSandboxRequest($requestId, $attributes = []) { From 268191333859491edca27c82956dd32502d0b26d Mon Sep 17 00:00:00 2001 From: Steven Maguire Date: Mon, 21 Nov 2016 19:56:48 -0600 Subject: [PATCH 14/14] Update ci build config --- .scrutinizer.yml | 1 + .travis.yml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 16e9f25..a903494 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -19,6 +19,7 @@ checks: tools: external_code_coverage: timeout: 600 + runs: 2 php_analyzer: true php_code_coverage: false php_code_sniffer: diff --git a/.travis.yml b/.travis.yml index f3f94cc..f20c368 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,5 +16,5 @@ script: - ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover after_script: - - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover coverage.clover + - if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi + - if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi