An easy-to-use Objective-C wrapper for the Uber API (no longer supported)

Overview

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.

Comments
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods šŸ¤“ https://github.com/CocoaPods/shared_resources/tree/master/media

    Created with cocoapods-readme.

    opened by ReadmeCritic 1
  • SIG ABORT problem when lowEstimate is not returned

    SIG ABORT problem when lowEstimate is not returned

    I got response where estimated prices were not available. It caused app to crash. Log:

    2014-08-30 15:22:08.236 UberKitDemo[5996:4007] Object being sent to price { "currency_code" = USD; "display_name" = UberSUV; estimate = "$118-150"; "high_estimate" = 150; "localized_display_name" = UberSUV; "low_estimate" = 118; "product_id" = "8920cb5e-51a4-4fa4-acdf-dd86c5e18ae0"; "surge_multiplier" = 1; } 2014-08-30 15:22:08.237 UberKitDemo[5996:4007] Object being sent to price { "currency_code" = ""; "display_name" = uberTAXI; estimate = Metered; "high_estimate" = ""; "localized_display_name" = uberTAXI; "low_estimate" = ""; "product_id" = "3ab64887-4842-4c8e-9780-ccecd3a0391d"; "surge_multiplier" = 1; } 2014-08-30 15:22:08.237 UberKitDemo[5996:4007] -[NSNull intValue]: unrecognized selector sent to instance 0x1940068 2014-08-30 15:22:08.245 UberKitDemo[5996:4007] *** Terminating

    My fix: UberPrice.m, line 40: _lowEstimate = -1; _highEstimate = -1; NSString *lowE = [dictionary objectForKey:@"low_estimate"]; NSString *highE = [dictionary objectForKey:@"high_estimate"]; if ( ![lowE isKindOfClass:[NSNull class]] ) _lowEstimate = [lowE intValue]; if ( ![highE isKindOfClass:[NSNull class]] ) _highEstimate = [highE intValue];

    UberKit.m, line 92: for(int i=0; i<prices.count; i++) { NSLog(@"Object being sent to price %@", [prices objectAtIndex:i]); UberPrice *price = [[UberPrice alloc] initWithDictionary:[prices objectAtIndex:i]]; if ( price.lowEstimate > -1) //added this [availablePrices addObject:price]; }

    opened by pirtil 1
  • Use CLLocation instead of lat, long

    Use CLLocation instead of lat, long

    UberKit uses lat and long as seperate float values which makes code messy. iOS has a CLLocation type for this (which is what CoreLocation uses when you get user location).

    • (void) getProductsForLocationWithLatitude:(float)latitude longitude:(float)longitude ....

    Should be:

    • (void) getProductsForLocationWithLocation:(CLLocation*) location ...

    You can then get lat, long from the CLLocation object.

    opened by jashsayani 1
  • Major updates in the UberKit and UberKitDemo

    Major updates in the UberKit and UberKitDemo

    Updates in the UberKit:

    • Added the Uber API methods: request, request detail, cancel, receipt and map
    • Removed the local folder of the UberKit and add the reference
    • Added the option to switch between the sandbox and production base url path
    • Added more models
    • Added comments
    • Minor improvements in the UberKit class

    Updates in the UberKitDemo:

    • Your can show the products, promotions, price estimates and time estimates in a table view
    • Added the class 'UberRequestViewController'
    • Added the possibility to make a request and show the detail of the request
    • Driver and vehicle detail are displayed
    • You can contact the driver
    • You can cancel the request
    • You can see the visual representation of the request
    • You can see the completed request receipt
    opened by ghost 0
  • Payment and map issue

    Payment and map issue

    Hi, just want to consult you on two points.

    1. Can I use my own app to do the payment without Uber?
    2. Can I use my own map to locate customers and drivers during the trip?

    Thanks.

    opened by borischou 0
  • init with server token?

    init with server token?

    The UberKit.m file needs the developer to put the server token in the string const. It would be better to have:

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

    opened by jashsayani 0
  • Single completion handler?

    Single completion handler?

    iOS convention has a single completion handler for async calls, instead of a success and failure callback.

    [uberKit getPriceForTripWithStartLatitude:START_LAT startLongitude:START_LONG endLatitude:END_LAT endLongitude:END_LONG success:^(NSArray *prices) failure:^(NSError *error, NSHTTPURLResponse *response)];

    Would become:

    [uberKit getPriceForTripWithStartLatitude:START_LAT startLongitude:START_LONG endLatitude:END_LAT endLongitude:END_LONG withCompletionHandler:^(NSArray *prices, NSError *err)];

    If there is an NSError, then the message in the error can be displayed, otherwise the prices array can be accessed.

    I believe this would clean the code and make it concise.

    opened by jashsayani 0
  • Improved data model safety

    Improved data model safety

    Added if conditions to make sure app wouldn't crash when returned data was instance of NSNull and you were trying to send "intValue/integerValue etc." to the objects.

    opened by borischou 0
  • How to get access token after authorisation redirect and callback

    How to get access token after authorisation redirect and callback

    I'm authorising users of my app using Oauth 2.0 following the documentation https://developer.uber.com/v1/auth/.

    After the user authorises the app, it's hitting my web server which then redirects to app using the internal url uberkit://.

    I detect this redirect in my app. I have the following function in UberKitDemoAppDelegate.m.

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
        NSLog(@"Callback URL received");
        return YES;
    }
    

    What function do I need to call once the user is back in the app to get the access token?

    Do I need the function in UberKitDemoAppDelegate.m or should the code to get the access token be triggered automatically?

    Thanks, Pete

    opened by pxg 7
