Skip to content

Commit

Permalink
Delete RemotePostType
Browse files Browse the repository at this point in the history
  • Loading branch information
mokagio committed Jan 16, 2025
1 parent 96e515a commit 05510e9
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 153 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

@class RemoteBlog;
@class RemoteBlogSettings;
@class RemotePostType;
@class RemoteUser;

typedef void (^PostTypesHandler)(NSArray <RemotePostType *> *postTypes);
typedef void (^PostFormatsHandler)(NSDictionary *postFormats);
typedef void (^UsersHandler)(NSArray <RemoteUser *> *users);
typedef void (^MultiAuthorCheckHandler)(BOOL isMultiAuthor);
Expand All @@ -22,15 +20,6 @@ typedef void (^SuccessHandler)(void);
- (void)getAllAuthorsWithSuccess:(UsersHandler)success
failure:(void (^)(NSError *error))failure;

/**
* @brief Synchronizes a blog's post types.
*
* @param success The block that will be executed on success. Can be nil.
* @param failure The block that will be executed on failure. Can be nil.
*/
- (void)syncPostTypesWithSuccess:(PostTypesHandler)success
failure:(void (^)(NSError *error))failure;

/**
* @brief Synchronizes a blog's post formats.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#import <Foundation/Foundation.h>
#import "BlogServiceRemoteREST.h"
#import "NSMutableDictionary+Helpers.h"
#import "RemotePostType.h"
#import "WordPressAuthenticator-Swift.h"
@import NSObject_SafeExpectations;
@import WordPressShared;
Expand Down Expand Up @@ -53,11 +52,6 @@
static NSString * const RemoteBlogSharingDisabledLikes = @"disabled_likes";
static NSString * const RemoteBlogSharingDisabledReblogs = @"disabled_reblogs";

static NSString * const RemotePostTypesKey = @"post_types";
static NSString * const RemotePostTypeNameKey = @"name";
static NSString * const RemotePostTypeLabelKey = @"label";
static NSString * const RemotePostTypeQueryableKey = @"api_queryable";

#pragma mark - Keys used for Update Calls
// Note: Only god knows why these don't match the "Parsing Keys"
static NSString * const RemoteBlogNameForUpdateKey = @"blogname";
Expand Down Expand Up @@ -131,36 +125,6 @@ - (void)getAllAuthorsWithRemoteUsers:(NSMutableArray <RemoteUser *>*)remoteUsers
}];
}

- (void)syncPostTypesWithSuccess:(PostTypesHandler)success
failure:(void (^)(NSError *error))failure
{
NSString *path = [self pathForPostTypes];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:WordPressComRESTAPIVersion_1_1];
NSDictionary *parameters = @{@"context": @"edit"};
[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] wp_map:^id(NSDictionary *json) {
return [self remotePostTypeWithDictionary:json];
}];
if (!postTypes.count) {
WPAuthenticatorLogError(@"Response to %@ did not include post types for site.", requestUrl);
failure(nil);
return;
}
if (success) {
success(postTypes);
}
} failure:^(NSError *error, NSHTTPURLResponse *httpResponse) {
if (failure) {
failure(error);
}
}];
}

- (void)syncPostFormatsWithSuccess:(PostFormatsHandler)success
failure:(void (^)(NSError *))failure
{
Expand Down Expand Up @@ -365,15 +329,6 @@ - (NSDictionary *)mapPostFormatsFromResponse:(id)response
}
}

- (RemotePostType *)remotePostTypeWithDictionary:(NSDictionary *)json
{
RemotePostType *postType = [[RemotePostType alloc] init];
postType.name = [json stringForKey:RemotePostTypeNameKey];
postType.label = [json stringForKey:RemotePostTypeLabelKey];
postType.apiQueryable = [json numberForKey:RemotePostTypeQueryableKey];
return postType;
}

- (RemoteBlogSettings *)remoteBlogSettingFromJSONDictionary:(NSDictionary *)json
{
NSAssert([json isKindOfClass:[NSDictionary class]], @"Invalid Settings Kind");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#import "BlogServiceRemoteXMLRPC.h"
#import "NSMutableDictionary+Helpers.h"
#import "RemotePostType.h"
#import "WordPressAuthenticator-Swift.h"
@import NSObject_SafeExpectations;
@import WordPressShared;

static NSString * const RemotePostTypeNameKey = @"name";
static NSString * const RemotePostTypeLabelKey = @"label";
static NSString * const RemotePostTypePublicKey = @"public";

@implementation BlogServiceRemoteXMLRPC

- (void)getAllAuthorsWithSuccess:(UsersHandler)success
Expand Down Expand Up @@ -72,34 +67,6 @@ - (void)getAllAuthorsWithRemoteUsers:(NSMutableArray <RemoteUser *>*)remoteUsers
}];
}

- (void)syncPostTypesWithSuccess:(PostTypesHandler)success failure:(void (^)(NSError *error))failure
{
NSArray *parameters = [self defaultXMLRPCArguments];
[self.api callMethod:@"wp.getPostTypes"
parameters:parameters
success:^(id responseObject, NSHTTPURLResponse *response) {

NSAssert([responseObject isKindOfClass:[NSDictionary class]], @"Response should be a dictionary.");
NSArray <RemotePostType *> *postTypes = [[responseObject allObjects] wp_map:^id(NSDictionary *json) {
return [self remotePostTypeFromXMLRPCDictionary:json];
}];
if (!postTypes.count) {
WPAuthenticatorLogError(@"Response to wp.getPostTypes did not include post types for site.");
failure(nil);
return;
}
if (success) {
success(postTypes);
}
} failure:^(NSError *error, NSHTTPURLResponse *response) {
WPAuthenticatorLogError(@"Error syncing post types (%@): %@", response.URL, error);

if (failure) {
failure(error);
}
}];
}

- (void)syncPostFormatsWithSuccess:(PostFormatsHandler)success failure:(void (^)(NSError *))failure
{
NSDictionary *dict = @{@"show-supported": @"1"};
Expand Down Expand Up @@ -197,13 +164,4 @@ - (RemoteUser *)remoteUserFromXMLRPCDictionary:(NSDictionary *)xmlrpcUser
return user;
}

- (RemotePostType *)remotePostTypeFromXMLRPCDictionary:(NSDictionary *)json
{
RemotePostType *postType = [[RemotePostType alloc] init];
postType.name = [json stringForKey:RemotePostTypeNameKey];
postType.label = [json stringForKey:RemotePostTypeLabelKey];
postType.apiQueryable = [json numberForKey:RemotePostTypePublicKey];
return postType;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,6 @@
// failure:^(NSError *error) {}];
//}
//
//#pragma mark - Synchronizing post types for a blog
//
//- (void)testThatSyncPostTypesForBlogWorks
//{
// RemoteBlog *blog = OCMStrictClassMock([RemoteBlog class]);
// OCMStub([blog blogID]).andReturn(@10);
//
// WordPressComRestApi *api = OCMStrictClassMock([WordPressComRestApi class]);
// BlogServiceRemoteREST *service = nil;
//
// XCTAssertNoThrow(service = [[BlogServiceRemoteREST alloc] initWithWordPressComRestApi:api siteID:blog.blogID]);
//
// NSString *endpoint = [NSString stringWithFormat:@"sites/%@/post-types", blog.blogID];
// NSString *url = [service pathForEndpoint:endpoint
// withVersion:WordPressComRESTAPIVersion_1_1];
//
// NSDictionary *parameters = @{@"context": @"edit"};
// OCMStub([api get:[OCMArg isEqual:url]
// parameters:[OCMArg isEqual:parameters]
// success:[OCMArg isNotNil]
// failure:[OCMArg isNotNil]]);
//
// [service syncPostTypesWithSuccess:^(NSArray<RemotePostType *> *postTypes) {}
// failure:^(NSError *error) {}];
//}
//
//#pragma mark - Synchronizing post formats for a blog
//
//- (void)testThatSyncPostFormatsForBlogWorks
Expand Down

0 comments on commit 05510e9

Please sign in to comment.