Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ let package = Package(
targets: [
.binaryTarget(
name: "WordPressKit",
url: "https://github.com/user-attachments/files/19315257/WordPressKit.zip",
checksum: "1b4ba5cef01a64e98ffdc02a5c8ac92f550f234222bfb6abf11b4b4df94435bc"
url: "https://github.com/user-attachments/files/19339848/WordPressKit.zip",
checksum: "5bf1ff361992dccf44dfe41b0a442ee4c3c13dc0a1ce9b647a8ed1b976b5c3fc"
),
]
)
2 changes: 2 additions & 0 deletions Sources/WordPressKit/Services/ThemeServiceRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ typedef void(^ThemeServiceRemoteFailureBlock)(NSError *error);
* @details Includes premium themes even if not purchased. Don't call this method if the list
* you want to retrieve is for a specific blog. Use getThemesForBlogId instead.
*
* @param search Search term for filtering themes. Cannot be nil.
* @param freeOnly Only fetch free themes, if false all WP themes will be returned
* @param page Results page to return.
* @param success The success handler. Can be nil.
Expand All @@ -66,6 +67,7 @@ typedef void(^ThemeServiceRemoteFailureBlock)(NSError *error);
* @returns A progress object that can be used to track progress and/or cancel the task
*/
- (NSProgress *)getWPThemesPage:(NSInteger)page
search:(NSString *)search
freeOnly:(BOOL)freeOnly
success:(ThemeServiceRemoteThemesRequestSuccessBlock)success
failure:(ThemeServiceRemoteFailureBlock)failure;
Expand Down
29 changes: 18 additions & 11 deletions Sources/WordPressKit/Services/ThemeServiceRemote.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
static NSString* const ThemeRequestNumberKey = @"number";
static NSInteger const ThemeRequestNumberValue = 50;
static NSString* const ThemeRequestPageKey = @"page";
static NSString* const ThemeRequestSearchKey = @"search";

@implementation ThemeServiceRemote

Expand Down Expand Up @@ -98,20 +99,26 @@ - (NSProgress *)getThemeId:(NSString*)themeId
}

- (NSProgress *)getWPThemesPage:(NSInteger)page
search:(NSString *)search
freeOnly:(BOOL)freeOnly
success:(ThemeServiceRemoteThemesRequestSuccessBlock)success
failure:(ThemeServiceRemoteFailureBlock)failure
{
NSParameterAssert(page > 0);

NSString *requestUrl = [self pathForEndpoint:@"themes"
withVersion:WordPressComRESTAPIVersion_1_2];

NSDictionary *parameters = @{ThemeRequestTierKey: freeOnly ? ThemeRequestTierFreeValue : ThemeRequestTierAllValue,
ThemeRequestNumberKey: @(ThemeRequestNumberValue),
ThemeRequestPageKey: @(page),
};

withVersion:WordPressComRESTAPIVersion_2_0];

NSMutableDictionary *parameters = [@{
ThemeRequestTierKey: freeOnly ? ThemeRequestTierFreeValue : ThemeRequestTierAllValue,
ThemeRequestNumberKey: @(ThemeRequestNumberValue),
ThemeRequestPageKey: @(page)
} mutableCopy];

if (search) {
parameters[ThemeRequestSearchKey] = search;
}

return [self getThemesWithRequestUrl:requestUrl
page:page
parameters:parameters
Expand Down Expand Up @@ -143,9 +150,9 @@ - (NSProgress *)getThemesPage:(NSInteger)page
}

- (NSProgress *)getThemesForBlogId:(NSNumber *)blogId
page:(NSInteger)page
success:(ThemeServiceRemoteThemesRequestSuccessBlock)success
failure:(ThemeServiceRemoteFailureBlock)failure
page:(NSInteger)page
success:(ThemeServiceRemoteThemesRequestSuccessBlock)success
failure:(ThemeServiceRemoteFailureBlock)failure
{
NSParameterAssert([blogId isKindOfClass:[NSNumber class]]);
NSParameterAssert(page > 0);
Expand Down
15 changes: 8 additions & 7 deletions Tests/WordPressKitTests/Tests/ThemeServiceRemoteTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ - (void)testThatGetThemesWorks
XCTAssertNoThrow(service = [[ThemeServiceRemote alloc] initWithWordPressComRestApi:api]);

NSString *url = [service pathForEndpoint:@"themes"
withVersion:WordPressComRESTAPIVersion_1_2];
withVersion:WordPressComRESTAPIVersion_2_0];

ThemeServiceRemoteThemesRequestSuccessBlock successBlock = ^void (NSArray<RemoteTheme *> *themes, BOOL hasMore, NSInteger totalThemeCount) {
NSCAssert([themes count] == expectedThemes, @"Expected %ld themes to be returned", expectedThemes);
Expand Down Expand Up @@ -224,9 +224,10 @@ - (void)testThatGetThemesWorks
}];

XCTAssertNoThrow([service getWPThemesPage:1
freeOnly:NO
success:successBlock
failure:nil]);
search:nil
freeOnly:NO
success:successBlock
failure:nil]);
}

- (void)testThatGetThemesForBlogIdWorks
Expand Down Expand Up @@ -268,9 +269,9 @@ - (void)testThatGetThemesForBlogIdWorks
}];

XCTAssertNoThrow([service getThemesForBlogId:blogId
page:1
success:successBlock
failure:nil]);
page:1
success:successBlock
failure:nil]);
}

- (void)testThatGetThemesForBlogIdThrowsExceptionWithoutBlogId
Expand Down