Owner
Sachin Kesiraju
Sachin Kesiraju
A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1

STTwitter A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1 Like a FOSS version of Twitter Fabric TwitterKit, without th

Nicolas Seriot 1k Nov 30, 2022
Giphy API client for iOS in Objective-C

Giphy-iOS Giphy-iOS is a Giphy API client for iOS in Objective-C. Usage To run the example project, clone the repo, and run pod install from the Examp

alex choi 52 Jul 11, 2019
ObjectiveFlickr, a Flickr API framework for Objective-C

ObjectiveFlickr ObjectiveFlickr is a Flickr API framework designed for Mac and iPhone apps. OAuth Support ObjectiveFlickr now supports Flickr's new OA

Lukhnos Liu 714 Jan 9, 2023
Unofficial Dribbble iOS wrapper allows you to integrate Dribble API into iOS application (Designer, Shot, Comment, User Story, Like, Follow)

DribbbleSDK DribbbleSDK is easy-to-use iOS wrapper for Dribbble SDK. We're working hard to complete the full coverage of available methods and make th

Agilie Team 74 Dec 2, 2020
A Swift wrapper for Foursquare API. iOS and OSX.

Das Quadrat Das Quadrat is Foursquare API wrapper written in Swift. Features Supports iOS and OSX. Covers all API endpoints. Authorization process imp

Constantine Fry 171 Jun 18, 2022
Swift Wrapper For Bittrex API

BittrexApiKit Swift client for Bittrex api. It support all APIs with most recent changes. more info here let api = Bittrex(apikey: "api key", secretke

Saeid 8 Apr 5, 2021
An API wrapper for bitFlyer.

SwiftFlyer An API wrapper for bitFlyer that supports all providing API. API Document https://lightning.bitflyer.jp/docs Usage Public API Fetch a marke

Ryo Ishikawa 39 Nov 3, 2022
A clima based app with use of API

Clima Our Goal Itā€™s time to take our app development skills to the next level. Weā€™re going to introduce you to the wonderful world of Application Prog

null 0 Nov 28, 2021
The best way to use the Zora API in your Swift projects.

ZoraKit The best way to use the Zora API in your Swift projects. Disclaimer This is still very much a work in progress, and is really a proof-of-conce

MBLA 6 Sep 23, 2022
Easy and powerful way to interact with VK API for iOS and macOS

Easy and powerful way to interact with VK API for iOS and macOS. Key features ?? It's not ios-vk-sdk ?? ?? One library for iOS and mac OS ?? ?? Fully

null 260 Dec 22, 2022
A Dropbox v2 client library written in Objective-C

TJDropbox TJDropbox is a Dropbox v2 client library written in Objective-C. When Dropbox originally announced their v2 API they included only a Swift c

Tim Johnsen 61 Dec 21, 2022
Pokeapi wrapper, written in Swift

PokemonKit What is this? PokemonKit is a swift wrapper for Pokeapi. PokemonKit use Alamofire and PromiseKit for async web requests handling. Usage imp

Continuous Learning 105 Nov 16, 2022
The Easiest and Simplest iOS library for Twitter and Facebook. Just Drop in and Use!

EasySocial iOS Library for Twitter and Facebook This library allows your apps to use Twitter and Facebook with minimal understanding of the relevant S

pj 124 Nov 17, 2022
Twitter API for Cocoa developers

FHSTwitterEngine Twitter API for Cocoa developers Created by Nathaniel Symer FHSTwitterEngine can: Authenticate using OAuth and/or xAuth. Make a reque

Nathaniel Symer 213 Jul 8, 2022
Unofficial GitHub API client in Swift

Github.swift ā¤ļø Support my apps ā¤ļø Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut

Khoa 184 Nov 25, 2022
Unified API Library for: Cloud Storage, Social Log-In, Social Interaction, Payment, Email, SMS, POIs, Video & Messaging.

Unified API Library for: Cloud Storage, Social Log-In, Social Interaction, Payment, Email, SMS, POIs, Video & Messaging. Included services are Dropbox, Google Drive, OneDrive, OneDrive for Business, Box, Egnyte, PayPal, Stripe, Google Places, Foursquare, Yelp, YouTube, Vimeo, Twitch, Facebook Messenger, Telegram, Line, Viber, Facebook, GitHub, Google+, LinkedIn, Slack, Twitter, Windows Live, Yahoo, Mailjet, Sendgrid, Twilio, Nexmo, Twizo.

CloudRail 195 Nov 29, 2021
A swift SDK for Medium's OAuth2 API

Medium SDK - Swift A library to allow access to Medium API for any Swift iOS application. Features Medium.com authorization & token handling Login sta

null 11 Jan 22, 2022
An Elegant Spotify Web API Library Written in Swift for iOS and macOS

Written in Swift 4.2 Spartan is a lightweight, elegant, and easy to use Spotify Web API wrapper library for iOS and macOS written in Swift 3. Under th

Dalton Hinterscher 107 Nov 8, 2022
Instagram API client written in Swift

SwiftInstagram is a wrapper for the Instagram API written in Swift. It allows you to authenticate users and request data from Instagram effortlessly.

Ander Goig 579 Dec 31, 2022