Latest 0.4.0
Homepage https://github.com/shannn214/TaxiGoDev
License MIT
Platforms ios 11.0
Dependencies HandyJSON
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

TaxiGoDev is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'TaxiGoDev'

Usage

You can access TaxiGoDev API like this:

var taxiGo = TaxiGo.shared

Setup

  • Set up Your URL Types
    Your Project -> TARGETS -> Info -> URL Types -> URL Schemes, Identifier ->
    image

    taxiGo.auth.appID = <YOUR_APPID>
    taxiGo.auth.appSecret = <YOUR_APP_SECRET>
    taxiGo.auth.redirectURL = <YOUR_REDIRECTURL>
    taxiGo.api.url = <SAND_BOX_URL/PRODUCTION_URL>
    taxiGo.api.apiKey = <YOUR_API_KEY>

Authorization

  • User Authorizes Your Application
    TaxiGo provides an authorization page where user can sign in with their LINE account and grant permission to your application. In the example, we use UIApplication to open the url.

    let url = URL(string: "https://user.taxigo.com.tw/oauth/authorize?app_id=<YOUR_APPID>&redirect_uri=<YOUR_REDIRECTURL>")
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
  • Redirect
    If you successfully sign in with your LINE account, TaxiGo will return a redirect uri along with an authorization code. You can access the authorization code as following:

In AppDelegate.swift, add the following to your application(_:open:options:) method.

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    taxiGo.auth.authCode = taxiGo.auth.getAuthCode(url: url)
}
  • Get User Access Token
    After you access the authorization code, you will be able to retrieve your access token and start using TaxiGo’s API.

    
    taxiGo.auth.getUserToken(success: { (auth) in
    
    // do something with the auth
    print(auth.access_token)
    ...

}) { (err) in
// do somwthing with the err
}


#### Request a ride
```swift
taxiGo.api.requestARide(withAccessToken: String, 
                        startLatitude: Double, 
                        startLongitude: Double, 
                        startAddress: String, 
                        endLatitude: Double?, 
                        endLongitude: Double?, 
                        endAddress: String?, 
                        success: { (ride, response) in

                            // do something with the ride and response
                            // response will provide you the status code

}) { (err) in
    // do something with the err
}

We also provide taxiGo.api.startObservingStatus to observe the status of the ride you request. Remember to start the observing before you request the ride.
Sweet reminder: It will keep observing until you set the value as false.

taxiGo.api.startObservingStatus = true

If you start to observe the ride’s status, you’ll need to implement delegate: TaxiGoAPIDelegate to access the callback. It will update the status every 5 seconds.

taxiGo.api.taxiGoDelegate = self

extension ViewController: TaxiGoAPIDelegate {

    func rideDidUpdate(status: String, ride: TaxiGo.API.Ride) {

        // do somthing with the callback
        print(status) // ex. WAITING_SPECIFY
        print(ride.driver?.vehicle)
        ...

    }

}

Cancel a ride

If you successfully request a ride, TaxiGoDev will save the ride’s id in taxiGo.api.id.

guard let token = taxiGo.auth.accessToken,
      let id = taxiGo.api.id else { return }

taxiGo.api.cancelARide(withAccessToken: token, id: id, success: { (ride, response) in

    taxiGo.api.startObservingStatus = false
    // do something with the ride and response
    // response will provide the status code

}) { (err, response) in
    // do something with the err
}

Nearby drivers

Sweet reminder: Rate Limit – 5 calls per minute.

taxiGo.api.getNearbyDriver(withAccessToken: token,
                        lat: place.coordinate.latitude,
                        lng: place.coordinate.longitude,
                        success: { (nearbyDrivers, response) in

                            nearbyDrivers.forEach({ (driver) in
                                print(driver.lat)
                                ...
                            })

}, failure: { (err, response) in
    // do something with the err
})

Rider

taxiGo.api.getRiderInfo(withAccessToken: token, success: { (rider, response) in

            print(rider.name)

            rider.favorite?.forEach({ (info) in
                print(info.address)
            })

}) { (err, response) in
    // do something with the err
}

Author

shannn214, [email protected]

License

TaxiGoDev is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "TaxiGoDev",
    "version": "0.4.0",
    "summary": "Open API of TaxiGo.",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/shannn214/TaxiGoDev",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "shannn214": "[email protected]"
    },
    "source": {
        "git": "https://github.com/shannn214/TaxiGoDev.git",
        "tag": "0.4.0"
    },
    "platforms": {
        "ios": "11.0"
    },
    "source_files": "TaxiGoDev/Classes/",
    "dependencies": {
        "HandyJSON": [
            "~> 4.2.0-beta1"
        ]
    }
}

Pin It on Pinterest

Share This