Skip to content

Latest commit

 

History

History
30 lines (28 loc) · 5.11 KB

COMPLETION_STATUS.md

File metadata and controls

30 lines (28 loc) · 5.11 KB

completion status

Provides an almost one-to-one mapping of Uber REST API methods to those in this API client.

Table of contents

Rides API

Uber API Method API Method Completion Status Notes Description
GET /authorize oauth2.Authorize ✔️ Authentication Allows you to redirect a user to the authorization URL for your application. See samples

uber/cmd/uber/main.go

Lines 111 to 130 in 1c064b6

scopes := []string{
oauth2.ScopeProfile, oauth2.ScopeRequest,
oauth2.ScopeHistory, oauth2.ScopePlaces,
oauth2.ScopeRequestReceipt, oauth2.ScopeDelivery,
// To allow for driver information retrieval
oauth2.ScopePartnerAccounts,
oauth2.ScopePartnerPayments,
oauth2.ScopePartnerTrips,
}
token, err := oauth2.AuthorizeByEnvApp(scopes...)
if err != nil {
log.Fatal(err)
}
blob, err := json.Marshal(token)
if err != nil {
log.Fatal(err)
}
and

uber/oauth2/oauth2.go

Lines 209 to 257 in 1c064b6

func Authorize(oconfig *OAuth2AppConfig, scopes ...string) (*oauth2.Token, error) {
config := &oauth2.Config{
ClientID: oconfig.ClientID,
ClientSecret: oconfig.ClientSecret,
Scopes: scopes,
Endpoint: oauth2.Endpoint{
AuthURL: OAuth2AuthURL,
TokenURL: OAuth2TokenURL,
},
RedirectURL: oconfig.RedirectURL,
}
srvAddr := ":8889"
if config.RedirectURL == "" {
config.RedirectURL = fmt.Sprintf("http://localhost%s/", srvAddr)
}
state := fmt.Sprintf("%v%f", time.Now().Unix(), rand.Float32())
urlToVisit := config.AuthCodeURL(state, oauth2.AccessTypeOffline)
fmt.Printf("Please visit this URL for the auth dialog: %v\n", urlToVisit)
callbackURLChan := make(chan url.Values)
go func() {
http.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
query := req.URL.Query()
callbackURLChan <- query
fmt.Fprintf(rw, "Received the token successfully. Please return to your terminal")
})
defer close(callbackURLChan)
if err := http.ListenAndServe(srvAddr, nil); err != nil {
log.Fatal(err)
}
}()
urlValues := <-callbackURLChan
gotState, wantState := urlValues.Get("state"), state
if gotState != wantState {
return nil, fmt.Errorf("states do not match: got: %q want: %q", gotState, wantState)
}
code := urlValues.Get("code")
ctx := context.Background()
token, err := config.Exchange(ctx, code)
if err != nil {
return nil, err
}
return token, nil
}
POST /token oauth2.Authorize ✔️ Authentication The Login endpoint that allows you to authorize your application and get an access token using the authorization code or client credentials grant. See for example, see samples

uber/cmd/uber/main.go

Lines 111 to 130 in 1c064b6

scopes := []string{
oauth2.ScopeProfile, oauth2.ScopeRequest,
oauth2.ScopeHistory, oauth2.ScopePlaces,
oauth2.ScopeRequestReceipt, oauth2.ScopeDelivery,
// To allow for driver information retrieval
oauth2.ScopePartnerAccounts,
oauth2.ScopePartnerPayments,
oauth2.ScopePartnerTrips,
}
token, err := oauth2.AuthorizeByEnvApp(scopes...)
if err != nil {
log.Fatal(err)
}
blob, err := json.Marshal(token)
if err != nil {
log.Fatal(err)
}
and

uber/oauth2/oauth2.go

Lines 209 to 257 in 1c064b6

func Authorize(oconfig *OAuth2AppConfig, scopes ...string) (*oauth2.Token, error) {
config := &oauth2.Config{
ClientID: oconfig.ClientID,
ClientSecret: oconfig.ClientSecret,
Scopes: scopes,
Endpoint: oauth2.Endpoint{
AuthURL: OAuth2AuthURL,
TokenURL: OAuth2TokenURL,
},
RedirectURL: oconfig.RedirectURL,
}
srvAddr := ":8889"
if config.RedirectURL == "" {
config.RedirectURL = fmt.Sprintf("http://localhost%s/", srvAddr)
}
state := fmt.Sprintf("%v%f", time.Now().Unix(), rand.Float32())
urlToVisit := config.AuthCodeURL(state, oauth2.AccessTypeOffline)
fmt.Printf("Please visit this URL for the auth dialog: %v\n", urlToVisit)
callbackURLChan := make(chan url.Values)
go func() {
http.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
query := req.URL.Query()
callbackURLChan <- query
fmt.Fprintf(rw, "Received the token successfully. Please return to your terminal")
})
defer close(callbackURLChan)
if err := http.ListenAndServe(srvAddr, nil); err != nil {
log.Fatal(err)
}
}()
urlValues := <-callbackURLChan
gotState, wantState := urlValues.Get("state"), state
if gotState != wantState {
return nil, fmt.Errorf("states do not match: got: %q want: %q", gotState, wantState)
}
code := urlValues.Get("code")
ctx := context.Background()
token, err := config.Exchange(ctx, code)
if err != nil {
return nil, err
}
return token, nil
}
PATCH /me client.ApplyPromoCode ✔️ Allows you to apply a promocode to your account. See

