-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPM Prep – Move some async perform
types at the WordPressComRESTAPIInterface
level
#788
base: trunk
Are you sure you want to change the base?
Changes from all commits
6f0f3c4
465d589
eb13fb9
b56f5d3
6f046e1
5484521
64e7698
5f2c8fd
38c2e25
e4f566b
23bc2ab
8d0d3df
bc6dcd1
f47621a
70cbfd0
7d8877b
19357f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,10 +198,14 @@ private enum RemotePostWordPressComCodingKeys: String, CodingKey { | |
static let postTags = "post_tag" | ||
} | ||
|
||
struct RemotePostCreateParametersWordPressComEncoder: Encodable { | ||
public struct RemotePostCreateParametersWordPressComEncoder: Encodable { | ||
let parameters: RemotePostCreateParameters | ||
|
||
func encode(to encoder: Encoder) throws { | ||
public init(parameters: RemotePostCreateParameters) { | ||
self.parameters = parameters | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the type became As for 🤔 In hindsight, I suppose the |
||
var container = encoder.container(keyedBy: RemotePostWordPressComCodingKeys.self) | ||
try container.encodeIfPresent(parameters.type, forKey: .type) | ||
try container.encodeIfPresent(parameters.status, forKey: .status) | ||
|
@@ -281,10 +285,14 @@ struct RemotePostUpdateParametersWordPressComMetadata: Encodable { | |
} | ||
} | ||
|
||
struct RemotePostUpdateParametersWordPressComEncoder: Encodable { | ||
public struct RemotePostUpdateParametersWordPressComEncoder: Encodable { | ||
let parameters: RemotePostUpdateParameters | ||
|
||
func encode(to encoder: Encoder) throws { | ||
public init(parameters: RemotePostUpdateParameters) { | ||
self.parameters = parameters | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: RemotePostWordPressComCodingKeys.self) | ||
try container.encodeIfPresent(parameters.ifNotModifiedSince, forKey: .ifNotModifiedSince) | ||
|
||
|
@@ -348,10 +356,14 @@ private enum RemotePostXMLRPCCodingKeys: String, CodingKey { | |
static let postTags = "post_tag" | ||
} | ||
|
||
struct RemotePostCreateParametersXMLRPCEncoder: Encodable { | ||
public struct RemotePostCreateParametersXMLRPCEncoder: Encodable { | ||
let parameters: RemotePostCreateParameters | ||
|
||
func encode(to encoder: Encoder) throws { | ||
public init(parameters: RemotePostCreateParameters) { | ||
self.parameters = parameters | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: RemotePostXMLRPCCodingKeys.self) | ||
try container.encode(parameters.type, forKey: .type) | ||
try container.encodeIfPresent(parameters.status, forKey: .postStatus) | ||
|
@@ -387,10 +399,14 @@ struct RemotePostCreateParametersXMLRPCEncoder: Encodable { | |
} | ||
} | ||
|
||
struct RemotePostUpdateParametersXMLRPCEncoder: Encodable { | ||
public struct RemotePostUpdateParametersXMLRPCEncoder: Encodable { | ||
let parameters: RemotePostUpdateParameters | ||
|
||
func encode(to encoder: Encoder) throws { | ||
public init(parameters: RemotePostUpdateParameters) { | ||
self.parameters = parameters | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: RemotePostXMLRPCCodingKeys.self) | ||
try container.encodeIfPresent(parameters.ifNotModifiedSince, forKey: .ifNotModifiedSince) | ||
try container.encodeIfPresent(parameters.status, forKey: .postStatus) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,14 +18,10 @@ public enum WordPressAPIError<EndpointError>: Error where EndpointError: Localiz | |
/// The API call returned an status code that's unacceptable to the endpoint. | ||
case unacceptableStatusCode(response: HTTPURLResponse, body: Data) | ||
/// The API call returned an HTTP response that WordPressKit can't parse. Receiving this error could be an indicator that there is an error response that's not handled properly by WordPressKit. | ||
case unparsableResponse(response: HTTPURLResponse?, body: Data?, underlyingError: Error) | ||
case unparsableResponse(response: HTTPURLResponse?, body: Data?, underlyingError: Error = URLError(.cannotParseResponse)) | ||
/// Other error occured. | ||
case unknown(underlyingError: Error) | ||
|
||
static func unparsableResponse(response: HTTPURLResponse?, body: Data?) -> Self { | ||
return WordPressAPIError<EndpointError>.unparsableResponse(response: response, body: body, underlyingError: URLError(.cannotParseResponse)) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't look up when, but relatively recently, I think, Swift acquired default values for associated parameters. So we can remove this builder method in favor of defining the underlying error as a default for the case. |
||
|
||
var response: HTTPURLResponse? { | ||
switch self { | ||
case .requestEncodingFailure, .connection, .unknown: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these properties went in the protocol to make the
async perform
methods work.The
async perform
methods, which like inWordPressComRestApi
are Swift-only, of course.I considered using an extension or a different protocol, but it seemed neat to have it all in
WordPressComRESTAPIInterfacing
, so that Swift code can used an upgraded version of the same interface that the Objective-C code uses. This will actually be useful in the cases where we have an ObjC superclass with the API client conforming toWordPressComRESTAPIInterfacing
and a subclass using the API client, too.