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

Commit f7aa1f9

Browse files
authored
Merge pull request #600 from wordpress-mobile/task/update-external-services-endpoint
Add wpcom/v2 external services endpoint
2 parents c323bc9 + 0b40210 commit f7aa1f9

File tree

7 files changed

+240
-207
lines changed

7 files changed

+240
-207
lines changed

WordPressKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pod::Spec.new do |s|
44
s.name = 'WordPressKit'
5-
s.version = '8.1.0'
5+
s.version = '8.2.0-beta.1'
66

77
s.summary = 'WordPressKit offers a clean and simple WordPress.com and WordPress.org API.'
88
s.description = <<-DESC

WordPressKit.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@
318318
74DA563A1F06EB3000FE9BF4 /* RemoteMedia.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DA56381F06EB3000FE9BF4 /* RemoteMedia.h */; settings = {ATTRIBUTES = (Public, ); }; };
319319
74DA563B1F06EB3000FE9BF4 /* RemoteMedia.m in Sources */ = {isa = PBXBuildFile; fileRef = 74DA56391F06EB3000FE9BF4 /* RemoteMedia.m */; };
320320
74E229491F1E73060085F7F2 /* SharingServiceRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74E229481F1E73060085F7F2 /* SharingServiceRemote.swift */; };
321-
74E2294B1F1E73340085F7F2 /* SharingServiceRemoteTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 74E2294A1F1E73340085F7F2 /* SharingServiceRemoteTests.m */; };
322321
74E2294E1F1E73FE0085F7F2 /* RemotePublicizeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74E2294D1F1E73FE0085F7F2 /* RemotePublicizeService.swift */; };
323322
74E229501F1E741B0085F7F2 /* RemotePublicizeConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74E2294F1F1E741B0085F7F2 /* RemotePublicizeConnection.swift */; };
324323
74E2295B1F1E77290085F7F2 /* KeyringConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74E229591F1E77290085F7F2 /* KeyringConnection.swift */; };
@@ -623,6 +622,8 @@
623622
FE20A6A6282BC68D0025E975 /* blogging-prompts-settings-fetch-success.json in Resources */ = {isa = PBXBuildFile; fileRef = FE20A6A5282BC68D0025E975 /* blogging-prompts-settings-fetch-success.json */; };
624623
FE20A6A8282BC83A0025E975 /* blogging-prompts-settings-update-with-response.json in Resources */ = {isa = PBXBuildFile; fileRef = FE20A6A7282BC83A0025E975 /* blogging-prompts-settings-update-with-response.json */; };
625624
FE20A6AA282BC8710025E975 /* blogging-prompts-settings-update-empty-response.json in Resources */ = {isa = PBXBuildFile; fileRef = FE20A6A9282BC8710025E975 /* blogging-prompts-settings-update-empty-response.json */; };
625+
FE5096522A13938500DDD071 /* SharingServiceRemoteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE5096512A13938500DDD071 /* SharingServiceRemoteTests.swift */; };
626+
FE5096562A13B7F200DDD071 /* sites-external-services.json in Resources */ = {isa = PBXBuildFile; fileRef = FE5096552A13B7F200DDD071 /* sites-external-services.json */; };
626627
FEAE3AC7298AC2A300E05A24 /* JetpackProxyServiceRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEAE3AC6298AC2A300E05A24 /* JetpackProxyServiceRemote.swift */; };
627628
FEB7A88F271873BD00A8CF85 /* reader-post-comments-update-notification-success.json in Resources */ = {isa = PBXBuildFile; fileRef = FEB7A88E271873BD00A8CF85 /* reader-post-comments-update-notification-success.json */; };
628629
FED77253298B819900C2346E /* JetpackProxyServiceRemoteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FED77252298B819900C2346E /* JetpackProxyServiceRemoteTests.swift */; };
@@ -986,7 +987,6 @@
986987
74DA56381F06EB3000FE9BF4 /* RemoteMedia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteMedia.h; sourceTree = "<group>"; };
987988
74DA56391F06EB3000FE9BF4 /* RemoteMedia.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RemoteMedia.m; sourceTree = "<group>"; };
988989
74E229481F1E73060085F7F2 /* SharingServiceRemote.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SharingServiceRemote.swift; sourceTree = "<group>"; };
989-
74E2294A1F1E73340085F7F2 /* SharingServiceRemoteTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SharingServiceRemoteTests.m; sourceTree = "<group>"; };
990990
74E2294D1F1E73FE0085F7F2 /* RemotePublicizeService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemotePublicizeService.swift; sourceTree = "<group>"; };
991991
74E2294F1F1E741B0085F7F2 /* RemotePublicizeConnection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemotePublicizeConnection.swift; sourceTree = "<group>"; };
992992
74E229591F1E77290085F7F2 /* KeyringConnection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyringConnection.swift; sourceTree = "<group>"; };
@@ -1300,6 +1300,8 @@
13001300
FE20A6A5282BC68D0025E975 /* blogging-prompts-settings-fetch-success.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "blogging-prompts-settings-fetch-success.json"; sourceTree = "<group>"; };
13011301
FE20A6A7282BC83A0025E975 /* blogging-prompts-settings-update-with-response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "blogging-prompts-settings-update-with-response.json"; sourceTree = "<group>"; };
13021302
FE20A6A9282BC8710025E975 /* blogging-prompts-settings-update-empty-response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "blogging-prompts-settings-update-empty-response.json"; sourceTree = "<group>"; };
1303+
FE5096512A13938500DDD071 /* SharingServiceRemoteTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharingServiceRemoteTests.swift; sourceTree = "<group>"; };
1304+
FE5096552A13B7F200DDD071 /* sites-external-services.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "sites-external-services.json"; sourceTree = "<group>"; };
13031305
FEAE3AC6298AC2A300E05A24 /* JetpackProxyServiceRemote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackProxyServiceRemote.swift; sourceTree = "<group>"; };
13041306
FEB7A88E271873BD00A8CF85 /* reader-post-comments-update-notification-success.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "reader-post-comments-update-notification-success.json"; sourceTree = "<group>"; };
13051307
FED77252298B819900C2346E /* JetpackProxyServiceRemoteTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackProxyServiceRemoteTests.swift; sourceTree = "<group>"; };
@@ -1608,7 +1610,7 @@
16081610
74E2294C1F1E73650085F7F2 /* Sharing */ = {
16091611
isa = PBXGroup;
16101612
children = (
1611-
74E2294A1F1E73340085F7F2 /* SharingServiceRemoteTests.m */,
1613+
FE5096512A13938500DDD071 /* SharingServiceRemoteTests.swift */,
16121614
FEFFD99A26C1598F00F34231 /* ShareAppContentServiceRemoteTests.swift */,
16131615
);
16141616
name = Sharing;
@@ -2209,6 +2211,7 @@
22092211
74C473C21EF32DD7009918F2 /* site-export-failure.json */,
22102212
74C473C01EF32C74009918F2 /* site-export-missing-status-failure.json */,
22112213
74C473BA1EF328D8009918F2 /* site-export-success.json */,
2214+
FE5096552A13B7F200DDD071 /* sites-external-services.json */,
22122215
74D67F221F15C3740010C5ED /* site-followers-delete-auth-failure.json */,
22132216
74D67F231F15C3740010C5ED /* site-followers-delete-bad-json-failure.json */,
22142217
74D67F241F15C3740010C5ED /* site-followers-delete-failure.json */,
@@ -2970,6 +2973,7 @@
29702973
7403A2FA1EF06FEB00DED7DC /* me-settings-change-firstname-success.json in Resources */,
29712974
74D67F321F15C3740010C5ED /* site-followers-delete-success.json in Resources */,
29722975
93F50A481F227F3600B5BEBA /* xmlrpc-response-valid-but-unexpected-dictionary.xml in Resources */,
2976+
FE5096562A13B7F200DDD071 /* sites-external-services.json in Resources */,
29732977
93BD27601EE73442002BB00B /* me-sites-bad-json-failure.json in Resources */,
29742978
17BF9A7320C7E18200BF57D2 /* reader-site-search-failure.json in Resources */,
29752979
FFE247B120C891E6002DF3A2 /* WordPressComSocial2FACodeSuccess.json in Resources */,
@@ -3323,7 +3327,6 @@
33233327
FED77253298B819900C2346E /* JetpackProxyServiceRemoteTests.swift in Sources */,
33243328
ABD95B7F25DD6C4B00735BEE /* CommentServiceRemoteRESTLikesTests.swift in Sources */,
33253329
8B749E8225AF7DDA00023F03 /* JetpackCapabilitiesServiceRemoteTests.swift in Sources */,
3326-
74E2294B1F1E73340085F7F2 /* SharingServiceRemoteTests.m in Sources */,
33273330
FEFFD99B26C1598F00F34231 /* ShareAppContentServiceRemoteTests.swift in Sources */,
33283331
FEEFD8B7280EC91B00A3E261 /* BloggingPromptsServiceRemoteTests.swift in Sources */,
33293332
73B3DAD621FBB20D00B2CF18 /* WordPressComRestApiTests+Locale.swift in Sources */,
@@ -3371,6 +3374,7 @@
33713374
17CE77F420C701C8001DEA5A /* ReaderSiteSearchServiceRemoteTests.swift in Sources */,
33723375
73A2F38D21E7FC8200388609 /* WordPressComServiceRemoteTests+SiteVerticalsPrompt.swift in Sources */,
33733376
74C473AF1EF2F7D1009918F2 /* SiteManagementServiceRemoteTests.swift in Sources */,
3377+
FE5096522A13938500DDD071 /* SharingServiceRemoteTests.swift in Sources */,
33743378
FFA4D4AA2423B10A00BF5180 /* WordPressOrgRestApiTests.swift in Sources */,
33753379
74A44DD51F13C6D8006CD8F4 /* PushAuthenticationServiceRemoteTests.swift in Sources */,
33763380
731BA83621DECD61000FDFCD /* SiteCreationRequestEncodingTests.swift in Sources */,

WordPressKit/RemotePublicizeService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ import Foundation
1212
@objc open var order: NSNumber = 0
1313
@objc open var serviceID = ""
1414
@objc open var type = ""
15+
@objc open var status = ""
1516
}

