Skip to content

guizmo51/uber-php

 
 

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.0"
  }

Run composer update

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'
));

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

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%