WaniKit 2.0.3

WaniKit 2.0.3

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

Andrew Kharchyshyn维护。



WaniKit 2.0.3

WaniKit

alt text

WaniKit - WaniKani.com API 的 Swift 封装。它基于 NSOperationNSOperationQueue,如 此 WWDC2015 讲座中所述。

我主要为了我的 - iOS WaniKani 客户端而构建此软件。

安装

使用方法

  1. 创建管理器对象,并为其提供 WaniKani API 密钥(可在 WaniKani 个人资料的“设置”中找到)

    let manager = WaniApiManager()
    manager.setApiKey("0123abc0123abc0123abc") // Pass key here
  2. 获取学习队列数据,以下是一个 API 调用示例

    manager.fetchStudyQueue { (result) -> Void in
        switch result {
        case .Error(let error):
            print(error())
        case .Response(let response):
            let resp = response()
            if let userInfo = resp.userInfo {
                print("userInfo: \(userInfo)")
            }
            if let studyQueueInfo = resp.studyQInfo {
                print("studyQInfo: \(studyQInfo)")
            }
        }
    }
  3. 获取水平进度

    manager.fetchLevelProgression { (result) -> Void in
        switch result {
        case .Error(let error):
            print(error())
        case .Response(let response):
            let resp = response()
            if let userInfo = resp.userInfo {
                print("userInfo: \(userInfo)")
            }
            if let levelProgressInfo = resp.levelProgression {
                print("levelProgression: \(levelProgressInfo)")
            }
        }
    }
  4. 如果您需要用户信息

    manager.fetchUserInfo { (result) -> Void in
      switch result {
      case .Error(let error):
        print(error())
      case .Response(let response):
        let resp = response()
        if let userInfo = resp {
          print(userInfo)
        }
      }
    }
  5. 特定级别的部首

    manager.fetchRadicalsList(7) { (result) -> Void in
      switch result {
      case .Error(let error):
        print(error())
      case .Response(let response):
        let resp = response()
        if let userInfo = resp.userInfo {
          print(userInfo)
        }
        if let radicals = resp.radicals {
          print(radicals)
        }
      }
    }
  6. 特定级别的汉字

    manager.fetchKanjiList(8) { (result) -> Void in
      switch result {
      case .Error(let error):
        print(error())
      case .Response(let response):
        let resp = response()
        if let userInfo = resp.userInfo {
          print(userInfo)
        }
        if let kanji = resp.kanji {
          print(kanji)
        }
      }
    }
  7. 特定级别的词汇 swift manager.fetchVocabList(9) { (result) -> Void in switch result { case .Error(let error): print(error()) case .Response(let response): let resp = response() if let userInfo = resp.userInfo { print(userInfo) } if let vocab = resp.vocab { print(vocab) } } }
  8. 关键项,带有百分比参数 swift manager.fetchCriticalItems(85) { (result) -> Void in switch result { case .Error(let error): print(error()) case .Response(let response): let resp = response() if let userInfo = resp.userInfo { print(userInfo) } if let criticalItems = resp.criticalItems { print(criticalItems) } } }

重要提示

管理器使用串行队列进行操作,因此请求将按您调用的顺序执行,并且直到前一个请求完成,没有人会开始。

队列中只能存在同一类型的单个操作,因此如果您对例如三次调用 fetchStudyQueue,它将只执行一次。

如果您需要同时发送多个相同请求,可以使用两个管理器或在这家公司上提交问题和请求。

作者

Andriy Kharchyshyn.,

@haawa799
在LinkedIn上打个招呼 https://ua.linkedin.com/in/andrew-kharchyshyn-39639164

许可证

WaniKit是在MIT许可证下提供的。有关更多信息,请参阅LICENSE文件。