Skip to content

Commit

Permalink
Merge branch release/1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rakuyoMo committed Jan 14, 2023
2 parents 6e29cbc + e82cc11 commit c6d48f9
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//: [Previous](@previous)

import PlaygroundSupport

import Foundation

import APIWrapper
Expand Down Expand Up @@ -36,7 +38,6 @@ extension API {
enum AdvancedAPI {
/// Finally, the new initialization method declared above is called on
/// the property wrapper to complete the interface definition.

@GET("/api", verification: .normal)
static var testAPI: APIParameterBuilder<()>? = nil
}
Expand Down
2 changes: 2 additions & 0 deletions Demo.playground/Pages/Basic.xcplaygroundpage/Contents.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import PlaygroundSupport

import Foundation

import APIWrapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//: [Previous](@previous)

import Foundation
import PlaygroundSupport

import Combine
import Foundation
import ObjectiveC

import APIWrapper
Expand Down
2 changes: 1 addition & 1 deletion Demo.playground/Sources/API+Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private extension API {
}

let (data, response) = try await URLSession.shared.data(for: request)
print("\(String(describing: response.url?.absoluteString)) End of request")
print("\(response.url?.absoluteString ?? "nil") End of request")

return data
}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ static var tupleParamAPI: APIParameterBuilder<(id: Int, name: String?)>? = {
@POST("/post")
static var postWithModel: APIParameterBuilder<Arg>? = {
// You can have your model follow the `APIParameterConvertible` protocol,
// or use `AnyAPIHashableParameter` to wrap your model in an outer layer.
AnyAPIHashableParameter($0)
// or use `AnyAPIParameter` to wrap your model in an outer layer.
AnyAPIParameter($0)
}
```

Expand Down
4 changes: 2 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ static var tupleParamAPI: APIParameterBuilder<(id: Int, name: String?)>? = {

@POST("/post")
static var postWithModel: APIParameterBuilder<Arg>? = {
// 您可以让您的模型遵循 `APIParameterConvertible` 协议,或者使用 `AnyAPIHashableParameter` 在外面包裹一层。
AnyAPIHashableParameter($0)
// 您可以让您的模型遵循 `APIParameterConvertible` 协议,或者使用 `AnyAPIParameter` 在外面包裹一层。
AnyAPIParameter($0)
}
```

Expand Down
2 changes: 1 addition & 1 deletion RaAPIWrapper.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pod::Spec.new do |s|

s.name = 'RaAPIWrapper'

s.version = '1.0.1'
s.version = '1.0.2'

s.summary = 'Makes it easier to define a network request.'

Expand Down
9 changes: 5 additions & 4 deletions Sources/Core/RequestInfo/APIParameterConvertible.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// APIParameters.swift
// APIParameterConvertible.swift
// RaAPIWrapper
//
// Created by Rakuyo on 2022/8/25.
Expand All @@ -8,9 +8,6 @@

import Foundation

/// Used to constrain what types can be used as api parameters.
public typealias APIParametrizable = AnyAPIParameter.Input

/// Means that the type can be converted to an interface parameter for requesting an api.
public protocol APIParameterConvertible {
/// Converts the target to an Encodable-compliant type.
Expand Down Expand Up @@ -41,6 +38,10 @@ extension Double: APIParameterConvertible { }

extension Bool: APIParameterConvertible { }

// MARK: - Data

extension Data: APIParameterConvertible { }

// MARK: - Array

extension Array: APIParameterConvertible {
Expand Down
12 changes: 12 additions & 0 deletions Sources/Core/RequestInfo/APIParametrizable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// APIParametrizable.swift
// RaAPIWrapper
//
// Created by Rakuyo on 2023/01/13.
// Copyright © 2022 Rakuyo. All rights reserved.
//

import Foundation

/// Used to constrain what types can be used as api parameters.
public typealias APIParametrizable = AnyAPIHashableParameter.Input
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

import Foundation

/// Represents an arbitrary api parameter.
public typealias AnyAPIParameter = AnyAPIHashableParameter

/// Make `Encodable` follow `Hashable` protocol.
public struct AnyAPIHashableParameter: AnyAPIHashable {
public typealias Value = Encodable
Expand Down
12 changes: 12 additions & 0 deletions Sources/Core/RequestInfo/AnyAPIParameter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// AnyAPIParameter.swift
// RaAPIWrapper
//
// Created by Rakuyo on 2023/01/13.
// Copyright © 2022 Rakuyo. All rights reserved.
//

import Foundation

/// Represents an arbitrary api parameter.
public typealias AnyAPIParameter = AnyAPIHashableParameter
15 changes: 13 additions & 2 deletions Tests/AvailabilityTests.swift → Tests/AvailabilityTest.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// AvailabilityTests.swift
// AvailabilityTest.swift
// RaAPIWrapper
//
// Created by Rakuyo on 2022/8/26.
Expand All @@ -14,6 +14,7 @@ final class AvailabilityTests: XCTestCase {
let param: (id: Int, name: String?) = (1, nil)
let info = TestAPI.$tupleParamAPI.createRequestInfo(param)

// Verify that `nil` is filtered out in `info.parameters`
XCTAssertEqual(info.parameters, packToParameters(["id": 1]))
XCTAssertNotEqual(info.parameters, packToParameters(["id": 1, "name": Optional.none]))

Expand All @@ -22,7 +23,7 @@ final class AvailabilityTests: XCTestCase {
XCTAssertNil(info.specialBaseURL)
}

private func packToParameters(_ value: [String: Optional<Int>]) -> AnyAPIParameter {
private func packToParameters(_ value: [String: Int?]) -> AnyAPIParameter {
return .init(value.mapValues { AnyAPIParameter($0) })
}
}
Expand All @@ -34,4 +35,14 @@ fileprivate struct TestAPI {
static var tupleParamAPI: APIParameterBuilder<(id: Int, name: String?)>? = {
["id": $0.id, "name": $0.name] as [String: Any?]
}

@POST(Self.path)
static var test1API: APIParameterBuilder<(id: Int, name: String)>? = {
["id": $0.id, "name": $0.name]
}

@POST(Self.path)
static var test2API: APIParameterBuilder<(id: String, name: String)>? = {
["id": $0.id, "name": $0.name]
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ExtensibilityTests.swift
// ExtensibilityTest.swift
// RaAPIWrapper
//
// Created by Rakuyo on 2022/12/15.
Expand Down

0 comments on commit c6d48f9

Please sign in to comment.