-
Notifications
You must be signed in to change notification settings - Fork 16
Re-implement RemoteBlog and RemoteBlogOptionsHelper in Swift #558
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import Foundation | ||
| import NSObject_SafeExpectations | ||
|
|
||
| /// This class encapsulates all of the *remote* Blog properties | ||
|
Contributor
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. Do you know what a remote blog is? And what's the difference with a "non-remote (?)" blog?
Contributor
Author
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 think "remote" indicates it's an HTTP API model, which is defined by the WordPress API schema (hence the "remote" name?). A "non-remote" blog (or just |
||
| @objcMembers public class RemoteBlog: NSObject { | ||
|
|
||
| /// The ID of the Blog entity. | ||
| public var blogID: NSNumber? | ||
|
|
||
| /// The organization ID of the Blog entity. | ||
| public var organizationID: NSNumber? | ||
|
|
||
| /// Represents the Blog Name. | ||
| public var name: String? | ||
|
|
||
| /// Description of the WordPress Blog. | ||
| public var tagline: String? | ||
|
|
||
| /// Represents the Blog Name. | ||
| public var url: String? | ||
|
|
||
| /// Maps to the XMLRPC endpoint. | ||
| public var xmlrpc: String? | ||
|
|
||
| /// Site Icon's URL. | ||
| public var icon: String? | ||
|
|
||
| /// Product ID of the site's current plan, if it has one. | ||
| public var planID: NSNumber? | ||
|
|
||
| /// Product name of the site's current plan, if it has one. | ||
| public var planTitle: String? | ||
|
|
||
| /// Indicates whether the current's blog plan is paid, or not. | ||
| public var hasPaidPlan: Bool = false | ||
|
|
||
| /// Indicates whether it's a jetpack site, or not. | ||
| public var jetpack: Bool = false | ||
|
|
||
| /// Boolean indicating whether the current user has Admin privileges, or not. | ||
| public var isAdmin: Bool = false | ||
|
|
||
| /// Blog's visibility preferences. | ||
| public var visible: Bool = false | ||
|
|
||
| /// Blog's options preferences. | ||
| public var options: NSDictionary? | ||
|
|
||
| /// Blog's capabilities: Indicate which actions are allowed / not allowed, for the current user. | ||
| public var capabilities: NSDictionary? | ||
|
|
||
| /// Blog's total disk quota space. | ||
| public var quotaSpaceAllowed: NSNumber? | ||
|
|
||
| /// Blog's total disk quota space used. | ||
| public var quotaSpaceUsed: NSNumber? | ||
|
|
||
| /// Parses details from a JSON dictionary, as returned by the WordPress.com REST API. | ||
| public init(JSONDictionary json: NSDictionary) { | ||
|
Contributor
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'm sure you thought of this, too, but at some point it'd be good to make this and the other types currently using
Contributor
Author
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. Indeed. Once I've finished the Swift translation, I'll have a look at the |
||
| self.blogID = json.number(forKey: "ID") | ||
| self.organizationID = json.number(forKey: "organization_id") | ||
| self.name = json.string(forKey: "name") | ||
| self.tagline = json.string(forKey: "description") | ||
| self.url = json.string(forKey: "URL") | ||
| self.xmlrpc = json.string(forKeyPath: "meta.links.xmlrpc") | ||
| self.jetpack = json.number(forKey: "jetpack")?.boolValue ?? false | ||
| self.icon = json.string(forKeyPath: "icon.img") | ||
| self.capabilities = json.object(forKey: "capabilities") as? NSDictionary | ||
| self.isAdmin = json.number(forKeyPath: "capabilities.manage_options")?.boolValue ?? false | ||
| self.visible = json.number(forKey: "visible")?.boolValue ?? false | ||
| self.options = RemoteBlogOptionsHelper.mapOptions(fromResponse: json) | ||
| self.planID = json.number(forKeyPath: "plan.product_id") | ||
| self.planTitle = json.string(forKeyPath: "plan.product_name_short") | ||
| self.hasPaidPlan = json.number(forKeyPath: "plan.is_free")?.boolValue ?? false | ||
| self.quotaSpaceAllowed = json.number(forKeyPath: "quota.space_allowed") | ||
| self.quotaSpaceUsed = json.number(forKeyPath: "quota.space_used") | ||
| } | ||
|
|
||
| } | ||
This file was deleted.
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.
Chasing down these two imports, I noticed their footprint is minimal in this implementation. As far as I could see, only this method:
WordPressKit-iOS/WordPressKit/AccountServiceRemoteREST.m
Lines 386 to 393 in 8ecfcca
Might it be useful to re-write it in Swift in the context of this PR?
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.
I intentionally started with the easy ones to translate. This
AccountServiceRemoteRESTfalls into my harder basket, and will be dealt with after I have finished with the easy ones 🥲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.
Sure.
Just to be clear, I was suggesting converting only that method, but I can see how adding a dedicated extension just for it would be wasteful given we'd remove it once the whole class is converted soon enough.