GoBus 0.1.3

GoBus 0.1.3

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布日期最后发布日期2016年5月
SPM支持SPM

Orlando Amorim维护。



GoBus 0.1.3

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

介绍

GoBus! 是一个库,帮助开发者使用 Swift 与 Inthegra API 进行交互。我们提供了一种简单的方式来获取数据和一些在 API 上未实现的新功能。

要求

  • iOS 8.0+
  • Xcode 7.3+

参与其中

  • 如果您想要 贡献,请随时 提交拉取请求
  • 如果您有 功能请求,请 打开一个问题
  • 如果您发现 错误,在提交问题之前请检查旧问题。

示例

按照以下三个步骤运行示例项目:克隆 GoBus 仓库,打开示例工作区并运行 示例 项目。

用法

设置认证令牌

设置认证令牌很简单,就像这样

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
    }
}

在这个例子中,我们只是设置了您的应用程序密钥、电子邮件和密码。有了这些,您将自动登录,访问令牌会自动获取和更新。

现在您可以使用 GoBus 函数了。

如何获取总线值

我们可以通过调用以下三个 GoBus 函数来获取总线值

获取所有总线

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)
            }
        }
    }
}

将返回包含总线对象、包含线路对象的数组和 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)
            }
        }
    }
}

传递您希望返回的线路编号,并将收到包含此线路总线对象的数组、包含线路的数组和 NSError

使用 GoBus().getBus 协议

//** 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)

查看更多,如示例项目中的获取线路和车站

安装

待办事项


  • [ ] 增加停止被线条搜索的功能
  • [ ] 优化文档

作者

奥兰多·阿莫里姆,[email protected]

许可证

GoBus可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。