Skip to content

Commit 6a83499

Browse files
author
Christian König
committed
Cleaned up access control
1 parent 1afeaa0 commit 6a83499

File tree

6 files changed

+47
-23
lines changed

6 files changed

+47
-23
lines changed

Source/Core/Request.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ internal enum Endpoint {
208208
}
209209
}
210210

211-
var needsBasicAuthHeader: Bool {
211+
internal var needsBasicAuthHeader: Bool {
212212
switch self {
213213
case .loginUser, .refreshToken, .revokeToken, .createNewFigoUser:
214214
return true
@@ -217,7 +217,7 @@ internal enum Endpoint {
217217
}
218218
}
219219

220-
var URLRequest: NSMutableURLRequest {
220+
internal var URLRequest: NSMutableURLRequest {
221221
let URL = Foundation.URL(string: Endpoint.baseURLString)!
222222
let request = NSMutableURLRequest(url: URL.appendingPathComponent(path))
223223
request.httpMethod = self.method.rawValue

Source/FigoClient.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ internal let POLLING_COUNTDOWN_INITIAL_VALUE = 100 // 100 x 400 ms = 40 s
3232
- Important: Completion handlers are NOT executed on the main thread
3333

3434
*/
35-
open class FigoClient {
35+
public class FigoClient {
3636

37-
let sessionDelegate = FigoURLSessionDelegate()
38-
let session: URLSession
37+
private let sessionDelegate = FigoURLSessionDelegate()
38+
private let session: URLSession
3939

4040
// Used for Basic HTTP authentication, derived from CliendID and ClientSecret
41-
var basicAuthCredentials: String?
41+
internal var basicAuthCredentials: String?
4242

4343
/// OAuth2 access token
44-
var accessToken: String?
44+
internal var accessToken: String?
4545

4646
/// OAuth2 refresh token
47-
var refreshToken: String?
47+
internal var refreshToken: String?
4848

4949

5050
public convenience init() {
@@ -70,7 +70,7 @@ open class FigoClient {
7070
}
7171
}
7272

73-
func request(_ endpoint: Endpoint, completion: @escaping (FigoResult<Data>) -> Void) {
73+
internal func request(_ endpoint: Endpoint, completion: @escaping (FigoResult<Data>) -> Void) {
7474
let mutableURLRequest = endpoint.URLRequest
7575

7676
if endpoint.needsBasicAuthHeader {
@@ -132,7 +132,7 @@ open class FigoClient {
132132
/**
133133
Check's the server's certificates to make sure that you are really talking to the figo server
134134
*/
135-
open class func dispositionForChallenge(_ challenge: URLAuthenticationChallenge) -> URLSession.AuthChallengeDisposition {
135+
internal class func dispositionForChallenge(_ challenge: URLAuthenticationChallenge) -> URLSession.AuthChallengeDisposition {
136136

137137
var disposition: URLSession.AuthChallengeDisposition = .performDefaultHandling
138138

@@ -159,7 +159,7 @@ open class FigoClient {
159159
}
160160

161161

162-
internal class FigoURLSessionDelegate: NSObject, URLSessionDelegate {
162+
private class FigoURLSessionDelegate: NSObject, URLSessionDelegate {
163163

164164
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
165165
completionHandler(FigoClient.dispositionForChallenge(challenge), nil)

Source/FigoDate.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111

12-
/// Provides a NSDate representation for the server's timestamps
12+
/// Provides a Foundation.Date representation for the server's timestamps
1313
public struct FigoDate: UnboxableByTransform, CustomStringConvertible {
1414

1515
public typealias UnboxRawValue = String
@@ -19,14 +19,14 @@ public struct FigoDate: UnboxableByTransform, CustomStringConvertible {
1919
public var formattedShort: String
2020
public var formattedLong: String
2121

22-
init() {
22+
internal init() {
2323
self.date = Foundation.Date.distantPast
2424
self.timestamp = ""
2525
self.formattedShort = "Invalid date"
2626
self.formattedLong = "Invalid date"
2727
}
2828

29-
init? (timestamp: String) {
29+
public init? (timestamp: String) {
3030
if let date = FigoDate.posixFormatter.date(from: timestamp) {
3131
self.date = date
3232
self.timestamp = timestamp

Source/FigoError.swift

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,36 @@
99
import Foundation
1010

1111

12+
/**
13+
If an error occurs, the API returns an error object with a couple of fields providing further details.
14+
*/
1215
public struct FigoError: Error, CustomStringConvertible, Unboxable {
1316

17+
/// Error code (see http://docs.figo.io/#error-handling)
1418
public let code: Int
19+
20+
// String identifying the source of the error
1521
public let group: String?
22+
23+
/// Error message
1624
public let message: String?
25+
26+
/// Error name
1727
public let name: String?
18-
public let originalDescription: String?
28+
29+
/// Error description (Renamed to allow a non-optinal implementation of CustomStringConvertible)
30+
public let narrative: String?
31+
32+
/// Any additional data
1933
public let data: [String:Any]?
2034

35+
2136
public init(unboxer: Unboxer) throws {
2237
code = (try? unboxer.unbox(key: "code")) ?? 0
2338
group = unboxer.unbox(key: "group")
2439
message = unboxer.unbox(key: "message")
2540
name = unboxer.unbox(key: "name")
26-
originalDescription = unboxer.unbox(key: "description")
41+
narrative = unboxer.unbox(key: "description")
2742
data = unboxer.unbox(key: "data")
2843
}
2944

@@ -32,13 +47,14 @@ public struct FigoError: Error, CustomStringConvertible, Unboxable {
3247
group = nil
3348
message = nil
3449
name = nil
35-
originalDescription = error.description
50+
narrative = error.description
3651
data = nil
3752
}
3853

54+
/// Narrative, message, name or code (depending on what values are available)
3955
public var description: String {
4056
get {
41-
if let description = originalDescription {
57+
if let description = narrative {
4258
return description
4359
}
4460
if let description = message {
@@ -50,11 +66,14 @@ public struct FigoError: Error, CustomStringConvertible, Unboxable {
5066
return "\(code)"
5167
}
5268
}
53-
69+
5470
}
5571

5672

57-
public enum InternalError: Error, CustomStringConvertible {
73+
/**
74+
Internal error type which is transformed into an FigoError
75+
*/
76+
internal enum InternalError: Error, CustomStringConvertible {
5877

5978
case noActiveSession
6079
case emptyResponse
@@ -65,7 +84,7 @@ public enum InternalError: Error, CustomStringConvertible {
6584
case taskProcessingTimeout
6685
case unboxingError(String)
6786

68-
public var code: Int {
87+
var code: Int {
6988
get {
7089
switch self {
7190
case .noActiveSession:
@@ -88,7 +107,7 @@ public enum InternalError: Error, CustomStringConvertible {
88107
}
89108
}
90109

91-
public var description: String {
110+
var description: String {
92111
get {
93112
switch self {
94113
case .noActiveSession:

Source/FigoResult.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
//
88

99

10+
/**
11+
Result type used for all API calls
12+
13+
Contains a generic value on success and a FigoError object on failure.
14+
*/
1015
public enum FigoResult<Value>: CustomStringConvertible, CustomDebugStringConvertible {
1116

1217
case success(Value)

Source/Types/Account.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public struct Account: Unboxable {
132132
type = try unboxer.unbox(key: "type")
133133

134134
// Special treatment for supported payments because the payment type values are stored in keys instead of values
135-
supportedPayments = try (unboxer.unbox(key: "supported_payments") as [String: AnyObject]).keys.map() { paymentType in
135+
supportedPayments = try (unboxer.unbox(key: "supported_payments") as [String: AnyObject]).keys.map() { paymentType in
136136
return (PaymentType(rawValue: paymentType) ?? PaymentType.Unknown, try unboxer.unbox(keyPath: "supported_payments.\(paymentType)"))
137137
}
138138
}

0 commit comments

Comments
 (0)