diff --git a/Sources/LicensePlistCore/Entity/GitHubLicense.swift b/Sources/LicensePlistCore/Entity/GitHubLicense.swift index 3c41e1f1..0a49faed 100644 --- a/Sources/LicensePlistCore/Entity/GitHubLicense.swift +++ b/Sources/LicensePlistCore/Entity/GitHubLicense.swift @@ -56,7 +56,7 @@ extension GitHubLicense { } case .success(let response): let license = GitHubLicense(library: library, - body: response.downloadUrl.lp.download().resultSync().value!, + body: response.contentDecoded, githubResponse: response) return Result(value: license) } diff --git a/Sources/LicensePlistCore/GitHubClient/RepoRequests.swift b/Sources/LicensePlistCore/GitHubClient/RepoRequests.swift index 18a96421..7d301147 100644 --- a/Sources/LicensePlistCore/GitHubClient/RepoRequests.swift +++ b/Sources/LicensePlistCore/GitHubClient/RepoRequests.swift @@ -33,13 +33,22 @@ struct RepoRequests { } struct LicenseResponse { - let downloadUrl: URL + let content: String + let contentDecoded: String + let encoding: String let kind: LicenseKindResponse } extension LicenseResponse: Decodable { static func decode(_ e: Extractor) throws -> LicenseResponse { - return try LicenseResponse(downloadUrl: URL(string: e.value("download_url"))!, kind: e.value("license")) + let content: String = try e.value("content") + let encofing: String = try e.value("encoding") + assert(encofing == "base64") + let contentDecoded = String(data: Data(base64Encoded: content, options: [.ignoreUnknownCharacters])!, encoding: .utf8)! + return try LicenseResponse(content: content, + contentDecoded: contentDecoded, + encoding: encofing, + kind: e.value("license")) } } diff --git a/Tests/LicensePlistTests/Entity/GitHubLicense.collectorTests.swift b/Tests/LicensePlistTests/Entity/GitHubLicense.collectorTests.swift index 812d89dc..e82c9893 100644 --- a/Tests/LicensePlistTests/Entity/GitHubLicense.collectorTests.swift +++ b/Tests/LicensePlistTests/Entity/GitHubLicense.collectorTests.swift @@ -15,8 +15,6 @@ class GitHubLicenseTests: XCTestCase { let license = GitHubLicense.download(carthage).resultSync().value! XCTAssertEqual(license.library, carthage) XCTAssertTrue(license.body.hasPrefix("MIT License")) - XCTAssertEqual(license.githubResponse.downloadUrl, - URL(string: "https://raw.githubusercontent.com/mono0926/NativePopup/master/LICENSE")) XCTAssertEqual(license.githubResponse.kind.spdxId, "MIT") } @@ -27,8 +25,6 @@ class GitHubLicenseTests: XCTestCase { forked.owner = "adjust" XCTAssertEqual(license.library, forked) XCTAssertTrue(license.body.hasPrefix("Copyright (c)")) - XCTAssertEqual(license.githubResponse.downloadUrl, - URL(string: "https://raw.githubusercontent.com/adjust/ios_sdk/master/MIT-LICENSE")) XCTAssertEqual(license.githubResponse.kind.spdxId, "MIT") } func testCollect_invalid() { diff --git a/Tests/LicensePlistTests/Entity/PlistInfoTests.swift b/Tests/LicensePlistTests/Entity/PlistInfoTests.swift index 4d0d70be..0f60e8e0 100644 --- a/Tests/LicensePlistTests/Entity/PlistInfoTests.swift +++ b/Tests/LicensePlistTests/Entity/PlistInfoTests.swift @@ -100,7 +100,9 @@ class PlistInfoTests: XCTestCase { let github = GitHub(name: "LicensePlist", nameSpecified: nil, owner: "mono0926", version: nil) let githubLicense = GitHubLicense(library: github, body: "body", - githubResponse: LicenseResponse(downloadUrl: URL(fileURLWithPath: ""), + githubResponse: LicenseResponse(content: "", + contentDecoded: "", + encoding: "", kind: LicenseKindResponse(name: "name", spdxId: nil))) target.cocoaPodsLicenses = [] @@ -120,7 +122,9 @@ class PlistInfoTests: XCTestCase { let github = GitHub(name: "LicensePlist", nameSpecified: nil, owner: "mono0926", version: nil) let githubLicense = GitHubLicense(library: github, body: "body", - githubResponse: LicenseResponse(downloadUrl: URL(fileURLWithPath: ""), + githubResponse: LicenseResponse(content: "", + contentDecoded: "", + encoding: "", kind: LicenseKindResponse(name: "name", spdxId: nil))) target.licenses = [githubLicense] @@ -132,7 +136,9 @@ class PlistInfoTests: XCTestCase { let github = GitHub(name: "LicensePlist", nameSpecified: nil, owner: "mono0926", version: nil) let githubLicense = GitHubLicense(library: github, body: "body", - githubResponse: LicenseResponse(downloadUrl: URL(fileURLWithPath: ""), + githubResponse: LicenseResponse(content: "", + contentDecoded: "", + encoding: "", kind: LicenseKindResponse(name: "name", spdxId: nil))) target.githubLibraries = [github] @@ -145,7 +151,9 @@ class PlistInfoTests: XCTestCase { let github = GitHub(name: "LicensePlist", nameSpecified: nil, owner: "mono0926", version: nil) let githubLicense = GitHubLicense(library: github, body: "body", - githubResponse: LicenseResponse(downloadUrl: URL(fileURLWithPath: ""), + githubResponse: LicenseResponse(content: "", + contentDecoded: "", + encoding: "", kind: LicenseKindResponse(name: "name", spdxId: nil))) target.githubLibraries = [github] diff --git a/Tests/LicensePlistTests/GitHubClient/RepoRequestsTests.swift b/Tests/LicensePlistTests/GitHubClient/RepoRequestsTests.swift index 7a778fe0..3e7fa7b0 100644 --- a/Tests/LicensePlistTests/GitHubClient/RepoRequestsTests.swift +++ b/Tests/LicensePlistTests/GitHubClient/RepoRequestsTests.swift @@ -13,9 +13,7 @@ class RepoRequestsTests: XCTestCase { let result = Session.shared.lp.sendSync(request) switch result { case .success(let response): - XCTAssertEqual( - response.downloadUrl, - URL(string: "https://raw.githubusercontent.com/mono0926/NativePopup/master/LICENSE")!) + XCTAssertTrue(response.contentDecoded.hasPrefix("MIT License")) case .failure(let error): XCTFail(String(describing: error)) } @@ -41,9 +39,7 @@ class RepoRequestsTests: XCTestCase { queue.addOperations([o1, o2], waitUntilFinished: true) let result = [o1.result!.value!, o2.result!.value!] XCTAssertEqual(result.count, 2) - XCTAssertEqual(result[0].downloadUrl, - URL(string: "https://raw.githubusercontent.com/mono0926/NativePopup/master/LICENSE")!) - XCTAssertEqual(result[1].downloadUrl, - URL(string: "https://raw.githubusercontent.com/ReactiveX/RxSwift/master/LICENSE.md")!) + XCTAssertTrue(result[0].contentDecoded.hasPrefix("MIT License")) + XCTAssertTrue(result[1].contentDecoded.hasPrefix("**The MIT License**")) } }