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.
- iOS 8.0+
- Xcode 7.3+
- 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.
Follow these 3 steps to run Example project: Clone GoBus repository, open Example workspace and run the Example project.
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.
We can get bus values by invoking the following three GoBus
function:
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
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
//** 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)
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
- Add ability to stop being sought by lines
- Improve Documentation
Orlando Amorim, [email protected]
GoBus is available under the MIT license. See the LICENSE file for more info.