Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
philprime committed Jan 31, 2025
1 parent 88b778c commit 5b32f40
Show file tree
Hide file tree
Showing 252 changed files with 110,241 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ let package = Package(
"PostieUtils",
"XMLCoder",
]),
.testTarget(name: "PostieTests", dependencies: [
"Postie",
"PostieMock"
]),
// dev .testTarget(name: "PostieTests", dependencies: [
// dev "Postie",
// dev "PostieMock"
// dev ]),

.target(name: "PostieMock", dependencies: ["Postie"]),

.target(name: "URLEncodedFormCoding", dependencies: ["PostieUtils"]),

.target(name: "PostieUtils"),
.testTarget(name: "PostieUtilsTests", dependencies: ["PostieUtils"])
// dev .testTarget(name: "PostieUtilsTests", dependencies: ["PostieUtils"])
]
)
4 changes: 4 additions & 0 deletions Sources/Postie/Headers/RequestHeaderValue.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/// A type that can be used as a value for an HTTP header.
///
/// The `RequestHeaderValue` protocol defines a type that can be used as a value for an HTTP header.
/// It requires conforming types to provide a `serializedHeaderValue` property that returns a string representation of the header value.
public protocol RequestHeaderValue {
/// The serialized value of the header.
///
Expand Down
4 changes: 4 additions & 0 deletions Sources/Postie/Path/RequestPathParameterValue.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/// A type that can be used as a value for a request path parameter.
///
/// The `RequestPathParameterValue` protocol defines a type that can be used as a value for a request path parameter.
/// It requires conforming types to provide a `serialized` property that returns a string representation of the path parameter value.
public protocol RequestPathParameterValue {
/// The serialized value of the path parameter.
///
Expand Down
17 changes: 17 additions & 0 deletions Sources/Postie/Query/QueryItem.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/// A type that can be used as a value for a query item.
///
/// The `QueryItemValue` protocol defines a type that can be used as a value for a query item.
/// It requires conforming types to provide a `serialized` property that returns a string representation of the query item value.
internal protocol QueryItemProtocol {
/// Custom name of the query item, can be nil
var name: String? { get }
Expand Down Expand Up @@ -171,8 +175,21 @@ extension QueryItem where T == String? {

// MARK: - OptionalType

/// A type that can be used as a value for a query item.
///
/// The `OptionalType` protocol defines a type that can be used as a value for a query item.
/// It requires conforming types to provide a `none` property that returns a nil value.
public protocol OptionalType {
/// The type of the wrapped value.
///
/// This property represents the type of the wrapped value.
/// It is used to represent the type of the wrapped value for the optional type.
associatedtype Wrapped

/// The nil value of the optional type.
///
/// This property represents the nil value of the optional type.
/// It is used to represent a nil value for the optional type.
static var none: Self { get }
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/Postie/Query/QueryItemValue.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/// A type that can be used as a value for a query item.
///
/// The `QueryItemValue` protocol defines a type that can be used as a value for a query item.
/// It requires conforming types to provide a `serializedQueryItem` property that returns a string representation of the query item value.
public protocol QueryItemValue {
/// The serialized value of the query item.
///
Expand Down
26 changes: 26 additions & 0 deletions Sources/Postie/Responses/NestedResponse.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
/// A property wrapper that wraps a nested response.
///
/// To support inheritance, which can be especially useful for pagination, use the property wrapper `@NestedResponse` to add nested responses.
///
/// While decoding the flat HTTP response will be applied recursively to all nested responses, therefore it is possible, that different nested responses access different values of the original HTTP response.
///
/// **Example:**
///
/// ```swift
/// struct PaginatedResponse<NestedRequest: Request>: Decodable {
///
/// /// Header which indicates how many more elements are available
/// @ResponseHeader<DefaultHeaderStrategy> var totalElements
///
/// @NestedResponse var nested: NestedRequest
/// }
///
/// struct ListRequest: Request {
///
/// typealias Response = PaginatedResponse<ListResponse>
///
/// struct ListResponse: Decodable {
/// // see other examples
/// }
/// }
/// ```
@propertyWrapper
public struct NestedResponse<Response: Decodable> {
/// The wrapped value representing the nested response.
Expand Down
17 changes: 17 additions & 0 deletions Sources/Postie/Responses/ResponseBody/ResponseBodyWrapper.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/// A property wrapper that wraps a response body.
///
/// The `ResponseBodyWrapper` property wrapper is used to wrap a response body value.
/// It provides a `wrappedValue` property that holds the response body value.
///
/// Example usage:
/// ```
/// @ResponseBodyWrapper var responseBody: MyResponseType?
/// ```
@propertyWrapper
public struct ResponseBodyWrapper<Body: Decodable, BodyStrategy: ResponseBodyDecodingStrategy> {
/// The wrapped value representing the decoded response body.
Expand Down Expand Up @@ -31,6 +40,14 @@ public struct ResponseBodyWrapper<Body: Decodable, BodyStrategy: ResponseBodyDec
// MARK: Decodable

extension ResponseBodyWrapper: Decodable {
/// Initializes a new instance of `ResponseBodyWrapper` from a decoder.
///
/// - Parameter decoder: The decoder to use for decoding the response body.
///
/// Example usage:
/// ```
/// let responseBody: MyResponseType? = try ResponseBodyWrapper(from: decoder)
/// ```
public init(from decoder: Decoder) throws {
guard let responseDecoder = decoder as? ResponseDecoding else {
self.wrappedValue = try Body(from: decoder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/// A property wrapper that wraps an error response body.
///
/// The `ResponseErrorBodyWrapper` property wrapper is used to wrap an error response body value.
/// It provides a `wrappedValue` property that holds the error response body value.
///
/// Example usage:
/// ```
/// @ResponseErrorBodyWrapper var errorResponseBody: MyErrorResponseType?
/// ```
@propertyWrapper
public struct ResponseErrorBodyWrapper<Body: Decodable, BodyStrategy: ResponseErrorBodyDecodingStrategy> {
/// The wrapped value representing the decoded error response body.
Expand Down Expand Up @@ -30,7 +39,16 @@ public struct ResponseErrorBodyWrapper<Body: Decodable, BodyStrategy: ResponseEr

// MARK: Decodable

/// Implements the `Decodable` protocol for `ResponseErrorBodyWrapper`.
extension ResponseErrorBodyWrapper: Decodable {
/// Initializes a new instance of `ResponseErrorBodyWrapper` from a decoder.
///
/// - Parameter decoder: The decoder to use for decoding the error response body.
///
/// Example usage:
/// ```
/// let errorResponseBody: MyErrorResponseType? = try ResponseErrorBodyWrapper(from: decoder)
/// ```
public init(from decoder: Decoder) throws {
guard let responseDecoder = decoder as? ResponseDecoding else {
self.wrappedValue = try Body(from: decoder)
Expand Down
6 changes: 6 additions & 0 deletions Sources/Postie/Status Codes/HTTPStatusCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ extension HTTPStatusCode: Comparable, Equatable {
}

extension Range where Bound == HTTPStatusCode {
/// Checks if a value is within a range of HTTP status codes.
///
/// - Parameters:
/// - range: The range of HTTP status codes to check against.
/// - value: The value to check against the range.
/// - Returns: `true` if the value is within the range, otherwise `false`.
public static func ~= (range: Range<HTTPStatusCode>, value: Int) -> Bool {
guard let status = HTTPStatusCode(rawValue: UInt16(value)) else {
return false
Expand Down
Loading

0 comments on commit 5b32f40

Please sign in to comment.