SwiftyNarou 1.1.14

SwiftyNarou 1.1.14

Roger Luo 维护。



 
依赖
SwiftSoup>= 0
SwiftyJSON>= 0
GzipSwift>= 0
 

  • Roger Luo

SwiftyNarou

SwiftyNarou 是围绕 Narou API 的 Swift 封装。除了支持所有 API 功能调用外,SwiftyNarou 还允许用户通过提供 ncode 来检索小说内容。灵感来源于 nshiba 的 narou4j (https://github.com/nshiba/narou4j)。

安装

Cocoapods

pod 'SwiftyNarou' 添加到 Podfile 中并运行 pod install。要使用,请 import SwiftyNarou

使用

获取查询 Narou API 的解析结果

自1.1.0版本起,您必须指定使用.JSON作为文件格式,因为只有JSON解析器已经被实现。

let request = NarouRequest(
  bigGenre: .fantasy,
  ... (more request params)
  responseFormat: NarouResponseFormat(
    fileFormat: .JSON, // this is mandatory for now.
    fields: [.ncode, .title, .author, ...] // select columns to return (highly recommended)
    limit: 10, // recommended
    ... (more output formatting)
  )
)
Narou.fetchNarouApi(request) { data, error in
  if err != nil, let count:Int, res: [NarouResponse] = data {
    // do something
  }
}

从Narou API查询获取原始结果

fetchNarouApiRaw不会派发到主队列,因此任何完成逻辑都必须包含一个派发操作。

let request = NarouRequest(
  bigGenre: .fantasy,
  ... (more request params)
  responseFormat: NarouResponseFormat(
    fileFormat: .JSON, // this is mandatory for now.
    fields: [.ncode, .title, .author, ...] // select columns to return (highly recommended)
    limit: 10, // recommended
    ... (more output formatting)
  )
)
Narou.fetchNarouApiRaw(request) { data, error in
  if err != nil, let res: [NarouResponse] = data {
    DispatchQueue.main.async {
      // do something
    }
  }
}

获取目录页面

let ncode = "n12345"
Narou.fetchNovelIndex(ncode) { data, error in
  if err != nil, let novelIndex = data {
    // do something
  }
}

获取章节内容

let ncode = "n12345"
Narou.fetchSectionContent(ncode) { data, error in
  if err != nil, let novelIndex = data {
    // do something
  }
}