Skip to content

Gameonn/uber-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Uber PHP Client

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

A PHP client for authenticating with Uber using OAuth 2.0 and consuming the API.

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.

Install

Via Composer

$ composer require stevenmaguire/uber-php

or update your composer.json file to include:

  "require": {
    "stevenmaguire/uber-php": "~1.1"
  }

Run composer update

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

$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'
    '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.

Get Products

By location:

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

By Id:

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

https://developer.uber.com/v1/endpoints/#product-types

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/v1/endpoints/#price-estimates

Get Time Estimates

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

https://developer.uber.com/v1/endpoints/#time-estimates

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/v1/endpoints/#promotions

Get User Activity

This feature is only available in version 1.1.

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

https://developer.uber.com/v1/endpoints/#user-activity-v1-1

Get User Profile

$profile = $client->getProfile();

https://developer.uber.com/v1/endpoints/#user-profile

Request A Ride

$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',
    'surge_confirmation_id' => 'e100a670' // Optional
));

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.

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/v1/endpoints/#request

Get Ride Details

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

https://developer.uber.com/v1/endpoints/#request-details

Get Ride Map

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

https://developer.uber.com/v1/endpoints/#request-map

Cancel Ride

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

https://developer.uber.com/v1/endpoints/#request-cancel

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.

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

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

$rate_limit = $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

These values will update after each request. getRateLimit will return null after the client is created and before the first successful request.

https://developer.uber.com/v1/api-reference/#rate-limiting

Using the Sandbox

Modify the status of an ongoing sandbox Request.

$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->setRequest($request->request_id, ['status' => 'accepted']);

https://developer.uber.com/v1/sandbox/#request

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

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

$updateProduct = $client->setProduct($product_id, ['surge_multiplier' => 2.2, 'drivers_available' => false]);

https://developer.uber.com/v1/sandbox/#product-types

Testing

$ ./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

About

A php client for consuming Uber API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%