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
14 changes: 4 additions & 10 deletions Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let package = Package(
.library(name: "WordPressReader", targets: ["WordPressReader"]),
.library(name: "WordPressCore", targets: ["WordPressCore"]),
.library(name: "WordPressCoreProtocols", targets: ["WordPressCoreProtocols"]),
.library(name: "WordPressKit", targets: ["WordPressKit"]),
],
dependencies: [
.package(url: "https://github.com/airbnb/lottie-ios", from: "4.4.0"),
Expand Down Expand Up @@ -195,26 +196,20 @@ let package = Package(
resources: [.process("Resources")],
swiftSettings: [.swiftLanguageMode(.v5)]
),
.target(
name: "WordPressKitObjCUtils",
cSettings: [
.define("NS_BLOCK_ASSERTIONS", to: "1", .when(configuration: .release))
]
),
.target(
name: "WordPressKitModels",
dependencies: [
"NSObject-SafeExpectations",
"WordPressKitObjCUtils",
"WordPressShared",
]
),
.target(
name: "WordPressKitObjC",
dependencies: [
"NSObject-SafeExpectations",
"wpxmlrpc",
"WordPressKitModels",
"WordPressKitObjCUtils",
"WordPressShared",
"WordPressKitModels"
],
publicHeadersPath: "include",
cSettings: [
Expand All @@ -226,7 +221,6 @@ let package = Package(
dependencies: [
"WordPressKitObjC",
"WordPressKitModels",
"WordPressKitObjCUtils",
"NSObject-SafeExpectations",
"WordPressShared",
"wpxmlrpc",
Expand Down
5 changes: 3 additions & 2 deletions Modules/Sources/WordPressKit/AccountSettingsRemote.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressShared
import WordPressKitObjC

public class AccountSettingsRemote: ServiceRemoteWordPressComREST {
Expand Down Expand Up @@ -178,12 +179,12 @@ public class AccountSettingsRemote: ServiceRemoteWordPressComREST {
throw ResponseError.decodingFailure
}

let aboutMeText = aboutMe.wpkit_stringByDecodingXMLCharacters()
let aboutMeText = aboutMe.stringByDecodingXMLCharacters()

return AccountSettings(firstName: firstName,
lastName: lastName,
displayName: displayName,
aboutMe: aboutMeText!,
aboutMe: aboutMeText,
username: username,
usernameCanBeChanged: usernameCanBeChanged,
email: email,
Expand Down
1 change: 0 additions & 1 deletion Modules/Sources/WordPressKit/Exports.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@_exported import WordPressKitModels
@_exported import WordPressKitObjC
@_exported import WordPressKitObjCUtils

extension ServiceRemoteWordPressComREST {
public var wordPressComRestApi: WordPressComRestApi {
Expand Down
3 changes: 2 additions & 1 deletion Modules/Sources/WordPressKit/PeopleServiceRemote.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressShared
import WordPressKitObjC

/// Encapsulates all of the People Management WordPress.com Methods
Expand Down Expand Up @@ -558,7 +559,7 @@ private extension PeopleServiceRemote {
let firstName = user["first_name"] as? String
let lastName = user["last_name"] as? String
let avatarURL = (user["avatar_URL"] as? NSString)
.flatMap { URL(string: $0.wpkit_stringByUrlEncoding())}
.flatMap { URL(string: $0.wp_stringByUrlEncoding())}

let linkedUserID = user["linked_user_ID"] as? Int ?? ID
let isSuperAdmin = user["is_super_admin"] as? Bool ?? false
Expand Down
5 changes: 3 additions & 2 deletions Modules/Sources/WordPressKit/PluginDirectoryEntry.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressShared

public struct PluginDirectoryEntry {
public let name: String
Expand Down Expand Up @@ -77,7 +78,7 @@ extension PluginDirectoryEntry: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let decodedName = try container.decode(String.self, forKey: .name)
name = decodedName.wpkit_stringByDecodingXMLCharacters()
name = decodedName.stringByDecodingXMLCharacters()
slug = try container.decode(String.self, forKey: .slug)
version = try? container.decode(String.self, forKey: .version)
lastUpdated = try? container.decode(Date.self, forKey: .lastUpdated)
Expand Down Expand Up @@ -115,7 +116,7 @@ extension PluginDirectoryEntry: Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(name.wpkit_stringByEncodingXMLCharacters(), forKey: .name)
try container.encode(name.stringByEncodingXMLCharacters(), forKey: .name)
try container.encode(slug, forKey: .slug)
try container.encodeIfPresent(version, forKey: .version)
try container.encodeIfPresent(lastUpdated, forKey: .lastUpdated)
Expand Down
3 changes: 2 additions & 1 deletion Modules/Sources/WordPressKit/StatsLastPostInsight.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressShared

public struct StatsLastPostInsight: Equatable, Decodable {
public let title: String
Expand Down Expand Up @@ -81,7 +82,7 @@ extension StatsLastPostInsight {

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
title = try container.decode(String.self, forKey: .title).trimmingCharacters(in: .whitespaces).wpkit_stringByDecodingXMLCharacters()
title = try container.decode(String.self, forKey: .title).trimmingCharacters(in: .whitespaces).stringByDecodingXMLCharacters()
url = try container.decode(URL.self, forKey: .url)
let dateString = try container.decode(String.self, forKey: .publishedDate)
guard let date = StatsLastPostInsight.dateFormatter.date(from: dateString) else {
Expand Down
8 changes: 0 additions & 8 deletions Modules/Sources/WordPressKit/String+Helpers.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import Foundation

extension String {
func stringByDecodingXMLCharacters() -> String {
return NSString.wpkit_decodeXMLCharacters(in: self)
}

func stringByEncodingXMLCharacters() -> String {
return NSString.wpkit_encodeXMLCharacters(in: self)
}

func trim() -> String {
return trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
}
Expand Down
8 changes: 4 additions & 4 deletions Modules/Sources/WordPressKitModels/NSString+Summary.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import WordPressKitObjCUtils
import WordPressShared

/// This is an extension to NSString that provides logic to summarize HTML content,
/// and convert HTML into plain text.
Expand All @@ -20,16 +20,16 @@ extension NSString {
.strippingShortcodes()
.makePlainText()
.trimmingCharacters(in: characterSet)
.wpkit_stringByEllipsizing(withMaxLength: NSString.PostDerivedSummaryLength, preserveWords: true)
.wp_stringByEllipsizing(withMaxLength: NSString.PostDerivedSummaryLength, preserveWords: true)
}
}

private extension String {
func makePlainText() -> String {
let characterSet = NSCharacterSet.whitespacesAndNewlines

return self.wpkit_stringByStrippingHTML()
.wpkit_stringByDecodingXMLCharacters()
return self.strippingHTML()
.stringByDecodingXMLCharacters()
.trimmingCharacters(in: characterSet)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressShared

@objcMembers public class RemoteBlogOptionsHelper: NSObject {

Expand Down Expand Up @@ -73,8 +74,8 @@ import Foundation

public class func remoteBlogSettings(fromXMLRPCDictionaryOptions options: NSDictionary) -> RemoteBlogSettings {
let remoteSettings = RemoteBlogSettings()
remoteSettings.name = options.string(forKeyPath: "blog_title.value")?.wpkit_stringByDecodingXMLCharacters()
remoteSettings.tagline = options.string(forKeyPath: "blog_tagline.value")?.wpkit_stringByDecodingXMLCharacters()
remoteSettings.name = options.string(forKeyPath: "blog_title.value")?.stringByDecodingXMLCharacters()
remoteSettings.tagline = options.string(forKeyPath: "blog_tagline.value")?.stringByDecodingXMLCharacters()
if options["blog_public"] != nil {
remoteSettings.privacy = options.number(forKeyPath: "blog_public.value")
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/Sources/WordPressKitObjC/AccountServiceRemoteREST.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "AccountServiceRemoteREST.h"
#import "WPMapFilterReduce.h"

@import WordPressShared;
@import WordPressKitModels;
@import NSObject_SafeExpectations;

Expand Down Expand Up @@ -420,9 +420,9 @@ - (RemoteUser *)remoteUserFromDictionary:(NSDictionary *)dictionary
- (NSArray *)remoteBlogsFromJSONArray:(NSArray *)jsonBlogs
{
NSArray *blogs = jsonBlogs;
return [[blogs wpkit_map:^id(NSDictionary *jsonBlog) {
return [[blogs wp_map:^id(NSDictionary *jsonBlog) {
return [[RemoteBlog alloc] initWithJSONDictionary:jsonBlog];
}] wpkit_filter:^BOOL(RemoteBlog *blog) {
}] wp_filter:^BOOL(RemoteBlog *blog) {
// Exclude deleted sites from query result, since the app does not handle deleted sites properly.
// I tried to use query arguments `site_visibility=visible` and `site_activity=active`, but neither excludes
// deleted sites.
Expand Down
6 changes: 3 additions & 3 deletions Modules/Sources/WordPressKitObjC/BlogServiceRemoteREST.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#import "BlogServiceRemoteREST.h"
#import "NSMutableDictionary+Helpers.h"
#import "RemotePostType.h"
#import "WPMapFilterReduce.h"
#import "WPKitLogging.h"

@import WordPressShared;
@import WordPressKitModels;
@import NSObject_SafeExpectations;

Expand Down Expand Up @@ -145,7 +145,7 @@ - (void)syncPostTypesWithSuccess:(PostTypesHandler)success
success:^(NSDictionary *responseObject, NSHTTPURLResponse *httpResponse) {

NSAssert([responseObject isKindOfClass:[NSDictionary class]], @"Response should be a dictionary.");
NSArray <RemotePostType *> *postTypes = [[responseObject arrayForKey:RemotePostTypesKey] wpkit_map:^id(NSDictionary *json) {
NSArray <RemotePostType *> *postTypes = [[responseObject arrayForKey:RemotePostTypesKey] wp_map:^id(NSDictionary *json) {
return [self remotePostTypeWithDictionary:json];
}];
if (!postTypes.count) {
Expand Down Expand Up @@ -340,7 +340,7 @@ - (NSString *)pathForSettings

- (NSArray *)usersFromJSONArray:(NSArray *)jsonUsers
{
return [jsonUsers wpkit_map:^RemoteUser *(NSDictionary *jsonUser) {
return [jsonUsers wp_map:^RemoteUser *(NSDictionary *jsonUser) {
return [self userFromJSONDictionary:jsonUser];
}];
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/Sources/WordPressKitObjC/BlogServiceRemoteXMLRPC.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#import "BlogServiceRemoteXMLRPC.h"
#import "NSMutableDictionary+Helpers.h"
#import "RemotePostType.h"
#import "WPMapFilterReduce.h"
#import "WPKitLogging.h"

@import WordPressShared;
@import WordPressKitModels;
@import NSObject_SafeExpectations;

Expand Down Expand Up @@ -49,7 +49,7 @@ - (void)getAllAuthorsWithRemoteUsers:(NSMutableArray <RemoteUser *>*)remoteUsers
[self.api callMethod:@"wp.getUsers"
parameters:parameters
success:^(id responseObject, NSHTTPURLResponse *response) {
NSArray <RemoteUser *> *responseUsers = [[responseObject allObjects] wpkit_map:^id(NSDictionary *xmlrpcUser) {
NSArray <RemoteUser *> *responseUsers = [[responseObject allObjects] wp_map:^id(NSDictionary *xmlrpcUser) {
return [self remoteUserFromXMLRPCDictionary:xmlrpcUser];
}];

Expand Down Expand Up @@ -82,7 +82,7 @@ - (void)syncPostTypesWithSuccess:(PostTypesHandler)success failure:(void (^)(NSE
success:^(id responseObject, NSHTTPURLResponse *response) {

NSAssert([responseObject isKindOfClass:[NSDictionary class]], @"Response should be a dictionary.");
NSArray <RemotePostType *> *postTypes = [[responseObject allObjects] wpkit_map:^id(NSDictionary *json) {
NSArray <RemotePostType *> *postTypes = [[responseObject allObjects] wp_map:^id(NSDictionary *json) {
return [self remotePostTypeFromXMLRPCDictionary:json];
}];
if (!postTypes.count) {
Expand Down
6 changes: 3 additions & 3 deletions Modules/Sources/WordPressKitObjC/CommentServiceRemoteREST.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "CommentServiceRemoteREST.h"
#import "RemoteComment.h"
#import "WPMapFilterReduce.h"

@import WordPressShared;
@import WordPressKitModels;
@import NSObject_SafeExpectations;

Expand Down Expand Up @@ -464,7 +464,7 @@ - (void)getLikesForCommentID:(NSNumber *)commentID

- (NSArray *)remoteCommentsFromJSONArray:(NSArray *)jsonComments
{
return [jsonComments wpkit_map:^id(NSDictionary *jsonComment) {
return [jsonComments wp_map:^id(NSDictionary *jsonComment) {
return [self remoteCommentFromJSONDictionary:jsonComment];
}];
}
Expand Down Expand Up @@ -530,7 +530,7 @@ - (NSString *)remoteStatusWithStatus:(NSString *)status
commentID:(NSNumber *)commentID
siteID:(NSNumber *)siteID
{
return [jsonUsers wpkit_map:^id(NSDictionary *jsonUser) {
return [jsonUsers wp_map:^id(NSDictionary *jsonUser) {
return [[RemoteLikeUser alloc] initWithDictionary:jsonUser commentID:commentID siteID:siteID];
}];
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/Sources/WordPressKitObjC/CommentServiceRemoteXMLRPC.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "CommentServiceRemoteXMLRPC.h"
#import "RemoteComment.h"
#import "WPMapFilterReduce.h"

@import WordPressShared;
@import wpxmlrpc;
@import NSObject_SafeExpectations;

Expand Down Expand Up @@ -203,7 +203,7 @@ - (void)trashComment:(RemoteComment *)comment

- (NSArray *)remoteCommentsFromXMLRPCArray:(NSArray *)xmlrpcArray
{
return [xmlrpcArray wpkit_map:^id(NSDictionary *xmlrpcComment) {
return [xmlrpcArray wp_map:^id(NSDictionary *xmlrpcComment) {
return [self remoteCommentFromXMLRPCDictionary:xmlrpcComment];
}];
}
Expand Down
Loading