From e12fce9ddcadd5a17e9d5042bcfa37c3ae01f0c9 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Tue, 18 Apr 2023 20:03:12 +0000 Subject: [PATCH] [Feature] All endpoints (#2) This PR contains the work done in implementing the endpoints needed for the remote calls: `GetAmiiboEndpoint`, `GetTypeEndpoint`, `GetGameSeriesEndpoint`, `GetSeriesEndpoint`, `GetSeriesEndpoint` and `GetLastUpdatedEndpoint` endpoints definitions. Furthermore, I added the the **SwiftLibs** package as a dependency and also, I defined constants for `String+Scheme`, `String+Host` and the `String+Path` extensions. Co-authored-by: Javier Cicchelli Reviewed-on: https://repo.rock-n-code.com/rock-n-code/amiibo-service/pulls/2 --- Package.swift | 14 ++++++++++++-- Sources/AmiiboService/AmiiboService.swift | 6 ------ Sources/Endpoints/GetAmiiboEndpoint.swift | 16 ++++++++++++++++ Sources/Endpoints/GetCharacterEndpoint.swift | 16 ++++++++++++++++ Sources/Endpoints/GetGameSeriesEndpoint.swift | 16 ++++++++++++++++ Sources/Endpoints/GetLastUpdatedEndpoint.swift | 16 ++++++++++++++++ Sources/Endpoints/GetSeriesEndpoint.swift | 16 ++++++++++++++++ Sources/Endpoints/GetTypeEndpoint.swift | 16 ++++++++++++++++ Sources/Extensions/String+Host.swift | 5 +++++ Sources/Extensions/String+Path.swift | 10 ++++++++++ Sources/Extensions/String+Scheme.swift | 5 +++++ .../AmiiboServiceTests/AmiiboServiceTests.swift | 11 ----------- 12 files changed, 128 insertions(+), 19 deletions(-) delete mode 100644 Sources/AmiiboService/AmiiboService.swift create mode 100644 Sources/Endpoints/GetAmiiboEndpoint.swift create mode 100644 Sources/Endpoints/GetCharacterEndpoint.swift create mode 100644 Sources/Endpoints/GetGameSeriesEndpoint.swift create mode 100644 Sources/Endpoints/GetLastUpdatedEndpoint.swift create mode 100644 Sources/Endpoints/GetSeriesEndpoint.swift create mode 100644 Sources/Endpoints/GetTypeEndpoint.swift create mode 100644 Sources/Extensions/String+Host.swift create mode 100644 Sources/Extensions/String+Path.swift create mode 100644 Sources/Extensions/String+Scheme.swift delete mode 100644 Tests/AmiiboServiceTests/AmiiboServiceTests.swift diff --git a/Package.swift b/Package.swift index 94de2e6..7ed4db2 100644 --- a/Package.swift +++ b/Package.swift @@ -4,6 +4,12 @@ import PackageDescription let package = Package( name: "AmiiboService", + platforms: [ + .iOS(.v13), + .macOS(.v10_15), + .tvOS(.v13), + .watchOS(.v8) + ], products: [ .library( name: "AmiiboService", @@ -12,11 +18,15 @@ let package = Package( ] ), ], - dependencies: [], + dependencies: [ + .package(url: "https://github.com/rock-n-code/swift-libs.git", from: "0.1.0") + ], targets: [ .target( name: "AmiiboService", - dependencies: [], + dependencies: [ + .product(name: "SwiftLibs", package: "swift-libs") + ], path: "Sources" ), .testTarget( diff --git a/Sources/AmiiboService/AmiiboService.swift b/Sources/AmiiboService/AmiiboService.swift deleted file mode 100644 index 48d14a1..0000000 --- a/Sources/AmiiboService/AmiiboService.swift +++ /dev/null @@ -1,6 +0,0 @@ -public struct AmiiboService { - public private(set) var text = "Hello, World!" - - public init() { - } -} diff --git a/Sources/Endpoints/GetAmiiboEndpoint.swift b/Sources/Endpoints/GetAmiiboEndpoint.swift new file mode 100644 index 0000000..fb3046f --- /dev/null +++ b/Sources/Endpoints/GetAmiiboEndpoint.swift @@ -0,0 +1,16 @@ +import Communications +import Foundation + +struct GetAmiiboEndpoint: Endpoint { + + // MARK: Properties + + let scheme: String = .Scheme.https + let host: String = .Host.amiiboApi + let port: Int? + let path: String = .Path.type + let method: HTTPRequestMethod = .get + let headers: [String : String] = [:] + let body: Data? + +} diff --git a/Sources/Endpoints/GetCharacterEndpoint.swift b/Sources/Endpoints/GetCharacterEndpoint.swift new file mode 100644 index 0000000..8b08a7b --- /dev/null +++ b/Sources/Endpoints/GetCharacterEndpoint.swift @@ -0,0 +1,16 @@ +import Communications +import Foundation + +struct GetCharacterEndpoint: Endpoint { + + // MARK: Properties + + let scheme: String = .Scheme.https + let host: String = .Host.amiiboApi + let port: Int? + let path: String = .Path.character + let method: HTTPRequestMethod = .get + let headers: [String : String] = [:] + let body: Data? + +} diff --git a/Sources/Endpoints/GetGameSeriesEndpoint.swift b/Sources/Endpoints/GetGameSeriesEndpoint.swift new file mode 100644 index 0000000..033ba65 --- /dev/null +++ b/Sources/Endpoints/GetGameSeriesEndpoint.swift @@ -0,0 +1,16 @@ +import Communications +import Foundation + +struct GetGameSeriesEndpoint: Endpoint { + + // MARK: Properties + + let scheme: String = .Scheme.https + let host: String = .Host.amiiboApi + let port: Int? + let path: String = .Path.gameSeries + let method: HTTPRequestMethod = .get + let headers: [String : String] = [:] + let body: Data? + +} diff --git a/Sources/Endpoints/GetLastUpdatedEndpoint.swift b/Sources/Endpoints/GetLastUpdatedEndpoint.swift new file mode 100644 index 0000000..1d7d0a2 --- /dev/null +++ b/Sources/Endpoints/GetLastUpdatedEndpoint.swift @@ -0,0 +1,16 @@ +import Communications +import Foundation + +struct GetLastUpdatedEndpoint: Endpoint { + + // MARK: Properties + + let scheme: String = .Scheme.https + let host: String = .Host.amiiboApi + let port: Int? + let path: String = .Path.lastUpdated + let method: HTTPRequestMethod = .get + let headers: [String : String] = [:] + let body: Data? + +} diff --git a/Sources/Endpoints/GetSeriesEndpoint.swift b/Sources/Endpoints/GetSeriesEndpoint.swift new file mode 100644 index 0000000..f791566 --- /dev/null +++ b/Sources/Endpoints/GetSeriesEndpoint.swift @@ -0,0 +1,16 @@ +import Communications +import Foundation + +struct GetSeriesEndpoint: Endpoint { + + // MARK: Properties + + let scheme: String = .Scheme.https + let host: String = .Host.amiiboApi + let port: Int? + let path: String = .Path.series + let method: HTTPRequestMethod = .get + let headers: [String : String] = [:] + let body: Data? + +} diff --git a/Sources/Endpoints/GetTypeEndpoint.swift b/Sources/Endpoints/GetTypeEndpoint.swift new file mode 100644 index 0000000..677f0d2 --- /dev/null +++ b/Sources/Endpoints/GetTypeEndpoint.swift @@ -0,0 +1,16 @@ +import Communications +import Foundation + +struct GetTypeEndpoint: Endpoint { + + // MARK: Properties + + let scheme: String = .Scheme.https + let host: String = .Host.amiiboApi + let port: Int? + let path: String = .Path.type + let method: HTTPRequestMethod = .get + let headers: [String : String] = [:] + let body: Data? + +} diff --git a/Sources/Extensions/String+Host.swift b/Sources/Extensions/String+Host.swift new file mode 100644 index 0000000..1e2c023 --- /dev/null +++ b/Sources/Extensions/String+Host.swift @@ -0,0 +1,5 @@ +extension String { + enum Host { + static let amiiboApi = "www.amiiboapi.com" + } +} diff --git a/Sources/Extensions/String+Path.swift b/Sources/Extensions/String+Path.swift new file mode 100644 index 0000000..fbd2a7f --- /dev/null +++ b/Sources/Extensions/String+Path.swift @@ -0,0 +1,10 @@ +extension String { + enum Path { + static let amiibo = "/api/amiibo/" + static let type = "/api/type" + static let gameSeries = "/api/gameseries" + static let series = "/api/amiiboseries" + static let character = "/api/character" + static let lastUpdated = "/api/lastupdated" + } +} diff --git a/Sources/Extensions/String+Scheme.swift b/Sources/Extensions/String+Scheme.swift new file mode 100644 index 0000000..e5291e3 --- /dev/null +++ b/Sources/Extensions/String+Scheme.swift @@ -0,0 +1,5 @@ +extension String { + enum Scheme { + static let https = "https" + } +} diff --git a/Tests/AmiiboServiceTests/AmiiboServiceTests.swift b/Tests/AmiiboServiceTests/AmiiboServiceTests.swift deleted file mode 100644 index 4aecad6..0000000 --- a/Tests/AmiiboServiceTests/AmiiboServiceTests.swift +++ /dev/null @@ -1,11 +0,0 @@ -import XCTest -@testable import AmiiboService - -final class AmiiboServiceTests: XCTestCase { - func testExample() throws { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct - // results. - XCTAssertEqual(AmiiboService().text, "Hello, World!") - } -}