uber/example_test.go

Lines 202 to 214 in 1c064b6

func Example_client_ApplyPromoCode() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
appliedPromoCode, err := client.ApplyPromoCode("uberd340ue")
if err != nil {
log.Fatal(err)
}
fmt.Printf("AppliedPromoCode: %#v\n", appliedPromoCode)
}
GET /history client.ListHistory ✔️ Retrieve the history of your trips. See

uber/example_test.go

Lines 45 to 80 in 1c064b6

func Example_client_ListHistory() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
pagesChan, cancelPaging, err := client.ListHistory(&uber.Pager{
MaxPages: 4,
LimitPerPage: 10,
StartOffset: 0,
})
if err != nil {
log.Fatal(err)
}
for page := range pagesChan {
if page.Err != nil {
fmt.Printf("Page: #%d err: %v\n", page.PageNumber, page.Err)
continue
}
fmt.Printf("Page: #%d\n\n", page.PageNumber)
for i, trip := range page.Trips {
startCity := trip.StartCity
if startCity.Name == "Tokyo" {
fmt.Printf("aha found the first Tokyo trip, canceling any more requests!: %#v\n", trip)
cancelPaging()
break
}
// Otherwise, continue listing
fmt.Printf("Trip: #%d ==> %#v place: %#v\n", i, trip, startCity)
}
}
}
GET /payment-methods client.ListPaymentMethods ✔️ Retrieves your payment methods. See

uber/example_test.go

Lines 26 to 43 in 1c064b6

func Example_client_ListPaymentMethods() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
listings, err := client.ListPaymentMethods()
if err != nil {
log.Fatal(err)
}
fmt.Printf("LastUsedD: %v\n", listings.LastUsedID)
for i, method := range listings.Methods {
fmt.Printf("#%d: ID: %q PaymentMethod: %q Description: %q\n",
i, method.ID, method.PaymentMethod, method.Description)
}
}
GET /places/{place_id} client.Place ✔️ Retrieves either your HOME or WORK addresses, if set. See

uber/example_test.go

Lines 230 to 242 in 1c064b6

func Example_client_RetrieveHomeAddress() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
place, err := client.Place(uber.PlaceHome)
if err != nil {
log.Fatal(err)
}
fmt.Printf("My home address: %#v\n", place.Address)
}
and

uber/example_test.go

Lines 244 to 256 in 1c064b6

func Example_client_RetrieveWorkAddress() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
place, err := client.Place(uber.PlaceWork)
if err != nil {
log.Fatal(err)
}
fmt.Printf("My work address: %#v\n", place.Address)
}
PUT /places/{place_id} client.UpdatePlace ✔️ Updates either your HOME or WORK addresses. See

uber/example_test.go

Lines 258 to 273 in 1c064b6

func Example_client_UpdateHomeAddress() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
updatedHome, err := client.UpdatePlace(&uber.PlaceParams{
Place: uber.PlaceHome,
Address: "685 Market St, San Francisco, CA 94103, USA",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("My updated home address: %#v\n", updatedHome)
}
and

uber/example_test.go

Lines 275 to 290 in 1c064b6

func Example_client_UpdateWorkAddress() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
updatedWork, err := client.UpdatePlace(&uber.PlaceParams{
Place: uber.PlaceWork,
Address: "685 Market St, San Francisco, CA 94103, USA",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("My updated work address: %#v\n", updatedWork)
}
GET /products client.ListProducts ✔️ Allows you to get a list of products/car options at a location. See

uber/example_test.go

Lines 439 to 456 in 1c064b6

func Example_client_ListProducts() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
products, err := client.ListProducts(&uber.Place{
Latitude: 38.8971,
Longitude: -77.0366,
})
if err != nil {
log.Fatal(err)
}
for i, product := range products {
fmt.Printf("#%d: ID: %q Product: %#v\n", i, product.ID, product)
}
}
GET /products/{product_id} client.ProductByID Retrieves a product/car option by its ID. See

uber/example_test.go

Lines 458 to 470 in 1c064b6

func Example_client_ProductByID() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
product, err := client.ProductByID("bc300c14-c30d-4d3f-afcb-19b240c16a13")
if err != nil {
log.Fatal(err)
}
fmt.Printf("The Product information: %#v\n", product)
}
GET /estimates/price client.EstimatePrice Returns an estimated price range for each product offered at a given location. See

uber/example_test.go

Lines 114 to 148 in 1c064b6

