Code Monkey home page Code Monkey logo

gobus's Introduction

GoBus: Elegant way to get data from Inthegra API in Swift.

Build status Platform iOS Swift 2 compatible CocoaPods compatible License: MIT

Introduction

GoBus! is a library to help developers to interact with Inthegra API in Swift. We provide an easy way to get data and some new features not implemented on api.

Requirements

  • iOS 8.0+
  • Xcode 7.3+

Getting involved

  • If you want to contribute please feel free to submit pull requests.
  • If you have a feature request please open an issue.
  • If you found a bug check older issues before submitting an issue.

Example

Follow these 3 steps to run Example project: Clone GoBus repository, open Example workspace and run the Example project.

Usage

Set Auth Token

It is quite simple to set auth token, just like this:

import UIKit
import GoBus

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        
        GoBus().setupWithApiKey(apiKey: String, email: String, password: String, url: String)
        return true
    }
}

In this example we just set your application key, email and password. With this, you will automatically logged and the access token retrieved and updated automatically.

Now you are read to use GoBus funcs.

How to get bus values

We can get bus values by invoking the following three GoBus function:

Get All Bus

GoBus().getBus(completion: (([Bus]?, [Line]?, NSError?) -> Void))

GoBus().getBus() { (buss, lines, error) in
    if error != nil {
        print(error?.code)
        print(error?.domain)
    }else {
        if lines != nil {
            for line in lines! {
                print(line.description)
            }
        }

        if buss != nil {
            for bus in buss! {
                print(bus.description)
            }
        }
    }
}

Will return an array with Bus objects, an array with Line objects and an NSError

All Bus of specific line

GoBus().getBus(inLine: String?, completion: (([Bus]?, [Line]?, NSError?) -> Void))

GoBus().getBus(inLine: "0408") { (buss, line, error) in
    if error != nil {
        print(error?.code)
        print(error?.domain)
    }else {
        if line != nil {
            //We received only one Line, which correspond to the line researched
            print(line![0].description)
        }

        // - buss - correspond to all Bus in the line researched
        if buss != nil {
            for bus in buss! {
                print(bus.description)
            }
        }
    }
}

Pass the number of the line you want to return and will receive an array with Bus objects of this line, an array with the Line and an NSError

Use GoBus().getBus PROTOCOL

//** repeatAfter works in Seconds
GoBus().getBus(inLine: String?, repeatAfter: Double?, completion: (([Bus]?, [Line]?, NSError?) -> Void))

//Usage:

//  1: GoBus().getBus(inLine: "0408", repeatAfter: 30, completion: (([Bus]?, [Line]?, NSError?) -> Void)) with Search
//  2: GoBus().getBus(repeatAfter: 30, completion: (([Bus]?, [Line]?, NSError?) -> Void)) without Search

//  3: In this case, you can use either the first way as the second

// - First, add GoBusDelegate in the class

let go = GoBus()
//Returns both the bus as the line now. From now on, every five seconds the function implemented by the protocol will return updated values.
let cancel = go.getBus(inLine: "0408", repeatAfter: 5) { (buss, line, error) in }

//Using this way (3), now you can cancel repeat After and the call protocol
go.cancel(cancel)

See more like how get Line and Stops in Example Project

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

Specify GoBus into your project's Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'GoBus'

Then run the following command:

$ pod install

To-Do List


  • Add ability to stop being sought by lines
  • Improve Documentation

Author

Orlando Amorim, [email protected]

License

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

gobus's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.