Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 07d9070

Browse files
authored
Revert "Use the new appendURLString function in WordPressComRestApi" (#729)
2 parents cc29a13 + dce187d commit 07d9070

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

WordPressKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
4A6B4A862B269D0C00802316 /* URLSessionHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A6B4A852B269D0C00802316 /* URLSessionHelperTests.swift */; };
184184
4AA5A1A32AA68F6B00969464 /* MediaLibraryTestSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA5A1A22AA68F6B00969464 /* MediaLibraryTestSupport.swift */; };
185185
4AA5A1A52AA695D700969464 /* LoadMediaLibraryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA5A1A42AA695D700969464 /* LoadMediaLibraryTests.swift */; };
186+
4AB6A3652B83191600769115 /* ReaderPostServiceRemote+FetchEndpointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AB6A3642B83191600769115 /* ReaderPostServiceRemote+FetchEndpointTests.swift */; };
186187
4AE278442B2FAF6200E4D9B1 /* HTTPProtocolHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AE278432B2FAF6200E4D9B1 /* HTTPProtocolHelpers.swift */; };
187188
4AE278482B2FBF1100E4D9B1 /* HTTPBodyEncodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AE278472B2FBF1100E4D9B1 /* HTTPBodyEncodingTests.swift */; };
188189
4AE2784A2B2FC6C600E4D9B1 /* HTTPHeaderValueParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AE278492B2FC6C600E4D9B1 /* HTTPHeaderValueParserTests.swift */; };
@@ -903,6 +904,7 @@
903904
4A6B4A852B269D0C00802316 /* URLSessionHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionHelperTests.swift; sourceTree = "<group>"; };
904905
4AA5A1A22AA68F6B00969464 /* MediaLibraryTestSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaLibraryTestSupport.swift; sourceTree = "<group>"; };
905906
4AA5A1A42AA695D700969464 /* LoadMediaLibraryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadMediaLibraryTests.swift; sourceTree = "<group>"; };
907+
4AB6A3642B83191600769115 /* ReaderPostServiceRemote+FetchEndpointTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ReaderPostServiceRemote+FetchEndpointTests.swift"; sourceTree = "<group>"; };
906908
4AE278432B2FAF6200E4D9B1 /* HTTPProtocolHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPProtocolHelpers.swift; sourceTree = "<group>"; };
907909
4AE278472B2FBF1100E4D9B1 /* HTTPBodyEncodingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPBodyEncodingTests.swift; sourceTree = "<group>"; };
908910
4AE278492B2FC6C600E4D9B1 /* HTTPHeaderValueParserTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPHeaderValueParserTests.swift; sourceTree = "<group>"; };
@@ -1671,6 +1673,7 @@
16711673
FA87FE0624EB39C4003FBEE3 /* ReaderPostServiceRemote+SubscriptionTests.swift */,
16721674
3236F79924AE406D0088E8F3 /* ReaderTopicServiceRemote+InterestsTests.swift */,
16731675
8B16CE91252502C4007BE5A9 /* RemoteReaderPostTests+V2.swift */,
1676+
4AB6A3642B83191600769115 /* ReaderPostServiceRemote+FetchEndpointTests.swift */,
16741677
);
16751678
name = Reader;
16761679
sourceTree = "<group>";
@@ -3595,6 +3598,7 @@
35953598
740B23D31F17F6BB00067A2A /* PostServiceRemoteXMLRPCTests.swift in Sources */,
35963599
93188D221F2264E60028ED4D /* TaxonomyServiceRemoteRESTTests.m in Sources */,
35973600
F194E1232417ED9F00874408 /* AtomicAuthenticationServiceRemoteTests.swift in Sources */,
3601+
4AB6A3652B83191600769115 /* ReaderPostServiceRemote+FetchEndpointTests.swift in Sources */,
35983602
9817D9D426BC8AF000ECBD8C /* CommentServiceRemoteXMLRPCTests.swift in Sources */,
35993603
74FC6F3B1F191BB400112505 /* NotificationSyncServiceRemoteTests.swift in Sources */,
36003604
731BA83821DECD97000FDFCD /* SiteCreationResponseDecodingTests.swift in Sources */,

WordPressKit/WordPressComRestApi.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,11 @@ open class WordPressComRestApi: NSObject {
484484
}
485485

486486
private func requestBuilder(URLString: String) throws -> HTTPRequestBuilder {
487-
var builder = HTTPRequestBuilder(url: baseURL)
488-
.appendURLString(URLString)
487+
guard let url = URL(string: URLString, relativeTo: baseURL) else {
488+
throw URLError(.badURL)
489+
}
490+
491+
var builder = HTTPRequestBuilder(url: url)
489492

490493
if appendsPreferredLanguageLocale {
491494
let preferredLanguageIdentifier = WordPressComLanguageDatabase().deviceLanguage.slug
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Foundation
2+
import XCTest
3+
import OHHTTPStubs
4+
5+
@testable import WordPressKit
6+
7+
class ReaderPostServiceRemoteFetchEndpointTests: XCTestCase {
8+
9+
override func tearDown() {
10+
super.tearDown()
11+
12+
HTTPStubs.removeAllStubs()
13+
}
14+
15+
func testEndpointIsFullURL() throws {
16+
var request: URLRequest?
17+
stub(condition: { _ in true }) {
18+
request = $0
19+
return HTTPStubsResponse(error: URLError(.networkConnectionLost))
20+
}
21+
22+
let complete = expectation(description: "API call completes")
23+
let service = ReaderPostServiceRemote(wordPressComRestApi: WordPressComRestApi())
24+
let endpoint = URL(string: "https://public-api.wordpress.com/rest/v1.2/read/liked")!
25+
service.fetchPosts(
26+
fromEndpoint: endpoint,
27+
algorithm: "none",
28+
count: 1,
29+
before: Date(),
30+
success: { _,_ in complete.fulfill() },
31+
failure: { _ in complete.fulfill() }
32+
)
33+
wait(for: [complete], timeout: 0.3)
34+
35+
var url = try XCTUnwrap(URLComponents(url: XCTUnwrap(request?.url), resolvingAgainstBaseURL: true))
36+
url.query = nil
37+
XCTAssertEqual(url.url?.absoluteString, "https://public-api.wordpress.com/rest/v1.2/read/liked")
38+
}
39+
40+
}

0 commit comments

Comments
 (0)