WordPressKit/SharingServiceRemote.swift

Lines changed: 63 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,50 +44,45 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST {
4444
let path = self.path(forEndpoint: endpoint, withVersion: ._1_1)
4545
let params = ["type": "publicize"]
4646

47-
wordPressComRestApi.GET(path,
48-
parameters: params as [String: AnyObject]?,
49-
success: { (responseObject: AnyObject, httpResponse: HTTPURLResponse?) in
50-
guard let onSuccess = success else {
51-
return
52-
}
47+
wordPressComRestApi.GET(path, parameters: params as [String: AnyObject]?) { responseObject, httpResponse in
48+
guard let responseDict = responseObject as? NSDictionary else {
49+
failure?(self.errorForUnexpectedResponse(httpResponse))
50+
return
51+
}
5352

54-
guard let responseDict = responseObject as? NSDictionary else {
53+
success?(self.remotePublicizeServicesFromDictionary(responseDict))
54+
55+
} failure: { error, _ in
56+
failure?(error)
57+
}
58+
}
59+
60+
/// Fetches the list of Publicize services for a specified siteID.
61+
///
62+
/// - Parameters:
63+
/// - siteID: The WordPress.com ID of the site.
64+
/// - success: An optional success block accepting an array of `RemotePublicizeService` objects.
65+
/// - failure: An optional failure block accepting an `NSError` argument.
66+
@objc open func getPublicizeServices(for siteID: NSNumber,
67+
success: (([RemotePublicizeService]) -> Void)?,
68+
failure: ((NSError?) -> Void)?) {
69+
let path = path(forEndpoint: "sites/\(siteID)/external-services", withVersion: ._2_0)
70+
let params = ["type": "publicize" as AnyObject]
71+
72+
wordPressComRestApi.GET(path, parameters: params) { result, httpResponse in
73+
switch result {
74+
case .success(let response):
75+
guard let responseDict = response as? NSDictionary else {
5576
failure?(self.errorForUnexpectedResponse(httpResponse))
5677
return
5778
}
5879

59-
let responseString = responseObject.description as NSString
60-
let services: NSDictionary = (responseDict.forKey(ServiceDictionaryKeys.services) as? NSDictionary) ?? NSDictionary()
61-
62-
let publicizeServices: [RemotePublicizeService] = services.allKeys.map { (key) -> RemotePublicizeService in
63-
let dict = (services.forKey(key) as? NSDictionary) ?? NSDictionary()
64-
let pub = RemotePublicizeService()
65-
66-
pub.connectURL = dict.string(forKey: ServiceDictionaryKeys.connectURL) ?? ""
67-
pub.detail = dict.string(forKey: ServiceDictionaryKeys.description) ?? ""
68-
pub.externalUsersOnly = dict.number(forKey: ServiceDictionaryKeys.externalUsersOnly)?.boolValue ?? false
69-
pub.icon = dict.string(forKey: ServiceDictionaryKeys.icon) ?? ""
70-
pub.serviceID = dict.string(forKey: ServiceDictionaryKeys.ID) ?? ""
71-
pub.jetpackModuleRequired = dict.string(forKey: ServiceDictionaryKeys.jetpackModuleRequired) ?? ""
72-
pub.jetpackSupport = dict.number(forKey: ServiceDictionaryKeys.jetpackSupport)?.boolValue ?? false
73-
pub.label = dict.string(forKey: ServiceDictionaryKeys.label) ?? ""
74-
pub.multipleExternalUserIDSupport = dict.number(forKey: ServiceDictionaryKeys.multipleExternalUserIDSupport)?.boolValue ?? false
75-
pub.type = dict.string(forKey: ServiceDictionaryKeys.type) ?? ""
76-
77-
// We're not guarenteed to get the right order by inspecting the
78-
// response dictionary's keys. Instead, we can check the index
79-
// of each service in the response string.
80-
pub.order = NSNumber(value: responseString.range(of: pub.serviceID).location)
81-
82-
return pub
83-
}
84-
85-
onSuccess(publicizeServices)
80+
success?(self.remotePublicizeServicesFromDictionary(responseDict))
8681

87-
},
88-
failure: { (error: NSError, _: HTTPURLResponse?) in
89-
failure?(error)
90-
})
82+
case .failure(let error):
83+
failure?(error as NSError)
84+
}
85+
}
9186
}
9287

9388
/// Fetches the current user's list of keyring connections.
@@ -512,6 +507,35 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST {
512507
return dict
513508
})
514509
}
510+
511+
private func remotePublicizeServicesFromDictionary(_ dictionary: NSDictionary) -> [RemotePublicizeService] {
512+
let responseString = dictionary.description as NSString
513+
let services: NSDictionary = (dictionary.forKey(ServiceDictionaryKeys.services) as? NSDictionary) ?? NSDictionary()
514+
515+
return services.allKeys.map { key in
516+
let dict = (services.forKey(key) as? NSDictionary) ?? NSDictionary()
517+
let pub = RemotePublicizeService()
518+
519+
pub.connectURL = dict.string(forKey: ServiceDictionaryKeys.connectURL) ?? ""
520+
pub.detail = dict.string(forKey: ServiceDictionaryKeys.description) ?? ""
521+
pub.externalUsersOnly = dict.number(forKey: ServiceDictionaryKeys.externalUsersOnly)?.boolValue ?? false
522+
pub.icon = dict.string(forKey: ServiceDictionaryKeys.icon) ?? ""
523+
pub.serviceID = dict.string(forKey: ServiceDictionaryKeys.ID) ?? ""
524+
pub.jetpackModuleRequired = dict.string(forKey: ServiceDictionaryKeys.jetpackModuleRequired) ?? ""
525+
pub.jetpackSupport = dict.number(forKey: ServiceDictionaryKeys.jetpackSupport)?.boolValue ?? false
526+
pub.label = dict.string(forKey: ServiceDictionaryKeys.label) ?? ""
527+
pub.multipleExternalUserIDSupport = dict.number(forKey: ServiceDictionaryKeys.multipleExternalUserIDSupport)?.boolValue ?? false
528+
pub.type = dict.string(forKey: ServiceDictionaryKeys.type) ?? ""
529+
pub.status = dict.string(forKey: ServiceDictionaryKeys.status) ?? ""
530+
531+
// We're not guarenteed to get the right order by inspecting the
532+
// response dictionary's keys. Instead, we can check the index
533+
// of each service in the response string.
534+
pub.order = NSNumber(value: responseString.range(of: pub.serviceID).location)
535+
536+
return pub
537+
}
538+
}
515539
}
516540

