Add Inoreader AppID and Key compatibility

This commit is contained in:
Maurice Parker 2020-10-24 21:25:00 -05:00
parent ecbd7d2f55
commit 8af61ea6ad
4 changed files with 49 additions and 23 deletions

View File

@ -90,7 +90,8 @@ final class ReaderAPICaller: NSObject {
return
}
let request = URLRequest(url: endpoint.appendingPathComponent(ReaderAPIEndpoints.login.rawValue), credentials: credentials)
var request = URLRequest(url: endpoint.appendingPathComponent(ReaderAPIEndpoints.login.rawValue), credentials: credentials)
addVariantHeaders(&request)
transport.send(request: request) { result in
switch result {
@ -141,7 +142,8 @@ final class ReaderAPICaller: NSObject {
return
}
let request = URLRequest(url: endpoint.appendingPathComponent(ReaderAPIEndpoints.token.rawValue), credentials: credentials)
var request = URLRequest(url: endpoint.appendingPathComponent(ReaderAPIEndpoints.token.rawValue), credentials: credentials)
addVariantHeaders(&request)
transport.send(request: request) { result in
switch result {
@ -182,8 +184,9 @@ final class ReaderAPICaller: NSObject {
}
let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.tags]
let request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
var request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
addVariantHeaders(&request)
transport.send(request: request, resultType: ReaderAPITagContainer.self) { result in
switch result {
@ -208,7 +211,7 @@ final class ReaderAPICaller: NSObject {
switch result {
case .success(let token):
var request = URLRequest(url: baseURL.appendingPathComponent(ReaderAPIEndpoints.renameTag.rawValue), credentials: self.credentials)
self.addVariantHeaders(&request)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
@ -245,8 +248,7 @@ final class ReaderAPICaller: NSObject {
switch result {
case .success(let token):
var request = URLRequest(url: baseURL.appendingPathComponent(ReaderAPIEndpoints.disableTag.rawValue), credentials: self.credentials)
self.addVariantHeaders(&request)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
@ -288,8 +290,9 @@ final class ReaderAPICaller: NSObject {
}
let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.subscriptions]
let request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
var request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
addVariantHeaders(&request)
transport.send(request: request, resultType: ReaderAPISubscriptionContainer.self) { result in
switch result {
@ -332,6 +335,7 @@ final class ReaderAPICaller: NSObject {
let callURL = baseURL.appendingPathComponent(ReaderAPIEndpoints.subscriptionEdit.rawValue)
var request = URLRequest(url: callURL, credentials: self.credentials)
self.addVariantHeaders(&request)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
@ -393,6 +397,7 @@ final class ReaderAPICaller: NSObject {
switch result {
case .success(let token):
var request = URLRequest(url: baseURL.appendingPathComponent(ReaderAPIEndpoints.subscriptionEdit.rawValue), credentials: self.credentials)
self.addVariantHeaders(&request)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
@ -426,6 +431,7 @@ final class ReaderAPICaller: NSObject {
switch result {
case .success(let token):
var request = URLRequest(url: baseURL.appendingPathComponent(ReaderAPIEndpoints.subscriptionEdit.rawValue), credentials: self.credentials)
self.addVariantHeaders(&request)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
@ -459,6 +465,7 @@ final class ReaderAPICaller: NSObject {
switch result {
case .success(let token):
var request = URLRequest(url: baseURL.appendingPathComponent(ReaderAPIEndpoints.subscriptionEdit.rawValue), credentials: self.credentials)
self.addVariantHeaders(&request)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
@ -493,6 +500,7 @@ final class ReaderAPICaller: NSObject {
switch result {
case .success(let token):
var request = URLRequest(url: baseURL.appendingPathComponent(ReaderAPIEndpoints.subscriptionEdit.rawValue), credentials: self.credentials)
self.addVariantHeaders(&request)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
@ -533,6 +541,7 @@ final class ReaderAPICaller: NSObject {
case .success(let token):
// Do POST asking for data about all the new articles
var request = URLRequest(url: baseURL.appendingPathComponent(ReaderAPIEndpoints.contents.rawValue), credentials: self.credentials)
self.addVariantHeaders(&request)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
@ -587,8 +596,9 @@ final class ReaderAPICaller: NSObject {
return
}
let request = URLRequest(url: callURL, credentials: credentials, conditionalGet: nil)
var request = URLRequest(url: callURL, credentials: credentials, conditionalGet: nil)
addVariantHeaders(&request)
transport.send(request: request, resultType: ReaderAPIReferenceWrapper.self) { result in
switch result {
@ -654,8 +664,9 @@ final class ReaderAPICaller: NSObject {
}
let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.unreadEntries]
let request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
var request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
addVariantHeaders(&request)
self.transport.send(request: request, resultType: ReaderAPIReferenceWrapper.self) { result in
switch result {
@ -676,6 +687,7 @@ final class ReaderAPICaller: NSObject {
case .success(let token):
// Do POST asking for data about all the new articles
var request = URLRequest(url: baseURL.appendingPathComponent(ReaderAPIEndpoints.contents.rawValue), credentials: self.credentials)
self.addVariantHeaders(&request)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
@ -730,7 +742,8 @@ final class ReaderAPICaller: NSObject {
completion(.success((nil, nil)))
return
}
let request = URLRequest(url: url, credentials: credentials)
var request = URLRequest(url: url, credentials: credentials)
addVariantHeaders(&request)
transport.send(request: request, resultType: [ReaderAPIEntry].self) { result in
@ -771,8 +784,9 @@ final class ReaderAPICaller: NSObject {
}
let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.unreadEntries]
let request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
var request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
addVariantHeaders(&request)
transport.send(request: request, resultType: ReaderAPIReferenceWrapper.self) { result in
switch result {
@ -806,6 +820,7 @@ final class ReaderAPICaller: NSObject {
case .success(let token):
// Do POST asking for data about all the new articles
var request = URLRequest(url: baseURL.appendingPathComponent(ReaderAPIEndpoints.editTag.rawValue), credentials: self.credentials)
self.addVariantHeaders(&request)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
@ -873,8 +888,9 @@ final class ReaderAPICaller: NSObject {
}
let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.starredEntries]
let request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
var request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
addVariantHeaders(&request)
transport.send(request: request, resultType: ReaderAPIReferenceWrapper.self) { result in
switch result {
@ -901,7 +917,7 @@ final class ReaderAPICaller: NSObject {
// MARK: Private
extension ReaderAPICaller {
private extension ReaderAPICaller {
func storeConditionalGet(key: String, headers: [AnyHashable : Any]) {
if var conditionalGet = accountMetadata?.conditionalGetInfo {
@ -909,4 +925,12 @@ extension ReaderAPICaller {
accountMetadata?.conditionalGetInfo = conditionalGet
}
}
func addVariantHeaders(_ request: inout URLRequest) {
if variant == .inoreader {
request.addValue(SecretsManager.provider.inoreaderAppId, forHTTPHeaderField: "AppId")
request.addValue(SecretsManager.provider.inoreaderAppKey, forHTTPHeaderField: "AppKey")
}
}
}

View File

@ -1817,7 +1817,7 @@
65C2E40024B05D8A000AFDF6 /* FeedsSettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedsSettingsModel.swift; sourceTree = "<group>"; };
65CBAD5924AE03C20006DD91 /* ColorPaletteContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPaletteContainerView.swift; sourceTree = "<group>"; };
65ED4083235DEF6C0081F399 /* NetNewsWire.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetNewsWire.app; sourceTree = BUILT_PRODUCTS_DIR; };
65ED409D235DEF770081F399 /* Subscribe to Feed.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; name = "Subscribe to Feed.appex"; path = "Subscribe to Feed MAS.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
65ED409D235DEF770081F399 /* Subscribe to Feed MAS.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Subscribe to Feed MAS.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
65ED409F235DEFF00081F399 /* container-migration.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "container-migration.plist"; sourceTree = "<group>"; };
65ED40F2235DF5E00081F399 /* NetNewsWire_macapp_target_macappstore.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = NetNewsWire_macapp_target_macappstore.xcconfig; sourceTree = "<group>"; };
65ED4186235E045B0081F399 /* NetNewsWire_safariextension_target_macappstore.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = NetNewsWire_safariextension_target_macappstore.xcconfig; sourceTree = "<group>"; };
@ -3221,7 +3221,7 @@
518B2ED22351B3DD00400001 /* NetNewsWire-iOSTests.xctest */,
51314637235A7BBE00387FDC /* NetNewsWire iOS Intents Extension.appex */,
65ED4083235DEF6C0081F399 /* NetNewsWire.app */,
65ED409D235DEF770081F399 /* Subscribe to Feed.appex */,
65ED409D235DEF770081F399 /* Subscribe to Feed MAS.appex */,
51C0513D24A77DF800194D5E /* NetNewsWire.app */,
51C0514424A77DF800194D5E /* NetNewsWire.app */,
510C415C24E5CDE3008226FD /* NetNewsWire Share Extension.appex */,
@ -3755,7 +3755,7 @@
);
name = "Subscribe to Feed MAS";
productName = "Subscribe to Feed";
productReference = 65ED409D235DEF770081F399 /* Subscribe to Feed.appex */;
productReference = 65ED409D235DEF770081F399 /* Subscribe to Feed MAS.appex */;
productType = "com.apple.product-type.app-extension";
};
840D617B2029031C009BC708 /* NetNewsWire-iOS */ = {

View File

@ -16,4 +16,6 @@ public protocol SecretsProvider {
var twitterConsumerKey: String { get }
var twitterConsumerSecret: String { get }
var redditConsumerKey: String { get }
var inoreaderAppId: String { get }
var inoreaderAppKey: String { get }
}

View File

@ -2,7 +2,7 @@
%{
import os
secrets = ['FEED_WRANGLER_KEY', 'MERCURY_CLIENT_ID', 'MERCURY_CLIENT_SECRET', 'FEEDLY_CLIENT_ID', 'FEEDLY_CLIENT_SECRET', 'TWITTER_CONSUMER_KEY', 'TWITTER_CONSUMER_SECRET', 'REDDIT_CONSUMER_KEY']
secrets = ['FEED_WRANGLER_KEY', 'MERCURY_CLIENT_ID', 'MERCURY_CLIENT_SECRET', 'FEEDLY_CLIENT_ID', 'FEEDLY_CLIENT_SECRET', 'TWITTER_CONSUMER_KEY', 'TWITTER_CONSUMER_SECRET', 'REDDIT_CONSUMER_KEY', 'INOREADER_APP_ID', 'INOREADER_APP_KEY']
def chunks(seq, size):
return (seq[i:(i + size)] for i in range(0, len(seq), size))