Documentation ¶
Overview ¶
Package uber provides an api client for the Uber api. It exposes methods to get information about Uber products, estimates, times, and users.
A lot of documentation will be pulled directly from https://developer.uber.com/v1/endpoints
Index ¶
- Constants
- Variables
- type Access
- type Client
- func (c *Client) AutOAuth(scope ...string) error
- func (c *Client) CancelRequest(requestID string) error
- func (c *Client) CreateRequest(productID string, start *Location, end *Location, surgeConfirmationID string) (*Request, error)
- func (c *Client) GetPrices(startLat, startLon, endLat, endLon float64) ([]*Price, error)
- func (c *Client) GetProducts(lat, lon float64) ([]*Product, error)
- func (c *Client) GetRequest(requestID string) (*Request, error)
- func (c *Client) GetTimes(startLat, startLon float64, uuid, productID string) ([]*Time, error)
- func (c *Client) GetUserActivity(offset, limit int) (*UserActivity, error)
- func (c *Client) GetUserProfile() (*User, error)
- func (c *Client) OAuth(scope ...string) (string, error)
- func (c *Client) RefreshAccessToken() error
- func (c *Client) SetAccessToken(authorizationCode string) error
- func (c *Client) SetAuth(clientID, clientSecret, redirect string)
- type Location
- type Price
- type Product
- type Request
- type Time
- type Trip
- type User
- type UserActivity
Constants ¶
const ( Version = "v1" ProductEndpoint = "products" PriceEndpoint = "estimates/price" TimeEndpoint = "estimates/time" HistoryEndpoint = "history" UserEndpoint = "me" RequestsEndpoint = "requests" AccessCodeEndpoint = "authorize" AccessTokenEndpoint = "token" State = "go-uber" Port = ":7635" )
Variables ¶
var ( UberAPIHost = fmt.Sprintf("https://api.uber.com/%s", Version) AuthHost = "https://login.uber.com/oauth" )
declared as vars so that unit tests can edit the values and hit internal test server
Functions ¶
This section is empty.
Types ¶
type Access ¶
type Access struct { // access_token result of three-legged OAuth 2.0 flow // Needed to make requests on behalf of a user Token string `json:"access_token"` // always "Bearer" TokenType string `json:"token_type"` // 30 days from request ExpiresIn int `json:"expires_in"` // When the user's access_token has expired, you may obtain a fresh access_token // by exchanging the refresh_token that is associated with the access_token RefreshToken string `json:"refresh_token"` // During the registration process, you'll be prompted to select the scopes your // application needs. You can also edit these preferences or add new scopes at a // later time. Users will be asked to grant permission for your application's // specific scopes when they authenticate. // // `profile` - Access the basic profile information on a user's Uber account // including their first name, email address, and profile picture. // // `history` - Pull trip data including the locations, times, and product type of // a user's historical pickups and drop-offs. Scope string `json:"scope"` }
access is returned from `AccessTokenEndpoint` See comment for `Client.access` https://developer.uber.com/v1/auth/
type Client ¶
type Client struct { // OAuth 2.0 bearer token necessary for the use of the User Activity and // User Profile endpoints. It is the result of three step authentication // outlined in https://developer.uber.com/v1/auth/#oauth-2-0. When procuring // this token, keep in mind that you must specify the history scope if you // intend to use the User Activity endpoint and the profile scope if you // intend to use the User Profile endpoint. *Access // An http.Client is needed to make requests to the API as well as do the // authentication. Rather than instantiate a new client on each request, we // memoize it here, as it will always be used. HttpClient *http.Client // contains filtered or unexported fields }
Client stores the tokens needed to access the Uber api. All methods of this package that hit said api are methods on this type.
func NewClient ¶
NewClient creates a new client. The serverToken is your API token provided by Uber. When accessing a user's profile or activity a serverToken is not enough and an accessToken must be specified with the correct scope. To access those endpoints, use `*Client.OAuth()`
func (*Client) AutOAuth ¶
AutOAuth automatically does the authorization flow by opening the user's browser, asking them to authorize, then booting up a server to deal with the user's redirect and authorizing your client.
func (*Client) CancelRequest ¶
func (*Client) CreateRequest ¶
func (*Client) GetPrices ¶
GetPrices returns an estimated price range for each product offered at a given location. The price estimate is provided as a formatted string with the full price range and the localized currency symbol.
The response also includes low and high estimates, and the ISO 4217 currency code for situations requiring currency conversion. When surge is active for a particular product, its surge_multiplier will be greater than 1, but the price estimate already factors in this multiplier. https://developer.uber.com/v1/endpoints/#price-estimates
func (*Client) GetProducts ¶
GetProducts returns information about the Uber products offered at a given location. The response includes the display name and other details about each product, and lists the products in the proper display order. https://developer.uber.com/v1/endpoints/#product-types
func (*Client) GetTimes ¶
GetTimes returns ETAs for all products offered at a given location, with the responses expressed as integers in seconds. We recommend that this endpoint be called every minute to provide the most accurate, up-to-date ETAs. The uuid and productID parameters can be empty strings. These provide additional experience customization.
func (*Client) GetUserActivity ¶
func (c *Client) GetUserActivity(offset, limit int) (*UserActivity, error)
GetUserActivity returns data about a user's lifetime activity with Uber. The response will include pickup locations and times, dropoff locations and times, the distance of past requests, and information about which products were requested.
func (*Client) GetUserProfile ¶
GetUserProfile returns information about the Uber user that has authorized with the application.
func (*Client) OAuth ¶
OAuth begins the authorization process with Uber. There's no way to do this strictly programatically because of the multi-step OAuth process. This method returns the URL that the user needs to go to in order for Uber to authorize your app and give you a authorization code.
func (*Client) RefreshAccessToken ¶
RefreshAccessToken uses the refresh token to get a new access token
func (*Client) SetAccessToken ¶
SetAccessToken completes the third step of the authorization process. Once the user generates an authorization code
type Location ¶
type Location struct { // Human-readable address // eg: "706 Mission St, San Francisco, CA" Address string `json:"address,omitempty"` // eg: 37.7860099 Latitude float64 `json:"latitude"` // eg: -122.4025387 Longitude float64 `json:"longitude"` }
Location contains a human-readable address as well as the exact coordinates of a location
type Price ¶
type Price struct { // eg: "08f17084-23fd-4103-aa3e-9b660223934b" ProductID string `json:"product_id"` // ISO 4217 currency code for situations requiring currency conversion // eg: "USD" CurrencyCode string `json:"currency_code"` // eg: "UberBLACK" DisplayName string `json:"display_name"` // Formatted string of estimate in local currency of the start location. Estimate // could be a range, a single number (flat rate) or "Metered" for TAXI. // eg: "$23-29" Estimate string `json:"estimate"` // The lowest value in the estimate for the given currency // eg: 23 LowEstimate int `json:"low_estimate"` // The highest value in the estimate for the given currency // eg: 29 HighEstimate int `json:"high_estimate"` // Uber price gouging factor // http://www.technologyreview.com/review/529961/in-praise-of-efficient-price-gouging/ // eg: 1 SurgeMultiplier float64 `json:"surge_multiplier"` }
Price contains information about a price estimate
type Product ¶
type Product struct { // Unique identifier representing a specific product for a given latitude & // longitude. For example, uberX in San Francisco will have a different // product_id than uberX in Los Angeles. // eg: "327f7914-cd12-4f77-9e0c-b27bac580d03" ProductID string `json:"product_id"` // Description of product // eg: "The original Uber" Description string `json:"description"` // eg: "UberBLACK" DisplayName string `json:"display_name"` // eg: 4 Capacity int `json:"capacity"` // A URI specifying the location of an image // eg: "http://..." Image string `json:"image"` }
Product type specifies an Uber product. An Uber product refers to a specific type of car/service.
type Request ¶
type Request struct { // The unique ID of the Request. // eg: "b2205127-a334-4df4-b1ba-fc9f28f56c96" RequestID string `json:"request_id"` // The status of the Request indicating state. // eg: "accepted" Status string `json:"status"` // The object that contains vehicle details. Vehicle struct { // The vehicle make or brand. // eg: "Bugatti" Make string `json:"make"` // The vehicle model or type. // eg: "Veyron" Model string `json:"model"` // The license plate number of the vehicle. // eg: "I<3Uber" LicensePlate string `json:"license_plate"` } `json:"vehicle"` // The object that contains driver details. Driver struct { // The formatted phone number for contacting the driver. // eg: "(555)555-5555" PhoneNumber string `json:"phone_number"` // The driver's star rating out of 5 stars. // eg: 5 Rating float64 `json:"rating"` // The URL to the photo of the driver. // eg: "https://d1w2poirtb3as9.cloudfront.net/img.jpeg" PictureURL string `json:"picture_url"` // The first name of the driver. // eg: "Bob" Name string `json:"name"` } `json:"driver"` // The object that contains the location information of the vehicle and driver. Location Location `json:"location"` // The estimated time of vehicle arrival in minutes. // eg: 4 ETA int `json:"eta"` // The surge pricing multiplier used to calculate the increased price of a Request. A multiplier of 1.0 means surge pricing is not in effect. // eg: 1.0 SurgeMultiplier float64 `json:"surge_multiplier"` }
Request is a user-requested trip See: https://developer.uber.com/v1/endpoints/#request-details
type Time ¶
type Time struct { // eg: "5f41547d-805d-4207-a297-51c571cf2a8c" ProductID string `json:"product_id"` // eg: "UberBLACK" DisplayName string `json:"display_name"` // The ETA in seconds // eg: 410, ie: 6 minutes and 50 seconds Estimate int `json:"estimate"` }
Time contains information about the estimated time of arrival for a product at a given location in seconds
type Trip ¶
type Trip struct { // Customer UUID // eg: "7354db54-cc9b-4961-81f2-0094b8e2d215" Uuid string `json:"uuid"` // Time in seconds // eg: 1401884467 RequestTime int `json:"request_time"` // eg: edf5e5eb-6ae6-44af-bec6-5bdcf1e3ed2c ProductID string `json:"product_id"` // String depicting the status of the trip. Don't know what values these could take // because the website only shows "completed" // eg: "completed" Status string `json:"status"` // Distance of request in miles (presumable that of the customer to he nearest driver) // eg: 0.0279562 Distance float64 `json:"distance"` // Start time of trip // eg: 1401884646 StartTime int `json:"start_time"` // Self explanatory (see `Location`) StartLocation *Location `json:"start_location"` // Start time of trip // eg: 1401884732 EndTime int `json:"end_time"` // Self explanatory (see `Location`) EndLocation *Location `json:"end_location"` }
Trip contains Information including the pickup location, dropoff location, request start time, request end time, and distance of requests (in miles), as well as the product type that was requested
type User ¶
type User struct { // eg: "Uber" FirstName string `json:"first_name"` // eg: "Developer" LastName string `json:"last_name"` // eg: "developer@uber.com" Email string `json:"email"` // Image URI // eg: "https://..." Picture string `json:"picture"` // Promotion code user has activated // eg: "teypo" PromoCode string `json:"promo_code"` // Unique identifier of the Uber user. UUID string `json:"uuid"` }
User is the response from the /me endpoint. Provides information about the authenticated users profile
type UserActivity ¶
type UserActivity struct { // How much the list of returned results is offset by (position in pagination) // eg: 0 Offset int `json:"offset"` // Number of items retrieved (that is, the length of `History` in this struct, // but not the total length of the history) // eg: 1 Limit int `json:"limit"` // Total number of items available // eg: 5 Count int `json:"count"` // List of trips (see `Trip`) History []*Trip `json:"history"` }
UserActivity contains data about a user's lifetime activity with Uber.