Skip to content

Commit

Permalink
A few small improvements and bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Cobbe committed Sep 19, 2016
1 parent c68b91b commit b52374e
Show file tree
Hide file tree
Showing 29 changed files with 2,486 additions and 2,451 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ Then, run the following command to install the dependency:
$ pod install
```

**Note**: If you are encountering `Use Legacy Swift Language Version` warnings after running `pod install`, then add the following to the end of your Podfile:
**Note**: If you are encountering `Use Legacy Swift Language Version` and/or `Always Embed Swift Standard Libraries` warnings after running `pod install`, then add the following to the end of your Podfile:

```ruby
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'YES'
end
end
end
Expand All @@ -91,7 +92,7 @@ brew install carthage

```
# SwiftyDropbox
github "https://github.com/dropbox/SwiftyDropbox" ~> 4.0.2
github "https://github.com/dropbox/SwiftyDropbox" ~> 4.0.3
```

Then, run the following command to install the dependency to checkout and build the Dropbox Swift SDK repository:
Expand Down Expand Up @@ -611,6 +612,20 @@ let transportClient = DropboxTransportClient(accessToken: "<MY_ACCESS_TOKEN>",
DropboxClientsManager.setupWithAppKeyDesktop("<APP_KEY>", transportClient: transportClient)
```

You can also set custom queues on a route-by-route basis in the response handler:

```Swift
let client = DropboxClientsManager.authorizedClient!

_ = client.files.listFolder(path: "").response(queue: DispatchQueue(label: "MyCustomSerialQueue")) { response, error in
if let result = response {
print(Thread.current) // Output: <NSThread: 0x61000007bec0>{number = 4, name = (null)}
print(Thread.main) // Output: <NSThread: 0x608000070100>{number = 1, name = (null)}
print(result)
}
}
```

### `DropboxClientsManager` class

The Swift SDK includes a convenience class, `DropboxClientsManager`, for integrating the different functions of the SDK into one class.
Expand Down
44 changes: 22 additions & 22 deletions Source/Source/PlatformNeutral/Async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Foundation

/// Datatypes and serializers for the async namespace
public class Async {
open class Async {
/// Result returned by methods that launch an asynchronous job. A method who may either launch an asynchronous job,
/// or complete the request synchronously, can use this union by extending it, and adding a 'complete' field with
/// the type of the synchronous response. See LaunchEmptyResult for an example.
Expand All @@ -20,17 +20,17 @@ public class Async {
return "\(SerializeUtil.prepareJSONForSerialization(LaunchResultBaseSerializer().serialize(self)))"
}
}
public class LaunchResultBaseSerializer: JSONSerializer {
open class LaunchResultBaseSerializer: JSONSerializer {
public init() { }
public func serialize(_ value: LaunchResultBase) -> JSON {
open func serialize(_ value: LaunchResultBase) -> JSON {
switch value {
case .asyncJobId(let arg):
var d = ["async_job_id": Serialization._StringSerializer.serialize(arg)]
d[".tag"] = .str("async_job_id")
return .dictionary(d)
}
}
public func deserialize(_ json: JSON) -> LaunchResultBase {
open func deserialize(_ json: JSON) -> LaunchResultBase {
switch json {
case .dictionary(let d):
let tag = Serialization.getTag(d)
Expand Down Expand Up @@ -60,9 +60,9 @@ public class Async {
return "\(SerializeUtil.prepareJSONForSerialization(LaunchEmptyResultSerializer().serialize(self)))"
}
}
public class LaunchEmptyResultSerializer: JSONSerializer {
open class LaunchEmptyResultSerializer: JSONSerializer {
public init() { }
public func serialize(_ value: LaunchEmptyResult) -> JSON {
open func serialize(_ value: LaunchEmptyResult) -> JSON {
switch value {
case .asyncJobId(let arg):
var d = ["async_job_id": Serialization._StringSerializer.serialize(arg)]
Expand All @@ -74,7 +74,7 @@ public class Async {
return .dictionary(d)
}
}
public func deserialize(_ json: JSON) -> LaunchEmptyResult {
open func deserialize(_ json: JSON) -> LaunchEmptyResult {
switch json {
case .dictionary(let d):
let tag = Serialization.getTag(d)
Expand All @@ -94,26 +94,26 @@ public class Async {
}

/// Arguments for methods that poll the status of an asynchronous job.
public class PollArg: CustomStringConvertible {
open class PollArg: CustomStringConvertible {
/// Id of the asynchronous job. This is the value of a response returned from the method that launched the job.
public let asyncJobId: String
open let asyncJobId: String
public init(asyncJobId: String) {
stringValidator(minLength: 1)(asyncJobId)
self.asyncJobId = asyncJobId
}
public var description: String {
open var description: String {
return "\(SerializeUtil.prepareJSONForSerialization(PollArgSerializer().serialize(self)))"
}
}
public class PollArgSerializer: JSONSerializer {
open class PollArgSerializer: JSONSerializer {
public init() { }
public func serialize(_ value: PollArg) -> JSON {
open func serialize(_ value: PollArg) -> JSON {
let output = [
"async_job_id": Serialization._StringSerializer.serialize(value.asyncJobId),
]
return .dictionary(output)
}
public func deserialize(_ json: JSON) -> PollArg {
open func deserialize(_ json: JSON) -> PollArg {
switch json {
case .dictionary(let dict):
let asyncJobId = Serialization._StringSerializer.deserialize(dict["async_job_id"] ?? .null)
Expand All @@ -135,17 +135,17 @@ public class Async {
return "\(SerializeUtil.prepareJSONForSerialization(PollResultBaseSerializer().serialize(self)))"
}
}
public class PollResultBaseSerializer: JSONSerializer {
open class PollResultBaseSerializer: JSONSerializer {
public init() { }
public func serialize(_ value: PollResultBase) -> JSON {
open func serialize(_ value: PollResultBase) -> JSON {
switch value {
case .inProgress:
var d = [String: JSON]()
d[".tag"] = .str("in_progress")
return .dictionary(d)
}
}
public func deserialize(_ json: JSON) -> PollResultBase {
open func deserialize(_ json: JSON) -> PollResultBase {
switch json {
case .dictionary(let d):
let tag = Serialization.getTag(d)
Expand Down Expand Up @@ -173,9 +173,9 @@ public class Async {
return "\(SerializeUtil.prepareJSONForSerialization(PollEmptyResultSerializer().serialize(self)))"
}
}
public class PollEmptyResultSerializer: JSONSerializer {
open class PollEmptyResultSerializer: JSONSerializer {
public init() { }
public func serialize(_ value: PollEmptyResult) -> JSON {
open func serialize(_ value: PollEmptyResult) -> JSON {
switch value {
case .inProgress:
var d = [String: JSON]()
Expand All @@ -187,7 +187,7 @@ public class Async {
return .dictionary(d)
}
}
public func deserialize(_ json: JSON) -> PollEmptyResult {
open func deserialize(_ json: JSON) -> PollEmptyResult {
switch json {
case .dictionary(let d):
let tag = Serialization.getTag(d)
Expand Down Expand Up @@ -219,9 +219,9 @@ public class Async {
return "\(SerializeUtil.prepareJSONForSerialization(PollErrorSerializer().serialize(self)))"
}
}
public class PollErrorSerializer: JSONSerializer {
open class PollErrorSerializer: JSONSerializer {
public init() { }
public func serialize(_ value: PollError) -> JSON {
open func serialize(_ value: PollError) -> JSON {
switch value {
case .invalidAsyncJobId:
var d = [String: JSON]()
Expand All @@ -237,7 +237,7 @@ public class Async {
return .dictionary(d)
}
}
public func deserialize(_ json: JSON) -> PollError {
open func deserialize(_ json: JSON) -> PollError {
switch json {
case .dictionary(let d):
let tag = Serialization.getTag(d)
Expand Down
28 changes: 14 additions & 14 deletions Source/Source/PlatformNeutral/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Foundation

/// Datatypes and serializers for the auth namespace
public class Auth {
open class Auth {
/// Errors occurred during authentication.
public enum AuthError: CustomStringConvertible {
/// The access token is invalid.
Expand All @@ -23,9 +23,9 @@ public class Auth {
return "\(SerializeUtil.prepareJSONForSerialization(AuthErrorSerializer().serialize(self)))"
}
}
public class AuthErrorSerializer: JSONSerializer {
open class AuthErrorSerializer: JSONSerializer {
public init() { }
public func serialize(_ value: AuthError) -> JSON {
open func serialize(_ value: AuthError) -> JSON {
switch value {
case .invalidAccessToken:
var d = [String: JSON]()
Expand All @@ -45,7 +45,7 @@ public class Auth {
return .dictionary(d)
}
}
public func deserialize(_ json: JSON) -> AuthError {
open func deserialize(_ json: JSON) -> AuthError {
switch json {
case .dictionary(let d):
let tag = Serialization.getTag(d)
Expand All @@ -68,30 +68,30 @@ public class Auth {
}

/// Error occurred because the app is being rate limited.
public class RateLimitError: CustomStringConvertible {
open class RateLimitError: CustomStringConvertible {
/// The reason why the app is being rate limited.
public let reason: Auth.RateLimitReason
open let reason: Auth.RateLimitReason
/// The number of seconds that the app should wait before making another request.
public let retryAfter: UInt64
open let retryAfter: UInt64
public init(reason: Auth.RateLimitReason, retryAfter: UInt64 = 1) {
self.reason = reason
comparableValidator()(retryAfter)
self.retryAfter = retryAfter
}
public var description: String {
open var description: String {
return "\(SerializeUtil.prepareJSONForSerialization(RateLimitErrorSerializer().serialize(self)))"
}
}
public class RateLimitErrorSerializer: JSONSerializer {
open class RateLimitErrorSerializer: JSONSerializer {
public init() { }
public func serialize(_ value: RateLimitError) -> JSON {
open func serialize(_ value: RateLimitError) -> JSON {
let output = [
"reason": Auth.RateLimitReasonSerializer().serialize(value.reason),
"retry_after": Serialization._UInt64Serializer.serialize(value.retryAfter),
]
return .dictionary(output)
}
public func deserialize(_ json: JSON) -> RateLimitError {
open func deserialize(_ json: JSON) -> RateLimitError {
switch json {
case .dictionary(let dict):
let reason = Auth.RateLimitReasonSerializer().deserialize(dict["reason"] ?? .null)
Expand All @@ -116,9 +116,9 @@ public class Auth {
return "\(SerializeUtil.prepareJSONForSerialization(RateLimitReasonSerializer().serialize(self)))"
}
}
public class RateLimitReasonSerializer: JSONSerializer {
open class RateLimitReasonSerializer: JSONSerializer {
public init() { }
public func serialize(_ value: RateLimitReason) -> JSON {
open func serialize(_ value: RateLimitReason) -> JSON {
switch value {
case .tooManyRequests:
var d = [String: JSON]()
Expand All @@ -134,7 +134,7 @@ public class Auth {
return .dictionary(d)
}
}
public func deserialize(_ json: JSON) -> RateLimitReason {
open func deserialize(_ json: JSON) -> RateLimitReason {
switch json {
case .dictionary(let d):
let tag = Serialization.getTag(d)
Expand Down
6 changes: 3 additions & 3 deletions Source/Source/PlatformNeutral/AuthRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
///

/// Routes for the auth namespace
public class AuthRoutes {
public let client: DropboxTransportClient
open class AuthRoutes {
open let client: DropboxTransportClient
init(client: DropboxTransportClient) {
self.client = client
}
Expand All @@ -16,7 +16,7 @@ public class AuthRoutes {
///
/// - returns: Through the response callback, the caller will receive a `Void` object on success or a `Void` object
/// on failure.
public func tokenRevoke() -> RpcRequest<VoidSerializer, VoidSerializer> {
open func tokenRevoke() -> RpcRequest<VoidSerializer, VoidSerializer> {
let route = Auth.tokenRevoke
return client.request(route)
}
Expand Down
10 changes: 5 additions & 5 deletions Source/Source/PlatformNeutral/Base.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import Foundation

import Alamofire

public class DropboxBase {
open class DropboxBase {
/// Routes within the auth namespace. See AuthRoutes for details.
public var auth: AuthRoutes!
open var auth: AuthRoutes!
/// Routes within the files namespace. See FilesRoutes for details.
public var files: FilesRoutes!
open var files: FilesRoutes!
/// Routes within the sharing namespace. See SharingRoutes for details.
public var sharing: SharingRoutes!
open var sharing: SharingRoutes!
/// Routes within the users namespace. See UsersRoutes for details.
public var users: UsersRoutes!
open var users: UsersRoutes!

public init(client: DropboxTransportClient) {
self.auth = AuthRoutes(client: client)
Expand Down
4 changes: 2 additions & 2 deletions Source/Source/PlatformNeutral/BaseTeam.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import Foundation

import Alamofire

public class DropboxTeamBase {
open class DropboxTeamBase {
/// Routes within the team namespace. See TeamRoutes for details.
public var team: TeamRoutes!
open var team: TeamRoutes!

public init(client: DropboxTransportClient) {
self.team = TeamRoutes(client: client)
Expand Down
2 changes: 1 addition & 1 deletion Source/Source/PlatformNeutral/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
import Foundation

/// Datatypes and serializers for the common namespace
public class Common {
open class Common {
}
2 changes: 1 addition & 1 deletion Source/Source/PlatformNeutral/DropboxClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Alamofire

/// The client for the User API. Call routes using the namespaces inside this object (inherited from parent).

public class DropboxClient: DropboxBase {
open class DropboxClient: DropboxBase {
fileprivate var transportClient: DropboxTransportClient

public convenience init(accessToken: String, selectUser: String? = nil) {
Expand Down
Loading

0 comments on commit b52374e

Please sign in to comment.