Skip to content

Commit

Permalink
add support for new API
Browse files Browse the repository at this point in the history
  • Loading branch information
shvets committed Oct 20, 2018
1 parent 224690e commit b1f8d6c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sources/WebAPI/KinoGoAPI-models.swift
Expand Up @@ -11,6 +11,21 @@ extension KinoGoAPI {
}
}

public var name: String {
get {
let pattern = "(<br/><i>.*</i>)"

do {
let regex = try NSRegularExpression(pattern: pattern)

return regex.stringByReplacingMatches(in: self.comment, options: [], range: NSMakeRange(0, self.comment.count), withTemplate: "")
}
catch {
return self.comment
}
}
}

enum CodingKeys: String, CodingKey {
case comment
case file
Expand Down
6 changes: 6 additions & 0 deletions Sources/WebAPI/KinoGoAPI.swift
Expand Up @@ -25,6 +25,12 @@ open class KinoGoAPI: HttpService {
}
}

public func getCookie(url: String) -> String? {
let response: DataResponse<Data>? = httpRequest(url)

return response?.response?.allHeaderFields["Set-Cookie"] as? String
}

func getPagePath(_ path: String, page: Int=1) -> String {
if page == 1 {
return path
Expand Down
12 changes: 12 additions & 0 deletions Tests/WebAPITests/KinoGoAPITests.swift
Expand Up @@ -11,6 +11,16 @@ class KinoGoAPITests: XCTestCase {
XCTAssertEqual(result, true)
}

func testGetCookie() throws {
if let result = subject.getCookie(url: "https://kinogo.by/11361-venom_2018_08-10.html") {
print(result)

XCTAssertNotNil(result)
} else {
XCTFail("Empty result")
}
}

func testGetAllCategories() throws {
let list = try subject.getAllCategories()

Expand Down Expand Up @@ -156,6 +166,8 @@ class KinoGoAPITests: XCTestCase {
let list = try subject.getSeasons(KinoGoAPI.SiteUrl + path)

print(list)
// print(list.first!.playlist.first!.comment)
// print(list.first!.playlist.first!.name)

XCTAssertNotNil(list)
XCTAssert(list.count > 0)
Expand Down

0 comments on commit b1f8d6c

Please sign in to comment.