2017 © Pedro Peláez
 

library uber-php

A php client for consuming the Uber API

image

stevenmaguire/uber-php

A php client for consuming the Uber API

  • Thursday, August 24, 2017
  • by stevenmaguire
  • Repository
  • 6 Watchers
  • 41 Stars
  • 4,509 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 27 Forks
  • 2 Open issues
  • 3 Versions
  • 104 % Grown

The README.md

Uber PHP Client

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads, (*1)

A PHP client for authenticating with Uber using OAuth 2.0 and consuming the API., (*2)

This package is intended to be used for communicating with the Uber API after you've secured an access token from your users. To authenticate users and retrieve access tokens, use stevenmaguire/oauth2-uber., (*3)

Install

Via Composer, (*4)

``` bash $ composer require stevenmaguire/uber-php, (*5)


> Note that the required version of PHP is 5.5. If you want use library with PHP 5.4 you should use 1.2.0 version. ## Usage ### Create client ```php $client = new Stevenmaguire\Uber\Client(array( 'access_token' => 'YOUR ACCESS TOKEN', 'server_token' => 'YOUR SERVER TOKEN', 'use_sandbox' => true, // optional, default false 'version' => 'v1.2', // optional, default 'v1.2' 'locale' => 'en_US', // optional, default 'en_US' ));

Please review the Sandbox documentation on how to develop and test against these endpoints without making real-world Requests and being charged., (*6)

Get Products

By location:

$products = $client->getProducts(array(
    'latitude' => '41.85582993',
    'longitude' => '-87.62730337'
));

https://developer.uber.com/docs/riders/references/api/v1.2/products-get, (*7)

By Id:

$product = $client->getProduct($productId);

https://developer.uber.com/docs/riders/references/api/v1.2/products-product_id-get, (*8)

Get Price Estimates

$estimates = $client->getPriceEstimates(array(
    'start_latitude' => '41.85582993',
    'start_longitude' => '-87.62730337',
    'end_latitude' => '41.87499492',
    'end_longitude' => '-87.67126465'
));

https://developer.uber.com/docs/riders/references/api/v1.2/estimates-price-get, (*9)

Get Time Estimates

$estimates = $client->getTimeEstimates(array(
    'start_latitude' => '41.85582993',
    'start_longitude' => '-87.62730337'
));

https://developer.uber.com/docs/riders/references/api/v1.2/estimates-time-get, (*10)

Get Promotions

$promotions = $client->getPromotions(array(
    'start_latitude' => '41.85582993',
    'start_longitude' => '-87.62730337',
    'end_latitude' => '41.87499492',
    'end_longitude' => '-87.67126465'
));

https://developer.uber.com/docs/riders/ride-promotions/introduction, (*11)

Get User Activity

This feature is only available since version 1.1., (*12)

$client->setVersion('v1.2'); // or v1.1
$history = $client->getHistory(array(
    'limit' => 50, // optional
    'offset' => 0 // optional
));

https://developer.uber.com/docs/riders/references/api/v1.2/history-get, (*13)

Get User Profile

$profile = $client->getProfile();

https://developer.uber.com/docs/riders/references/api/v1.2/me-get, (*14)

Update User Profile

$attributes = array('applied_promotion_codes' => 'PROMO_CODE');
$profileResponse = $client->setProfile($attributes);

https://developer.uber.com/docs/riders/references/api/v1.2/me-patch, (*15)

Get Payment Methods

$paymentMethods = $client->getPaymentMethods();

https://developer.uber.com/docs/riders/references/api/v1.2/payment-methods-get, (*16)

Get Place

$placeId = 'home';
$place = $client->getPlace($placeId);

https://developer.uber.com/docs/riders/references/api/v1.2/places-place_id-get, (*17)

Update a Place

$placeId = 'home';
$attributes = array('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, (*18)

Request A Ride

$request = $client->requestRide(array(
    'start_latitude' => '41.85582993',
    'start_longitude' => '-87.62730337',
    'end_latitude' => '41.87499492',
    'end_longitude' => '-87.67126465',
    'product_id' => '4bfc6c57-98c0-424f-a72e-c1e2a1d49939', // Optional
    'surge_confirmation_id' => 'e100a670',                  // Optional
    'payment_method_id' => 'a1111c8c-c720-46c3-8534-2fcd'   // Optional
));

Upfront Fares

Upfront fares means the total fare is known before the ride is taken., (*19)

  • An end location is required
  • There is no surge confirmation flow
  • The user should specify a fare_id to confirm consent to the upfront fare
  • The user should specify the number of seats that are required for shared products (like UberPOOL)
  1. In the products endpoint GET /products, products will have the upfront_fare_enabled field set to true.
  2. Use the ride request estimate endpoint POST /requests/estimate with the product_id to get a fare_id. The fare_id can be used to lock down an upfront fare and arrival time for a trip. The fare_id expires after two minutes. If the fare_id is expired or not valid, we return a 422 error.
  3. Request the ride using the ride request endpoint POST /requests with the fare_id returned in the previous step.

https://developer.uber.com/docs/riders/ride-requests/tutorials/api/best-practices#upfront-fares, (*20)

Surge Confirmation Flow

If the ride request is using a product that has a surge multiplier, the API wrapper will throw an Exception and provide a response body that includes a surge confirmation ID., (*21)

try {
    $request = $client->requestRide(array(
        'product_id' => '4bfc6c57-98c0-424f-a72e-c1e2a1d49939',
        'start_latitude' => '41.85582993',
        'start_longitude' => '-87.62730337',
        'end_latitude' => '41.87499492',
        'end_longitude' => '-87.67126465'
    ));
} catch (Stevenmaguire\Uber\Exception $e) {
    $body = $e->getBody();
    $surgeConfirmationId = $body['meta']['surge_confirmation']['surge_confirmation_id'];
}

https://developer.uber.com/docs/riders/ride-requests/tutorials/api/best-practices#handling-surge-pricing, (*22)

Get Current Ride Details

$request = $client->getCurrentRequest();

https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-get, (*23)

Get Ride Details

$request = $client->getRequest($requestId);

https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-get, (*24)

Update Current Ride Details

$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, (*25)

Update Ride Details

$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, (*26)

Get Ride Estimate

$requestEstimate = $client->getRequestEstimate(array(
    'product_id' => '4bfc6c57-98c0-424f-a72e-c1e2a1d49939',
    'start_latitude' => '41.85582993',
    'start_longitude' => '-87.62730337',
    'end_latitude' => '41.87499492', // optional
    'end_longitude' => '-87.67126465', // optional
));

https://developer.uber.com/docs/riders/references/api/v1.2/requests-estimate-post, (*27)

Get Ride Map

$map = $client->getRequestMap($requestId);

https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-map-get, (*28)

Get Ride Receipt

$receipt = $client->getRequestReceipt($requestId);

https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-receipt-get, (*29)

Cancel Current Ride

$request = $client->cancelCurrentRequest();

https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-delete, (*30)

Cancel Ride

$request = $client->cancelRequest($requestId);

https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-delete, (*31)

Create Reminder

$attributes = array(
    'reminder_time' => '1429294463',
    'phone_number' => '555-555-5555',
    'event' => array(
        'time' => '1429294463',
        'name' => 'Frisbee with friends',
        'location' => 'Dolores Park',
        'latitude' => '37.759773',
        'longitude' => '-122.427063',
    ),
    'product_id' => 'a1111c8c-c720-46c3-8534-2fcdd730040d',
    'trip_branding' => array(
        '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, (*32)

Get Reminder

$reminderId = '4bfc6c57-98c0-424f-a72e-c1e2a1d49939';
$reminder = $client->getReminder($reminderId);

https://developer.uber.com/docs/riders/references/api/v1.2/reminders-reminder_id-get, (*33)

Update Reminder

$reminderId = '4bfc6c57-98c0-424f-a72e-c1e2a1d49939';
$attributes = array(
    'reminder_time' => '1429294463',
    'phone_number' => '555-555-5555',
    'event' => array(
        'time' => '1429294463',
        'name' => 'Frisbee with friends',
        'location' => 'Dolores Park',
        'latitude' => '37.759773',
        'longitude' => '-122.427063',
    ),
    'product_id' => 'a1111c8c-c720-46c3-8534-2fcdd730040d',
    'trip_branding' => array(
        '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, (*34)

Cancel Reminder

$reminderId = '4bfc6c57-98c0-424f-a72e-c1e2a1d49939';
$reminder = $client->cancelReminder($reminderId);

https://developer.uber.com/docs/riders/references/api/v1.2/reminders-reminder_id-delete, (*35)

Get Driver Profile

$profile = $client->getDriverProfile();

https://developer.uber.com/docs/drivers/references/api/v1/partners-me-get, (*36)

Get Driver Payments

$profile = $client->getDriverPayments(array(
    'limit' => 50, // optional
    'offset' => 0 // optional
));

https://developer.uber.com/docs/drivers/references/api/v1/partners-payments-get, (*37)

Get Driver Trips

$profile = $client->getDriverTrips(array(
    'limit' => 50, // optional
    'offset' => 0 // optional
));

https://developer.uber.com/docs/drivers/references/api/v1/partners-trips-get, (*38)

Rate Limiting

This feature is only supported for v1 version of the API., (*39)

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., (*40)

When consuming the service with this package, your rate limit status will be made available within the client., (*41)

$product = $client->getProduct($productId);

$rateLimit = $client->getRateLimit();

$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., (*42)

https://developer.uber.com/v1/api-reference/#rate-limiting, (*43)

Using the Sandbox

Modify the status of an ongoing sandbox Request., (*44)

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., (*45)

$request = $client->requestRide(array(
    'product_id' => '4bfc6c57-98c0-424f-a72e-c1e2a1d49939',
    'start_latitude' => '41.85582993',
    'start_longitude' => '-87.62730337',
    'end_latitude' => '41.87499492',
    'end_longitude' => '-87.67126465'
));

$updateRequest = $client->setSandboxRequest($request->request_id, array('status' => 'accepted'));

https://developer.uber.com/v1/sandbox/#request, (*46)

Simulate the possible responses the Request endpoint will return when requesting a particular product, such as surge pricing, against the Sandbox., (*47)

$product = $client->getProduct($productId);

$updateProduct = $client->setSandboxProduct($productId, array('surge_multiplier' => 2.2, 'drivers_available' => false));

https://developer.uber.com/v1/sandbox/#product-types, (*48)

Testing

bash $ ./vendor/bin/phpunit, (*49)

Contributing

Please see CONTRIBUTING for details., (*50)

Credits

License

The MIT License (MIT). Please see License File for more information., (*51)

The Versions

24/08 2017

dev-master

9999999-dev http://github.com/stevenmaguire/uber-php

A php client for consuming the Uber API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php oauth2 uber

22/11 2016

dev-support-version-1.2

dev-support-version-1.2 http://github.com/stevenmaguire/uber-php

A php client for consuming the Uber API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php oauth2 uber

24/03 2015

1.0.0

1.0.0.0 http://github.com/stevenmaguire/uber-php

A php client for consumer Uber API

  Sources   Download

MIT

The Requires

 

The Development Requires