- Simple wrapper of the Uber API
- You need an app.
- All methods are async.
- All methods return an instance of UberResponse where T is the serialized Uber response data. An UberResponse also contains an Error property which will contain information in the event of an error being returned by the underlying API.
- Contains an UberSandboxClient for submitting requests against the Uber API sandbox.
Note I built this in my spare time for a bit of fun, if you've found any bugs or you'd like to contribute please get involved!
When making requests on behalf of a user via OAuth, ensure you understand scopes.
The following methods can use client OR server authentication:
- GetProductsAsync
- GetPriceEstimateAsync
- GetTimeEstimateAsync
- GetPromotionAsync
The following methods require client (OAuth) authentication:
- GetUserActivityAsync
- GetUserProfileAsync
- RequestAsync
- GetRequestDetailsAsync
- GetRequestMapAsync
- CancelRequestAsync
var uberClient = new UberClient(AccessTokenType.Server, serverToken, clientId, clientSecret, baseUri);
var uberClient = new UberClient(AccessTokenType.Server, serverToken, clientId, clientSecret, baseUri);
The web application example demonstrates how to authenticate users and execute each method.
// Create authentication client
var authClient = new UberAuthenticationClient(clientId, clientSecret);
// Generate authorize URL - If you don't specify scope, state or redirect URI then app defaults will be used
var authorizeUrl = authClient.GetAuthorizeUrl();
// Once authorized, swap authorization code for an access token
var accessToken = await authClient.GetAccessTokenAsync(code, "http://your-redirect-uri.com");
// You can now make requests on behalf of the user
var authClient = new UberAuthenticationClient(clientId, clientSecret);
var url = uberClient.GetAuthorizeUrl();
var authClient = new UberAuthenticationClient(clientId, clientSecret);
var accessToken = await uberClient.GetAccessTokenAsync(code, "http://your-redirect-uri.com");
var authClient = new UberAuthenticationClient(clientId, clientSecret);
var accessToken = await uberClient.RefreshAccessTokenAsync(refreshToken, "http://your-redirect-uri.com");
var authClient = new UberAuthenticationClient(clientId, clientSecret);
var revoked = await uberClient.RevokeAccessTokenAsync(accessToken);
var uberClient = new UberClient(AccessTokenType.Server, serverToken);
var products = await uberClient.GetProductsAsync(startLatitude, startLongitude);
var uberClient = new UberClient(AccessTokenType.Server, serverToken);
var prices = await uberClient.GetPriceEstimateAsync(startLatitude, startLongitude, endLatitude, endLongitude);
var uberClient = new UberClient(AccessTokenType.Server, serverToken);
var times = await uberClient.GetTimeEstimateAsync(startLatitude, startLongitude);
var uberClient = new UberClient(AccessTokenType.Server, serverToken);
var promotion = await uberClient.GetPromotionAsync(startLatitude, startLongitude, endLatitude, endLongitude);
var uberClient = new UberClient(AccessTokenType.Client, clientToken);
var userActivity = await uberClient.GetUserActivityAsync(0, 50);
var uberClient = new UberClient(AccessTokenType.Client, clientToken);
var userProfile = await uberClient.GetUserProfileAsync();
var uberClient = new UberClient(AccessTokenType.Client, clientToken);
var request = await uberClient.RequestAsync(productId, startLatitude, startLongitude, endLatitude, endLongitude);
var uberClient = new UberClient(AccessTokenType.Client, clientToken);
var requestDetails = await uberClient.GetRequestDetailsAsync(requestId);
var uberClient = new UberClient(AccessTokenType.Client, clientToken);
var request = await uberClient.GetRequestMapAsync(requestId);
var uberClient = new UberClient(AccessTokenType.Client, clientToken);
var cancel = await uberClient.CancelRequestAsync(requestId);
using System;
using System.Configuration;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using Newtonsoft.Json;
using Uber.SDK.Helpers;
using Uber.SDK.Models;
using WebHooks.Extensions;
namespace WebHooks.Controllers
{
public class HookController : ApiController
{
[HttpPost]
public async Task<HttpResponseMessage> Uber()
{
try
{
string json = await Request.Content.ReadAsStringAsync();
#region Webhook verification
string signature = Request.GetHeaderValue("X-Uber-Signature");
if (string.IsNullOrEmpty(signature))
return Request.CreateResponse(HttpStatusCode.Forbidden);
string clientSecret = ConfigurationManager.AppSettings["UBER.ClientSecret"];
if (!UberSignature.IsSendedByUber(clientSecret, json, signature))
return Request.CreateResponse(HttpStatusCode.Forbidden);
#endregion Webhook verification
var uberWebHookData = await JsonDeserialize<WebHook>(json);
}
catch (Exception e)
{
// log exception
return Request.CreateResponse(HttpStatusCode.OK);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
[HttpGet]
public string Test()
{
return $"Test. {DateTime.Now}. MachineName: {Environment.MachineName}. {Environment.CurrentDirectory}: {Environment.NewLine}";
}
#region Helper method
private Task<T> JsonDeserialize<T>(string jsonString)
{
Task<T> ser = Task.Factory.StartNew(() => JsonConvert.DeserializeObject<T>(jsonString));
return ser;
}
#endregion Helper method
}
}