Skip to content

Latest commit

 

History

History
185 lines (146 loc) · 6.47 KB

README.md

File metadata and controls

185 lines (146 loc) · 6.47 KB

UberKit

UberKit is a simple Objective-C wrapper for the new Uber API .

Installation

Cocoapods

UberKit is available through Cocoapods. To install it, simply add the following to your Podfile. ``` pod 'UberKit' ```

Alternative

Alternatively, you can always just drag and drop the folder 'UberKit' into your project and ``#import "UberKit.h"`` and you're good to go.

Basic API Implementation

This is to implement the Uber API without having users sign in to their Uber account.

To implement UberKit, first initialize it with your server token.

You can get your server token from Uber Developers.

  UberKit *uberKit = [[UberKit alloc] initWithServerToken:@"YOUR_SERVER_TOKEN"];

Alternatively, you can set your server token to a shared instance of UberKit as follows:

    [[UberKit sharedInstance] setServerToken:@"YOUR_SERVER_TOKEN"];

To get all products available from a particular location

 [uberKit getProductsForLocation:location withCompletionHandler:^(NSArray *products, NSURLResponse *response, NSError *error)
     {
         if(!error)
         {
             //Got the array of available products for the location.
         }
         else
         {
             NSLog(@"Error %@", error);
         }
     }];

To get the time for arrival of a product to a particular location

[uberKit getTimeForProductArrivalWithLocation:location withCompletionHandler:^(NSArray *times, NSURLResponse *response, NSError *error)
     {
         if(!error)
         {
             //Got the array of available products and the time they'll take to reach the mentioned location.
         }
         else
         {
             NSLog(@"Error %@", error);
         }
     }];

To get the price for a trip between two locations

[uberKit getPriceForTripWithStartLocation:location endLocation:endLocation  withCompletionHandler:^(NSArray *prices, NSURLResponse *response, NSError *error)
     {
         if(!error)
         {
             //Got the array of available products and the price of a trip from the start location to the end location.
         }
         else
         {
             NSLog(@"Error %@", error);
         }
     }];

To get the available promotion for a trip between two locations

[uberKit getPromotionForLocation:location endLocation:endLocation withCompletionHandler:^(UberPromotion *promotion, NSURLResponse *response,  NSError *error)
     {
        if(!error)
        {
            //Got the promotion as an UberPromotion
        }
        else
        {
            NSLog(@"Error %@", error);
        }
     }];

OAuth implementation

Introduction

This is to implement the Uber API with endpoints that require user authorization such as user history and profile. The authorization process is implemented by:

  1. Allowing the users to sign in to their Uber accounts.

  2. Obtaining an access token on user approval of app's permissions.

  3. Using this access token to make calls to the Uber API.

UberKit automatically redirects to Safari where users enter their Uber login credentials to allow access to their profiles.

Implementation

Before you can get started using UberKit with login parameters, you must first create an Uber application at Uber Developers and fill in all necessary fields.

[Note: To gain access to the user's profile and history, ensure that you have these permissions enabled in your app's dashboard]

To implement UberKit with authorization from the user first initialize it with your client id, client secret, redirect URI and application name from the application you made on Uber Developer.

UberKit *uberKit = [[UberKit alloc] initWithClientID:@"YOUR_CLIENT_ID" ClientSecret:@"YOUR_CLIENT_SECRET" RedirectURL:@"YOUR_REDIRECT_URL" ApplicationName:@"YOUR_APPLICATION_NAME"]; //Set these fields from your app on Uber Developers.
uberKit.delegate = self; //Set the delegate (only for login)

Add the UberKit delegate to the @interface of your view controller to detect when an Uber access token becomes available for use after successful authorization. Then, you must add the following methods to your view controller:

- (void) uberKit: (UberKit *) uberKit didReceiveAccessToken: (NSString *) accessToken
{
    //Got the access token, can now make requests for user data
}
- (void) uberKit: (UberKit *) uberKit loginFailedWithError: (NSError *) error
{
    //An error occurred in the login process
}

You can also retrieve the access token when it is available by using NSString *token = [[UberKit sharedInstance] getStoredAuthToken];

To begin the login process, call the method 'startLogin' using [uberKit startLogin];

Once you've successfully retrieved an access token, you can then make the following calls to the Uber API :

To get all activity by the user

[uberKit getUserActivityWithCompletionHandler:^(NSArray *activities, NSURLResponse *response, NSError *error)
         {
             if(!error)
             {
                 //Got an array of the history of activities performed by the user
             }
             else
             {
                 NSLog(@"Error %@", error);
             }
         }];

To get the profile of the user

[uberKit getUserProfileWithCompletionHandler:^(UberProfile *profile, NSURLResponse *response, NSError *error)
         {
             if(!error)
             {
                 //Got the user's profile as an UberProfile
             }
             else
             {
                 NSLog(@"Error %@", error);
             }
         }];

For more help, check out the Demo !

For any assistance, reach out to me on Twitter @sachinkesiraju

Featured In

Let me know where you use UberKit so I can add it here!

Community

If you feel that you can contribute to improving UberKit or add a new feature, feel free to raise an issue/submit a PR.

License

UberKit is available under the MIT License. See the LICENSE for more information.