func Example_client_EstimatePrice() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
estimatesPageChan, cancelPaging, err := client.EstimatePrice(&uber.EstimateRequest{
StartLatitude: 37.7752315,
EndLatitude: 37.7752415,
StartLongitude: -122.418075,
EndLongitude: -122.518075,
SeatCount: 2,
})
if err != nil {
log.Fatal(err)
}
itemCount := uint64(0)
for page := range estimatesPageChan {
if page.Err != nil {
fmt.Printf("PageNumber: #%d err: %v", page.PageNumber, page.Err)
continue
}
for i, estimate := range page.Estimates {
itemCount += 1
fmt.Printf("Estimate: #%d ==> %#v\n", i, estimate)
}
if itemCount >= 23 {
cancelPaging()
}
}
}
GET /estimates/time client.EstimateTime ✔️ Returns ETAs for all products currently available at a given location. See

uber/example_test.go

Lines 150 to 186 in 1c064b6

func Example_client_EstimateTime() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
estimatesPageChan, cancelPaging, err := client.EstimateTime(&uber.EstimateRequest{
StartLatitude: 37.7752315,
EndLatitude: 37.7752415,
StartLongitude: -122.418075,
EndLongitude: -122.518075,
// Comment out to search only for estimates for: uberXL
// ProductID: "821415d8-3bd5-4e27-9604-194e4359a449",
})
if err != nil {
log.Fatal(err)
}
itemCount := uint64(0)
for page := range estimatesPageChan {
if page.Err != nil {
fmt.Printf("PageNumber: #%d err: %v", page.PageNumber, page.Err)
continue
}
for i, estimate := range page.Estimates {
itemCount += 1
fmt.Printf("Estimate: #%d ==> %#v\n", i, estimate)
}
if itemCount >= 23 {
cancelPaging()
}
}
}
GET /requests/estimate client.UpfrontFare ✔️ Privileged scope, so needs an OAuth2.0 authorized client. This method is needed before you request a ride Allows retrieve the upfront fare for all products currently available at a given location. See

uber/example_test.go

Lines 317 to 343 in 1c064b6

func Example_client_UpfrontFare() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
upfrontFare, err := client.UpfrontFare(&uber.EstimateRequest{
StartLatitude: 37.7752315,
EndLatitude: 37.7752415,
StartLongitude: -122.418075,
EndLongitude: -122.518075,
SeatCount: 2,
})
if err != nil {
log.Fatal(err)
}
if upfrontFare.SurgeInEffect() {
fmt.Printf("Surge is in effect!\n")
fmt.Printf("Please visit this URL to confirm %q then"+
"request again", upfrontFare.Estimate.SurgeConfirmationURL)
return
}
fmt.Printf("Fare: %#v\n", upfrontFare.Fare)
fmt.Printf("Trip: %#v\n", upfrontFare.Trip)
}
POST /requests client.RequestRide ✔️ Privileged scope, OAuth2.0 bearer token with the request scope. Requires you to pass in the FareID retrieved from client.UpfrontFare See

uber/example_test.go

Lines 345 to 368 in 1c064b6

func Example_client_RequestRide() {
client, err := uber.NewClientFromOAuth2File(os.ExpandEnv("$HOME/.uber/credentials.json"))
if err != nil {
log.Fatal(err)
}
ride, err := client.RequestRide(&uber.RideRequest{
StartLatitude: 37.7752315,
StartLongitude: -122.418075,
EndLatitude: 37.7752415,
EndLongitude: -122.518075,
PromptOnFare: func(fare *uber.UpfrontFare) error {
if fare.Fare.Value >= 6.00 {
return fmt.Errorf("exercise can't hurt instead of $6.00 for that walk!")
}
return nil
},
})
if err != nil {
log.Fatalf("ride request err: %v", err)
}
fmt.Printf("Your ride information: %+v\n", ride)
}
GET /requests/current client.CurrentTrip ✔️ Requires privileged scope all_trips to be set Retrieve details of an ongoing trip
PATCH /requests/current ✖️ Unimplemented Update an ongoing trip's destination
DELETE /requests/current ✖️ Unimplemented Cancel the ongoing trip
GET /requests/{request_id} client.TripByID ✔️ Requires privileged scope all_trips to be set Retrieve the details of an ongoing or completed trip that was created by your app, by the trip's ID
PATCH /requests/{request_id} ✖️ Unimplemented Update the ongoing request's destination using the Ride Request endpoint
DELETE /requests/{request_id} Unimplemented Cancel the ongoing request on behalf of a rider
GET /requests/{request_id}/map client.OpenMap ✔️ This method is only available after a trip has been accepted by a driver and is in the accepted state
GET /requests/{request_id}/receipt client.RequestReceipt ✔️ A privileged scope, whose output is only available after the requests.receipt_ready webhook notification is sent The trip receipt may be adjusted after the requests.receipt_ready webhook is sent as finalized receipts can be delayed. See

uber/example_test.go

Lines 216 to 228 in 1c064b6

func Example_client_RequestReceipt() {
client, err := uber.NewClient()
if err != nil {
log.Fatal(err)
}
receipt, err := client.RequestReceipt("b5512127-a134-4bf4-b1ba-fe9f48f56d9d")
if err != nil {
log.Fatal(err)
}
fmt.Printf("That receipt: %#v\n", receipt)
}