Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class SharedDataIssueSolver: NSObject {
/// both apps are logged in with the same account.
///
public func migrateAuthKey(for username: String) {
guard AppConfiguration.isJetpack,
guard BuildSettings.current.brand == .jetpack,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using BuildSettings over AppConfiguration allows moving to WordPressData where the latter is not available.

let token = try? keychainUtils.getPassword(for: username, serviceName: WPAccountConstants.authToken.rawValue) else {
return
}
Expand Down
74 changes: 74 additions & 0 deletions WordPress/Classes/Models/Blog/Blog+SupportDescription.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import WordPressData

extension Blog {

/// Formatted information to send to Support when user creates a new ticket.
var supportDescription: String {
let blogType = "Type: \(stateDescription)"
let urlType = wordPressComRestApi != nil ? "REST" : "Self-hosted"
let urlString = "URL: \(url ?? "'no url!'")"

let username: String?
let planDescription: String?
if account == nil {
if let jetpackConnectedUsername = jetpack?.connectedUsername {
username = jetpackConnectedUsername
} else {
username = nil
}
planDescription = nil
} else {
let planIDString: String
if let planID {
planIDString = "\(planID)"
} else {
planIDString = "'no id'"
}
planDescription = "Plan: \(planTitle ?? "'no title'") (\(planIDString))"
username = nil
}

var blogInformation: [String] = []

// Add information to array in the order we want to display it.
blogInformation.append(blogType)

if let username {
blogInformation.append(username)
}

blogInformation.append(urlType)
blogInformation.append(urlString)

if let planDescription {
blogInformation.append(planDescription)
}

if let jetpack, jetpack.isInstalled, let version = jetpack.version {
blogInformation.append("Jetpack-version: \(version)")
}

return blogInformation.joined(separator: " ")
}

var stateDescription: String {
guard account == nil else {
return "wpcom"
}

guard let jetpack else {
return "self_hosted"
}

if jetpack.isConnected {
let apiType = wordPressComRestApi != nil ? "REST" : "XML-RPC"
return "jetpack_connected - \(apiType)"
}

if jetpack.isInstalled {
return "self-hosted - jetpack_installed"
}

return "self_hosted"
}
}
22 changes: 22 additions & 0 deletions WordPress/Classes/Models/Blog/Blog+WordPressComRestAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import WordPressData
import WordPressKit

public extension Blog {

/// Returns a REST API client, if available
///
/// If the blog is a WordPress.com one or it has Jetpack it will return a REST API client.
/// Otherwise, the XML-RPC API should be used.
///
/// - Warning: this method doesn't know if a Jetpack blog has the JSON API disabled.
@objc
var wordPressComRestApi: WordPressComRestApi? {
account?.wordPressComRestApi
}

/// Whether the blog is hosted on WordPress.com or connected through Jetpack.
@objc
func isAccessibleThroughWPCom() -> Bool {
wordPressComRestApi != nil
}
}
30 changes: 0 additions & 30 deletions WordPress/Classes/Models/Blog/Blog.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,36 +272,6 @@ typedef NS_ENUM(NSInteger, SiteVisibility) {
*/
- (NSString *)logDescription;

/**
Returns formatted Blog information to send to Support when user creates a new ticket.
*/
- (NSString *)supportDescription;

/**
Returns formatted Blog State information to send to Support when user creates a new ticket.
*/
- (NSString *)stateDescription;

/**
Returns a REST API client if available

If the blog is a WordPress.com one or it has Jetpack it will return a REST API
client. Otherwise, the XML-RPC API should be used.

@warning this method doesn't know if a Jetpack blog has the JSON API disabled

@return a WordPressComRestApi object if available
*/
- (nullable WordPressComRestApi *)wordPressComRestApi;

/**
Call this method to know if the blog is hosted at WPcom or accessed through Jetpack.

@return YES if the blog is hosted at WPcom or if it's connected through Jetpack.
NO otherwise.
*/
- (BOOL)isAccessibleThroughWPCom;

/**
Check if there is already a basic auth credential stored for this blog/site.

Expand Down
71 changes: 0 additions & 71 deletions WordPress/Classes/Models/Blog/Blog.m
Original file line number Diff line number Diff line change
Expand Up @@ -824,65 +824,6 @@ - (NSString *)logDescription
return [NSString stringWithFormat:@"<Blog Name: %@ URL: %@ XML-RPC: %@%@ ObjectID: %@>", self.settings.name, self.url, self.xmlrpc, extra, self.objectID.URIRepresentation];
}

- (NSString *)supportDescription
{
// Gather information

NSString *blogType = [NSString stringWithFormat:@"Type: (%@)", [self stateDescription]];
NSString *urlType = [self wordPressComRestApi] ? @"REST" : @"Self-hosted";
NSString *url = [NSString stringWithFormat:@"URL: %@", self.url];

NSString *username;
NSString *planDescription;
if (self.account) {
planDescription = [NSString stringWithFormat:@"Plan: %@ (%@)", self.planTitle, self.planID];
} else {
username = [self.jetpack connectedUsername];
}

NSString *jetpackVersion;
if ([self.jetpack isInstalled]) {
jetpackVersion = [NSString stringWithFormat:@"Jetpack-version: %@", [self.jetpack version]];
}

// Add information to array in the order we want to display it.

NSMutableArray *blogInformation = [[NSMutableArray alloc] init];
[blogInformation addObject:blogType];
if (username) {
[blogInformation addObject:username];
}
[blogInformation addObject:urlType];
[blogInformation addObject:url];
if (planDescription) {
[blogInformation addObject:planDescription];
}
if (jetpackVersion) {
[blogInformation addObject:jetpackVersion];
}

// Combine and return.
return [NSString stringWithFormat:@"<%@>", [blogInformation componentsJoinedByString:@" "]];
}

- (NSString *)stateDescription
{
if (self.account) {
return @"wpcom";
}

if ([self.jetpack isConnected]) {
NSString *apiType = [self wordPressComRestApi] ? @"REST" : @"XML-RPC";
return [NSString stringWithFormat:@"jetpack_connected - %@", apiType];
}

if ([self.jetpack isInstalled]) {
return @"self-hosted - jetpack_installed";
}

return @"self_hosted";
}

#pragma mark - api accessor

- (WordPressOrgXMLRPCApi *)xmlrpcApi
Expand All @@ -905,18 +846,6 @@ - (WordPressOrgRestApi *)selfHostedSiteRestApi
return _selfHostedSiteRestApi;
}

- (WordPressComRestApi *)wordPressComRestApi
{
if (self.account) {
return self.account.wordPressComRestApi;
}
return nil;
}

- (BOOL)isAccessibleThroughWPCom {
return self.wordPressComRestApi != nil;
}

- (BOOL)supportsRestApi {
// We don't want to check for `restApi` as it can be `nil` when the token
// is missing from the keychain.
Expand Down
5 changes: 0 additions & 5 deletions WordPress/Classes/Models/PublicizeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public extension PublicizeService {
case threads
case unknown

/// Returns the local image for the icon representing the social network.
var localIconImage: UIImage {
WPStyleGuide.socialIcon(for: rawValue as NSString)
}

Comment on lines -44 to -48

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

socialIcon(for service: NSString) -> UIImage is defined in the apps target / Keystone, which WordPressData does not have access to.

By moving it away from here, we unblock adding this required extension to the framework.

/// A string describing the service in a human-readable format.
public var description: String {
rawValue.split(separator: "-").joined(separator: " ").localizedCapitalized
Expand Down
3 changes: 2 additions & 1 deletion WordPress/Classes/Models/WPAccount+Lookup.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BuildSettingsKit
import CoreData

public extension WPAccount {
Expand All @@ -19,7 +20,7 @@ public extension WPAccount {
// Decoupling allows moving the type to WordPressData, see https://github.com/wordpress-mobile/WordPress-iOS/issues/24165.
@objc
static func tokenForUsername(_ username: String) -> String? {
token(forUsername: username, isJetpack: AppConfiguration.isJetpack)
token(forUsername: username, isJetpack: BuildSettings.current.brand == .jetpack)
}

/// Does this `WPAccount` object have any associated blogs?
Expand Down
12 changes: 6 additions & 6 deletions WordPress/Classes/Services/BlogJetpackSettingsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct BlogJetpackSettingsService {
success()
return
}
guard let remoteAPI = blog.wordPressComRestApi(),
guard let remoteAPI = blog.wordPressComRestApi,
let blogDotComId = blog.dotComID as? Int
else {
failure(nil)
Expand Down Expand Up @@ -78,7 +78,7 @@ struct BlogJetpackSettingsService {
success()
return
}
guard let remoteAPI = blog.wordPressComRestApi(),
guard let remoteAPI = blog.wordPressComRestApi,
let blogDotComId = blog.dotComID as? Int
else {
failure(nil)
Expand All @@ -101,7 +101,7 @@ struct BlogJetpackSettingsService {
}

func updateJetpackSettingsForBlog(_ blog: Blog, success: @escaping () -> Void, failure: @escaping (Error?) -> Void) {
guard let remoteAPI = blog.wordPressComRestApi(),
guard let remoteAPI = blog.wordPressComRestApi,
let blogDotComId = blog.dotComID as? Int,
let blogSettings = blog.settings
else {
Expand All @@ -122,7 +122,7 @@ struct BlogJetpackSettingsService {
}

func updateJetpackMonitorSettingsForBlog(_ blog: Blog, success: @escaping () -> Void, failure: @escaping (Error?) -> Void) {
guard let remoteAPI = blog.wordPressComRestApi(),
guard let remoteAPI = blog.wordPressComRestApi,
let blogDotComId = blog.dotComID as? Int,
let blogSettings = blog.settings
else {
Expand Down Expand Up @@ -166,7 +166,7 @@ struct BlogJetpackSettingsService {
}

func updateJetpackModuleActiveSettingForBlog(_ blog: Blog, module: String, active: Bool, success: @escaping () -> Void, failure: @escaping (Error?) -> Void) {
guard let remoteAPI = blog.wordPressComRestApi(),
guard let remoteAPI = blog.wordPressComRestApi,
let blogDotComId = blog.dotComID as? Int else {
failure(nil)
return
Expand All @@ -183,7 +183,7 @@ struct BlogJetpackSettingsService {
}

func disconnectJetpackFromBlog(_ blog: Blog, success: @escaping () -> Void, failure: @escaping (Error?) -> Void) {
guard let remoteAPI = blog.wordPressComRestApi(),
guard let remoteAPI = blog.wordPressComRestApi,
let blogDotComId = blog.dotComID as? Int else {
failure(nil)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import WordPressKit
/// - Returns: A CommentServiceRemote instance
@objc func remote(blog: Blog) -> CommentServiceRemote? {
if blog.supports(.wpComRESTAPI),
let api = blog.wordPressComRestApi(),
let api = blog.wordPressComRestApi,
let dotComID = blog.dotComID {
return CommentServiceRemoteREST(wordPressComRestApi: api, siteID: dotComID)
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/EditorSettingsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ import WordPressKit
}

func api(for blog: Blog) -> WordPressComRestApi? {
return blog.wordPressComRestApi()
return blog.wordPressComRestApi
}

var apiForDefaultAccount: WordPressComRestApi? {
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/HomepageSettingsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct HomepageSettingsService {
fileprivate let siteID: Int

init?(blog: Blog, coreDataStack: CoreDataStack) {
guard let api = blog.wordPressComRestApi(), let dotComID = blog.dotComID as? Int else {
guard let api = blog.wordPressComRestApi, let dotComID = blog.dotComID as? Int else {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/MediaRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private extension MediaRepository {

@objc(remoteForBlog:error:)
func remote(for blog: Blog) throws -> MediaServiceRemote {
if blog.supports(.wpComRESTAPI), let dotComID = blog.dotComID, let api = blog.wordPressComRestApi() {
if blog.supports(.wpComRESTAPI), let dotComID = blog.dotComID, let api = blog.wordPressComRestApi {
return MediaServiceRemoteREST(wordPressComRestApi: api, siteID: dotComID)
}

Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/PeopleService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct PeopleService {
/// - context: CoreData context to be used.
///
init?(blog: Blog, coreDataStack: CoreDataStackSwift) {
guard let api = blog.wordPressComRestApi(), let dotComID = blog.dotComID as? Int else {
guard let api = blog.wordPressComRestApi, let dotComID = blog.dotComID as? Int else {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/PlanService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ open class PlanService: NSObject {

extension PlanService {
@objc public func plansWithPricesForBlog(_ blog: Blog, success: @escaping () -> Void, failure: @escaping (Error) -> Void) {
guard let restAPI = blog.wordPressComRestApi(),
guard let restAPI = blog.wordPressComRestApi,
let siteID = blog.dotComID?.intValue else {
let description = NSLocalizedString("Unable to update plan prices. There is a problem with the supplied blog.",
comment: "This is an error message that could be shown when updating Plans in the app.")
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/PostService+Revisions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extension PostService {
failure: @escaping (Error?) -> Void) {
guard let blogId = post.blog.dotComID,
let postId = post.postID,
let api = post.blog.wordPressComRestApi() else {
let api = post.blog.wordPressComRestApi else {
failure(nil)
return
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/PostService.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ @implementation PostService

- (instancetype)initWithManagedObjectContext:(NSManagedObjectContext *)context {
return [self initWithManagedObjectContext:context
postServiceRemoteFactory:[PostServiceRemoteFactory.alloc init]];
postServiceRemoteFactory:[[PostServiceRemoteFactory alloc] init]];
}

- (instancetype)initWithManagedObjectContext:(NSManagedObjectContext *)context
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/PostServiceRemoteFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import WordPressShared
@objc public class PostServiceRemoteFactory: NSObject {
@objc public func forBlog(_ blog: Blog) -> PostServiceRemote? {
if blog.supports(.wpComRESTAPI),
let api = blog.wordPressComRestApi(),
let api = blog.wordPressComRestApi,
let dotComID = blog.dotComID {
return PostServiceRemoteREST(wordPressComRestApi: api, siteID: dotComID)
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/RoleService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct RoleService {
fileprivate let siteID: Int

init?(blog: Blog, coreDataStack: CoreDataStack) {
guard let api = blog.wordPressComRestApi(), let dotComID = blog.dotComID as? Int else {
guard let api = blog.wordPressComRestApi, let dotComID = blog.dotComID as? Int else {
return nil
}

Expand Down
Loading