Skip to content

Commit

Permalink
Add support for driver endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmaguire committed Aug 24, 2017
1 parent 3bfc2b4 commit 9b837dd
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 1 deletion.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# Changelog
All Notable changes to `uber-php` will be documented in this file

## 1.6.0 - 2017-08-23

### Added
- Support for driver endpoints

### Deprecated
- Nothing

### Fixed
- Nothing

### Removed
- Nothing

### Security
- Nothing

## 1.5.1 - 2017-08-03

### Added
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,30 @@ $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)

### Get Driver Profile

```php
$profile = $client->getDriverProfile();
```

[https://developer.uber.com/docs/drivers/references/api/v1/partners-me-get](https://developer.uber.com/docs/drivers/references/api/v1/partners-me-get)

### Get Driver Payments

```php
$profile = $client->getDriverPayments();
```

[https://developer.uber.com/docs/drivers/references/api/v1/partners-payments-get](https://developer.uber.com/docs/drivers/references/api/v1/partners-payments-get)

### Get Driver Trips

```php
$profile = $client->getDriverTrips();
```

[https://developer.uber.com/docs/drivers/references/api/v1/partners-trips-get](https://developer.uber.com/docs/drivers/references/api/v1/partners-trips-get)

### Rate Limiting

> This feature is only supported for `v1` version of the API.
Expand Down
1 change: 1 addition & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class Client
{
use GetSetTrait;
use Resources\Drivers;
use Resources\Estimates;
use Resources\Products;
use Resources\Promotions;
Expand Down
74 changes: 74 additions & 0 deletions src/Resources/Drivers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php namespace Stevenmaguire\Uber\Resources;

trait Drivers
{
/**
* Fetches the profile for the current driver.
*
* The Profile endpoint returns the profile of the authenticated driver.
* A profile includes information such as name, email, rating, and activation status.
*
* @return stdClass The JSON response from the request
*
* @see https://developer.uber.com/docs/drivers/references/api/v1/partners-me-get
*/
public function getDriverProfile()
{
return $this->request('get', 'partners/me');
}

/**
* Makes a request to the Uber API and returns the response.
*
* @param string $verb The Http verb to use
* @param string $path The path of the APi after the domain
* @param array $parameters Parameters
*
* @return stdClass The JSON response from the request
* @throws Exception
*/
abstract protected function request($verb, $path, $parameters = []);

/**
* Lists payments for the current driver.
*
* The Earnings endpoint returns an array of payments for the given driver.
* Payments are available at this endpoint in near real-time. Some entries,
* such as device_subscription will appear on a periodic basis when actually
* billed to the partner.
*
* If a trip is cancelled (either by rider or driver) and there is no payment
* made, the corresponding trip_id of that cancelled trip will not appear in
* this endpoint. If the given driver works for a fleet manager, there will
* be no payments associated and the response will always be an empty array.
* Drivers working for fleet managers will receive payments from the fleet
* manager and not from Uber.
*
* @param array $attributes
*
* @return stdClass The JSON response from the request
*
* @see https://developer.uber.com/docs/drivers/references/api/v1/partners-payments-get
*/
public function getDriverPayments($attributes = [])
{
return $this->request('get', '/partners/payments', $attributes);
}

/**
* Lists trips for the current driver.
*
* The Trip History endpoint returns an array of trips for the authenticated
* driver.
*
* @param array $attributes
*
* @return stdClass The JSON response from the request
*
* @see https://developer.uber.com/docs/drivers/references/api/v1/partners-trips-get
*/
public function getDriverTrips($attributes = [])
{
return $this->request('get', '/partners/trips', $attributes);
}
}
66 changes: 65 additions & 1 deletion tests/src/UberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,70 @@ public function testGetRequestEstimate()
$requestEstimate = $this->client->getRequestEstimate($params);
}

public function testGetDriverProfile()
{
$this->client->setVersion('v1.1');

$getResponse = m::mock('GuzzleHttp\Psr7\Response');
$getResponse->shouldReceive('getBody')->times(1)->andReturn('{"driver_id": "8LvWuRAq2511gmr8EMkovekFNa2848lyMaQevIto-aXmnK9oKNRtfTxYLgPq9OSt8EzAu5pDB7XiaQIrcp-zXgOA5EyK4h00U6D1o7aZpXIQah--U77Eh7LEBiksj2rahB==","first_name": "Uber","last_name": "Tester","email": "uber.developer+tester@example.com","phone_number": "+15555550001","picture": "https://d1w2poirtb3as9.cloudfront.net/16ce502f4767f17b120e.png","promo_code": "ubert4544ue","rating": 5,"activation_status": "active"}');
$getResponse->shouldReceive('getHeader')->times(3)->andReturnValues([1000, 955, strtotime("+1 day")]);

$http_client = m::mock('GuzzleHttp\Client');
$http_client->shouldReceive('get')
->with($this->client->getUrlFromPath('/partners/me'), ['headers' => $this->client->getHeaders()])
->times(1)->andReturn($getResponse);

$this->client->setHttpClient($http_client);

$history = $this->client->getDriverProfile();
}

public function testGetDriverPayments()
{
$params = [
'limit' => 1,
'offset' => 1
];

$this->client->setVersion('v1.1');

$getResponse = m::mock('GuzzleHttp\Psr7\Response');
$getResponse->shouldReceive('getBody')->times(1)->andReturn('{"count": 1200,"limit": 1,"payments": [{"payment_id": "5cb8304c-f3f0-4a46-b6e3-b55e020750d7","category": "fare","event_time": 1502842757,"trip_id": "5cb8304c-f3f0-4a46-b6e3-b55e020750d7","cash_collected": 0,"amount": 3.12,"driver_id": "8LvWuRAq2511gmr8EMkovekFNa2848lyMaQevIto-aXmnK9oKNRtfTxYLgPq9OSt8EzAu5pDB7XiaQIrcp-zXgOA5EyK4h00U6D1o7aZpXIQah--U77Eh7LEBiksj2rahB==","breakdown": {"other": 4.16,"toll": 1,"service_fee": -1.04},"rider_fees": {"split_fare": 0.50},"partner_id": "8LvWuRAq2511gmr8EMkovekFNa2848lyMaQevIto-aXmnK9oKNRtfTxYLgPq9OSt8EzAu5pDB7XiaQIrcp-zXgOA5EyK4h00U6D1o7aZpXIQah--U77Eh7LEBiksj2rahB==","currency_code": "USD"}],"offset": 0}');
$getResponse->shouldReceive('getHeader')->times(3)->andReturnValues([1000, 955, strtotime("+1 day")]);

$http_client = m::mock('GuzzleHttp\Client');
$http_client->shouldReceive('get')
->with($this->client->getUrlFromPath('/partners/payments'), ['headers' => $this->client->getHeaders(), 'query' => $params])
->times(1)->andReturn($getResponse);

$this->client->setHttpClient($http_client);

$history = $this->client->getDriverPayments($params);
}

public function testGetDriverTrips()
{
$params = [
'limit' => 1,
'offset' => 1
];

$this->client->setVersion('v1.1');

$getResponse = m::mock('GuzzleHttp\Psr7\Response');
$getResponse->shouldReceive('getBody')->times(1)->andReturn('{"count": 1200,"limit": 1,"trips": [{"fare": 6.2,"dropoff": {"timestamp": 1502844378},"vehicle_id": "0082b54a-6a5e-4f6b-b999-b0649f286381","distance": 0.37,"start_city": {"latitude": 38.3498,"display_name": "Charleston, WV","longitude": -81.6326},"status_changes": [{"status": "accepted","timestamp": 1502843899},{"status": "driver_arrived","timestamp": 1502843900},{"status": "trip_began","timestamp": 1502843903},{"status": "completed","timestamp": 1502844378}],"surge_multiplier": 1,"pickup": {"timestamp": 1502843903},"driver_id": "8LvWuRAq2511gmr8EMkovekFNa2848lyMaQevIto-aXmnK9oKNRtfTxYLgPq9OSt8EzAu5pDB7XiaQIrcp-zXgOA5EyK4h00U6D1o7aZpXIQah--U77Eh7LEBiksj2rahB==","status": "completed","duration": 475,"trip_id": "b5613b6a-fe74-4704-a637-50f8d51a8bb1","currency_code": "USD"}],"offset": 0}');
$getResponse->shouldReceive('getHeader')->times(3)->andReturnValues([1000, 955, strtotime("+1 day")]);

$http_client = m::mock('GuzzleHttp\Client');
$http_client->shouldReceive('get')
->with($this->client->getUrlFromPath('/partners/trips'), ['headers' => $this->client->getHeaders(), 'query' => $params])
->times(1)->andReturn($getResponse);

$this->client->setHttpClient($http_client);

$history = $this->client->getDriverTrips($params);
}

public function testRequestRide()
{
$params = [
Expand Down Expand Up @@ -488,7 +552,7 @@ public function testGetRequestReceipt()
$receipt = $this->client->getRequestReceipt($request_id);
}

public function test_Get_Request_Map()
public function testGetRequestMap()
{
$request_id = 'mock_request_id';

Expand Down

0 comments on commit 9b837dd

Please sign in to comment.