517541
// Keys for PublicizeService dictionaries
@@ -527,6 +551,7 @@ private struct ServiceDictionaryKeys {
527551
static let multipleExternalUserIDSupport = "multiple_external_user_ID_support"
528552
static let services = "services"
529553
static let type = "type"
554+
static let status = "status"
530555
}
531556

532557
// Keys for both KeyringConnection and PublicizeConnection dictionaries
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"services": {
3+
"facebook": {
4+
"ID": "facebook",
5+
"label": "Facebook",
6+
"type": "publicize",
7+
"description": "Publish your posts to your Facebook timeline or page.",
8+
"genericon": {
9+
"class": "facebook-alt",
10+
"unicode": "\\f203"
11+
},
12+
"icon": "http:\/\/i.wordpress.com\/wp-content\/admin-plugins\/publicize\/assets\/publicize-fb-2x.png",
13+
"connect_URL": "https:\/\/public-api.wordpress.com\/connect\/?action=request&kr_nonce=9b9bc62d36&nonce=a14cc808a1&for=connect&service=facebook&blog=193189927&kr_blog_nonce=e12bbe845e&magic=keyring",
14+
"multiple_external_user_ID_support": true,
15+
"external_users_only": true,
16+
"jetpack_support": true,
17+
"jetpack_module_required": "publicize"
18+
},
19+
"twitter": {
20+
"ID": "twitter",
21+
"label": "Twitter",
22+
"type": "publicize",
23+
"description": "Publish your posts to your Twitter account.",
24+
"genericon": {
25+
"class": "twitter",
26+
"unicode": "\\f202"
27+
},
28+
"icon": "http:\/\/i.wordpress.com\/wp-content\/admin-plugins\/publicize\/assets\/publicize-twitter-2x.png",
29+
"connect_URL": "https:\/\/public-api.wordpress.com\/connect\/?action=request&kr_nonce=9b9bc62d36&nonce=7aa41a23e8&for=connect&service=twitter&blog=193189927&kr_blog_nonce=e12bbe845e&magic=keyring",
30+
"multiple_external_user_ID_support": false,
31+
"external_users_only": false,
32+
"jetpack_support": true,
33+
"jetpack_module_required": "publicize",
34+
"status": "unsupported"
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)