Skip to content

Commit

Permalink
Merge pull request #25 from immobiliare/1.2.1
Browse files Browse the repository at this point in the history
Release 1.2.1
  • Loading branch information
malcommac authored Mar 15, 2022
2 parents 9b4dbd7 + 4b8f439 commit 55a4e4f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion RealHTTP.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "RealHTTP"
s.version = "1.2.0"
s.version = "1.2.1"
s.summary = "Lightweight yet powerful http-client & stubber for Swift with native async/await support"
s.homepage = "https://github.com/immobiliare/RealHTTP.git"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
3 changes: 3 additions & 0 deletions Sources/RealHTTP/Client/HTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class HTTPClient {
/// Headers which are automatically attached to each request.
public var headers = HTTPHeaders()

/// A list of query params values which will be appended to each request.
public var queryParams = [URLQueryItem]()

/// Timeout interval for requests, expressed in seconds.
/// Defaults value is `HTTPRequest.DefaultTimeout` but each http request may use it's value.
public var timeout: TimeInterval = HTTPRequest.DefaultTimeout
Expand Down
5 changes: 5 additions & 0 deletions Sources/RealHTTP/Client/HTTPRequest/HTTPRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ extension URLComponents {
newComp.host = baseURL.host
newComp.port = baseURL.port
newComp.path = baseURL.path + (newComp.path.first == "/" ? "" : "/") + newComp.path

if let commonQueryParams = client?.queryParams, commonQueryParams.isEmpty == false {
newComp.queryItems?.append(contentsOf: commonQueryParams)
}

return newComp.url
}

Expand Down
10 changes: 6 additions & 4 deletions Sources/RealHTTP/Client/HTTPResponse/HTTPResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ public struct HTTPResponse: CustomStringConvertible {
/// Decode a raw response using `Decodable` object type.
///
/// - Returns: `T` or `nil` if no response has been received.
public func decode<T: Decodable>(_ decodable: T.Type, decoder: JSONDecoder = .init()) throws -> T? {
guard let data = data else { return nil }
public func decode<T: Decodable>(_ decodable: T.Type, decoder: JSONDecoder = .init()) throws -> T {
guard let data = data else {
throw HTTPError.init(.emptyResponse)
}

let decodedObj = try decoder.decode(T.self, from: data)
return decodedObj
Expand All @@ -144,7 +146,7 @@ public struct HTTPResponse: CustomStringConvertible {
/// Decode a raw response and transform it to passed `HTTPDecodableResponse` type.
///
/// - Returns: T or `nil` if response is empty.
public func decode<T: HTTPDecodableResponse>(_ decodable: T.Type) throws -> T? {
public func decode<T: HTTPDecodableResponse>(_ decodable: T.Type) throws -> T {
try decodable.decode(self)
}

Expand Down Expand Up @@ -174,7 +176,7 @@ public protocol HTTPDecodableResponse {
/// A custom decoder function.
///
/// - Returns: a valid instance of `Self` or `nil`.
static func decode(_ response: HTTPResponse) throws -> Self?
static func decode(_ response: HTTPResponse) throws -> Self

}

Expand Down
2 changes: 1 addition & 1 deletion Sources/RealHTTP/RealHTTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
public enum RealHTTP {

/// Current RealHTTP version.
static let sdkVersion = "1.2.0"
static let sdkVersion = "1.2.1"

/// Identifier of the agent string.
static let agentIdentifier = "realhttp"
Expand Down

0 comments on commit 55a4e4f

Please sign in to comment.