Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
  •  
  •  
  •  
24 changes: 0 additions & 24 deletions Sources/WordPressKit/Info.plist

This file was deleted.

15 changes: 0 additions & 15 deletions Sources/WordPressKit/Models/RemoteUser.h

This file was deleted.

5 changes: 0 additions & 5 deletions Sources/WordPressKit/Models/RemoteUser.m

This file was deleted.

8 changes: 0 additions & 8 deletions Sources/WordPressKit/Private/WPKit-Swift.h

This file was deleted.

65 changes: 0 additions & 65 deletions Sources/WordPressKit/WordPressKit.h

This file was deleted.

13 changes: 13 additions & 0 deletions Sources/WordPressKitModels/RemoteUser.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

@objcMembers public class RemoteUser: NSObject {
public var userID: NSNumber?
public var username: String?
public var email: String?
public var displayName: String?
public var primaryBlogID: NSNumber?
public var avatarURL: String?
public var dateCreated: Date?
public var emailVerified: Bool = false
public var linkedUserID: NSNumber?

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.

The original properties in the original Objective-C code are null_unspecified or implicitly unwrapped optional. I can keep the original code and make the new properties IUO, too. But that does not feel right.

The new code now uses optional, which means the app will need to update their codebase to deal with the new optional properties instead of IUO properties.

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#import "AccountServiceRemoteREST.h"
#import "WPKit-Swift.h"
@import NSObject_SafeExpectations;

static NSString * const UserDictionaryIDKey = @"ID";
Expand Down Expand Up @@ -54,7 +53,7 @@ - (void)getAccountDetailsWithSuccess:(void (^)(RemoteUser *remoteUser))success
{
NSString *requestUrl = [self pathForEndpoint:@"me"
withVersion:WordPressComRESTAPIVersion_1_1];

[self.wordPressComRESTAPI get:requestUrl
parameters:nil
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
Expand Down Expand Up @@ -135,7 +134,7 @@ - (void)isPasswordlessAccount:(NSString *)identifier success:(void (^)(BOOL pass
NSDictionary *dict = (NSDictionary *)responseObject;
BOOL passwordless = [[dict numberForKey:@"passwordless"] boolValue];
success(passwordless);

} failure:^(NSError *error, NSHTTPURLResponse *httpResponse) {
if (failure) {
failure(error);
Expand All @@ -147,14 +146,14 @@ - (void)isEmailAvailable:(NSString *)email success:(void (^)(BOOL available))suc
{
static NSString * const errorEmailAddressInvalid = @"invalid";
static NSString * const errorEmailAddressTaken = @"taken";

[self.wordPressComRESTAPI get:@"is-available/email"
parameters:@{ @"q": email, @"format": @"json"}
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
if ([responseObject isKindOfClass:[NSDictionary class]]) {
NSString *error = [responseObject objectForKey:@"error"];
NSString *message = [responseObject objectForKey:@"message"];

if (error != NULL) {
if ([error isEqualToString:errorEmailAddressTaken]) {
// While this is informed as an error by the endpoint, for the purpose of this method
Expand Down Expand Up @@ -182,10 +181,10 @@ - (void)isEmailAvailable:(NSString *)email success:(void (^)(BOOL available))suc
failure(error);
}
}

return;
}

if (success) {
BOOL available = [[responseObject numberForKey:@"available"] boolValue];
success(available);
Expand Down Expand Up @@ -292,10 +291,10 @@ - (void)requestWPComSignupLinkForEmail:(NSString *)email
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure
{

NSString *path = [self pathForEndpoint:@"auth/send-signup-email"
withVersion:WordPressComRESTAPIVersion_1_1];

NSDictionary *extraParams = @{
@"signup_flow_name": @"mobile-ios",
MagicLinkParameterFlow: MagicLinkFlowSignup
Expand All @@ -321,7 +320,7 @@ - (void)requestWPComMagicLinkForEmail:(NSString *)email
failure:(void (^)(NSError *error))failure
{
NSAssert([email length] > 0, @"Needs an email address.");

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:@{
@"email": email,
@"client_id": clientID,
Expand All @@ -331,7 +330,7 @@ - (void)requestWPComMagicLinkForEmail:(NSString *)email
if (![@"wordpress" isEqualToString:scheme]) {
[params setObject:scheme forKey:@"scheme"];
}

if (extraParams != nil) {
[params addEntriesFromDictionary:extraParams];
}
Expand Down Expand Up @@ -398,7 +397,7 @@ - (RemoteUser *)remoteUserFromDictionary:(NSDictionary *)dictionary
remoteUser.avatarURL = [dictionary stringForKey:UserDictionaryAvatarURLKey];
remoteUser.dateCreated = [NSDate wpkit_dateWithISO8601String:[dictionary stringForKey:UserDictionaryDateKey]];
remoteUser.emailVerified = [[dictionary numberForKey:UserDictionaryEmailVerifiedKey] boolValue];

return remoteUser;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#import "BlogServiceRemoteREST.h"
#import "NSMutableDictionary+Helpers.h"
#import "RemotePostType.h"
#import "WPKit-Swift.h"
@import NSObject_SafeExpectations;

#pragma mark - Parsing Keys
Expand Down Expand Up @@ -82,7 +81,7 @@ - (void)getAllAuthorsWithSuccess:(UsersHandler)success
/**
This method is called recursively to fetch all authors.
The success block is called whenever the response users array is nil or empty.

@param remoteUsers The loaded remote users
@param offset The first n users to be skipped in the returned array
@param success The block that will be executed on success
Expand All @@ -96,11 +95,11 @@ - (void)getAllAuthorsWithRemoteUsers:(NSMutableArray <RemoteUser *>*)remoteUsers
NSMutableDictionary *parameters = [@{ @"authors_only":@(YES),
@"number": @(100)
} mutableCopy];

if ([offset wp_isValidObject]) {
parameters[@"offset"] = offset.stringValue;
}

NSString *path = [self pathForUsers];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:WordPressComRESTAPIVersion_1_1];
Expand All @@ -110,9 +109,9 @@ - (void)getAllAuthorsWithRemoteUsers:(NSMutableArray <RemoteUser *>*)remoteUsers
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
if (success) {
NSArray *responseUsers = responseObject[@"users"];

NSMutableArray *users = [remoteUsers wp_isValidObject] ? [remoteUsers mutableCopy] : [NSMutableArray array];

if (![responseUsers wp_isValidObject] || responseUsers.count == 0) {
success([users copy]);
} else {
Expand Down Expand Up @@ -140,7 +139,7 @@ - (void)syncPostTypesWithSuccess:(PostTypesHandler)success
[self.wordPressComRESTAPI get:requestUrl
parameters:parameters
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) {
return [self remotePostTypeWithDictionary:json];
Expand All @@ -166,7 +165,7 @@ - (void)syncPostFormatsWithSuccess:(PostFormatsHandler)success
NSString *path = [self pathForPostFormats];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:WordPressComRESTAPIVersion_1_1];

[self.wordPressComRESTAPI get:requestUrl
parameters:nil
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
Expand Down Expand Up @@ -208,7 +207,7 @@ - (void)syncBlogSettingsWithSuccess:(SettingsHandler)success
{
NSString *path = [self pathForSettings];
NSString *requestUrl = [self pathForEndpoint:path withVersion:WordPressComRESTAPIVersion_1_1];

[self.wordPressComRESTAPI get:requestUrl
parameters:nil
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
Expand Down Expand Up @@ -238,7 +237,7 @@ - (void)updateBlogSettings:(RemoteBlogSettings *)settings
NSDictionary *parameters = [self remoteSettingsToDictionary:settings];
NSString *path = [NSString stringWithFormat:@"sites/%@/settings?context=edit", self.siteID];
NSString *requestUrl = [self pathForEndpoint:path withVersion:WordPressComRESTAPIVersion_1_1];

[self.wordPressComRESTAPI post:requestUrl
parameters:parameters
success:^(NSDictionary *responseDict, NSHTTPURLResponse *httpResponse) {
Expand Down Expand Up @@ -376,10 +375,10 @@ - (RemotePostType *)remotePostTypeWithDictionary:(NSDictionary *)json
- (RemoteBlogSettings *)remoteBlogSettingFromJSONDictionary:(NSDictionary *)json
{
NSAssert([json isKindOfClass:[NSDictionary class]], @"Invalid Settings Kind");

RemoteBlogSettings *settings = [RemoteBlogSettings new];
NSDictionary *rawSettings = [json dictionaryForKey:RemoteBlogSettingsKey];

// General
settings.name = [json stringForKey:RemoteBlogNameKey];
settings.tagline = [json stringForKey:RemoteBlogTaglineKey];
Expand Down Expand Up @@ -480,10 +479,10 @@ - (NSDictionary *)remoteSettingsToDictionary:(RemoteBlogSettings *)settings
[parameters setValueIfNotNil:settings.commentsSortOrder forKey:RemoteBlogCommentsSortOrderKey];
[parameters setValueIfNotNil:settings.commentsThreadingEnabled forKey:RemoteBlogCommentsThreadingEnabledKey];
[parameters setValueIfNotNil:settings.commentsThreadingDepth forKey:RemoteBlogCommentsThreadingDepthKey];

[parameters setValueIfNotNil:settings.pingbackOutboundEnabled forKey:RemoteBlogCommentsPingbackOutboundKey];
[parameters setValueIfNotNil:settings.pingbackInboundEnabled forKey:RemoteBlogCommentsPingbackInboundKey];

[parameters setValueIfNotNil:settings.relatedPostsEnabled forKey:RemoteBlogRelatedPostsEnabledKey];
[parameters setValueIfNotNil:settings.relatedPostsShowHeadline forKey:RemoteBlogRelatedPostsShowHeadlineKey];
[parameters setValueIfNotNil:settings.relatedPostsShowThumbnails forKey:RemoteBlogRelatedPostsShowThumbnailsKey];
Expand All @@ -497,7 +496,7 @@ - (NSDictionary *)remoteSettingsToDictionary:(RemoteBlogSettings *)settings
[parameters setValueIfNotNil:settings.sharingCommentLikesEnabled forKey:RemoteBlogSharingCommentLikesEnabled];
[parameters setValueIfNotNil:settings.sharingDisabledLikes forKey:RemoteBlogSharingDisabledLikes];
[parameters setValueIfNotNil:settings.sharingDisabledReblogs forKey:RemoteBlogSharingDisabledReblogs];

return parameters;
}

Expand Down
Loading