-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added convenience decoding strategies
- Loading branch information
Showing
12 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
Sources/Postie/Responses/ResponseBody/ResponseBody+DecodingStrategies.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
public extension ResponseBody { | ||
|
||
typealias OptionalContent = ResponseBodyWrapper<Body, OptionalContentStrategy> | ||
|
||
typealias Status200 = ResponseBodyWrapper<Body, ValidateStatus200BodyStrategy> | ||
typealias Status303 = ResponseBodyWrapper<Body, ValidateStatus303BodyStrategy> | ||
} |
9 changes: 9 additions & 0 deletions
9
Sources/Postie/Responses/ResponseErrorBody/ResponseErrorBody+DecodingStrategies.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public extension ResponseErrorBody { | ||
typealias Status400 = ResponseErrorBodyWrapper<Body, ValidateStatus400BodyStrategy> | ||
typealias Status401 = ResponseErrorBodyWrapper<Body, ValidateStatus401BodyStrategy> | ||
typealias Status403 = ResponseErrorBodyWrapper<Body, ValidateStatus403BodyStrategy> | ||
typealias Status404 = ResponseErrorBodyWrapper<Body, ValidateStatus404BodyStrategy> | ||
typealias Status410 = ResponseErrorBodyWrapper<Body, ValidateStatus410BodyStrategy> | ||
typealias Status422 = ResponseErrorBodyWrapper<Body, ValidateStatus422BodyStrategy> | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
Sources/Postie/Strategies/Body/ValidateStatus200BodyStrategy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public struct ValidateStatus200BodyStrategy: ResponseBodyDecodingStrategy { | ||
public static func allowsEmptyContent(for _: Int) -> Bool { | ||
return false | ||
} | ||
|
||
public static func validate(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.ok.rawValue | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Sources/Postie/Strategies/Body/ValidateStatus201BodyStrategy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public struct ValidateStatus201BodyStrategy: ResponseBodyDecodingStrategy { | ||
public static func allowsEmptyContent(for _: Int) -> Bool { | ||
return false | ||
} | ||
|
||
public static func validate(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.created.rawValue | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Sources/Postie/Strategies/Body/ValidateStatus303BodyStrategy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public struct ValidateStatus303BodyStrategy: ResponseBodyDecodingStrategy { | ||
public static func allowsEmptyContent(for _: Int) -> Bool { | ||
return true | ||
} | ||
|
||
public static func validate(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.seeOther.rawValue | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Sources/Postie/Strategies/Body/ValidateStatus400BodyStrategy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct ValidateStatus400BodyStrategy: ResponseErrorBodyDecodingStrategy { | ||
public static func isError(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.badRequest.rawValue | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Sources/Postie/Strategies/Body/ValidateStatus401BodyStrategy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct ValidateStatus401BodyStrategy: ResponseErrorBodyDecodingStrategy { | ||
public static func isError(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.unauthorized.rawValue | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Sources/Postie/Strategies/Body/ValidateStatus403BodyStrategy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct ValidateStatus403BodyStrategy: ResponseErrorBodyDecodingStrategy { | ||
public static func isError(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.forbidden.rawValue | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Sources/Postie/Strategies/Body/ValidateStatus404BodyStrategy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct ValidateStatus404BodyStrategy: ResponseErrorBodyDecodingStrategy { | ||
public static func isError(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.notFound.rawValue | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Sources/Postie/Strategies/Body/ValidateStatus410BodyStrategy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct ValidateStatus410BodyStrategy: ResponseErrorBodyDecodingStrategy { | ||
public static func isError(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.gone.rawValue | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Sources/Postie/Strategies/Body/ValidateStatus422BodyStrategy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct ValidateStatus422BodyStrategy: ResponseErrorBodyDecodingStrategy { | ||
public static func isError(statusCode: Int) -> Bool { | ||
statusCode == HTTPStatusCode.unprocessableEntity.rawValue | ||
} | ||
} |