Skip to content

Commit

Permalink
Allow overridden parameter types on GET/DELETE
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper Blues committed Aug 6, 2021
1 parent dde4d21 commit 544f712
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Allow overridden parameter types on GET/DELETE

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Fri Aug 6 10:54:16 2021 +0800
#
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 1 and 1 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
#
# Changes to be committed:
# modified: Sources/Networking+HTTPRequests.swift
#
# Untracked files:
# .idea/
#
30 changes: 30 additions & 0 deletions Sources/Networking+HTTPRequests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ public extension Networking {
return handleJSONRequest(.get, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: cachingLevel, completion: completion)
}

/// GET request to the specified path, allowing overridden parameter types
///
/// Overridden parameter types can be useful, for example some REST-ful APIs do not strictly adhere to spec.
///
/// - Parameters:
/// - path: The path for the GET request.
/// - parameterType: The parameters type to be used.
/// - parameters: The parameters to be used, they will be serialized using Percent-encoding and appended to the URL.
/// - completion: The result of the operation, it's an enum with two cases: success and failure.
/// - Returns: The request identifier.
@discardableResult
func get(_ path: String, parameterType: ParameterType, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String {
handleJSONRequest(.get, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion)
}

/// Registers a fake GET request for the specified path. After registering this, every GET request to the path, will return the registered response.
///
/// - Parameters:
Expand Down Expand Up @@ -205,6 +220,21 @@ public extension Networking {
return handleJSONRequest(.delete, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion)
}

/// DELETE request to the specified path, allowing overridden parameter types
///
/// Overridden parameter types can be useful, for example some REST-ful APIs do not strictly adhere to spec.
///
/// - Parameters:
/// - path: The path for the DELETE request.
/// - parameterType: The parameters type to be used.
/// - parameters: The parameters to be used, they will be serialized using Percent-encoding and appended to the URL.
/// - completion: The result of the operation, it's an enum with two cases: success and failure.
/// - Returns: The request identifier.
@discardableResult
func delete(_ path: String, parameterType: ParameterType, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String {
handleJSONRequest(.delete, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion)
}

/// Registers a fake DELETE request for the specified path. After registering this, every DELETE request to the path, will return the registered response.
///
/// - Parameters:
Expand Down

0 comments on commit 544f712

Please sign in to comment.