Skip to content

Commit

Permalink
Merge pull request #92 from s-aska/fix_bug_bool_cast_anyobject
Browse files Browse the repository at this point in the history
Bool being seen as int when using AnyObject
  • Loading branch information
mattdonnelly committed Jun 23, 2015
2 parents bf0646e + 02bb119 commit f85a1d8
Show file tree
Hide file tree
Showing 22 changed files with 187 additions and 187 deletions.
6 changes: 3 additions & 3 deletions Swifter/Swifter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class Swifter {

// MARK: - JSON Requests

internal func jsonRequestWithPath(path: String, baseURL: NSURL, method: String, parameters: Dictionary<String, AnyObject>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler? = nil, downloadProgress: JSONSuccessHandler? = nil, success: JSONSuccessHandler? = nil, failure: SwifterHTTPRequest.FailureHandler? = nil) -> SwifterHTTPRequest {
internal func jsonRequestWithPath(path: String, baseURL: NSURL, method: String, parameters: Dictionary<String, Any>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler? = nil, downloadProgress: JSONSuccessHandler? = nil, success: JSONSuccessHandler? = nil, failure: SwifterHTTPRequest.FailureHandler? = nil) -> SwifterHTTPRequest {
let jsonDownloadProgressHandler: SwifterHTTPRequest.DownloadProgressHandler = {
data, _, _, response in

Expand Down Expand Up @@ -167,11 +167,11 @@ public class Swifter {
}
}

internal func getJSONWithPath(path: String, baseURL: NSURL, parameters: Dictionary<String, AnyObject>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: JSONSuccessHandler?, success: JSONSuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest {
internal func getJSONWithPath(path: String, baseURL: NSURL, parameters: Dictionary<String, Any>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: JSONSuccessHandler?, success: JSONSuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest {
return self.jsonRequestWithPath(path, baseURL: baseURL, method: "GET", parameters: parameters, uploadProgress: uploadProgress, downloadProgress: downloadProgress, success: success, failure: failure)
}

internal func postJSONWithPath(path: String, baseURL: NSURL, parameters: Dictionary<String, AnyObject>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: JSONSuccessHandler?, success: JSONSuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest {
internal func postJSONWithPath(path: String, baseURL: NSURL, parameters: Dictionary<String, Any>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: JSONSuccessHandler?, success: JSONSuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest {
return self.jsonRequestWithPath(path, baseURL: baseURL, method: "POST", parameters: parameters, uploadProgress: uploadProgress, downloadProgress: downloadProgress, success: success, failure: failure)
}

Expand Down
12 changes: 6 additions & 6 deletions Swifter/SwifterAccountsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class SwifterAccountsClient: SwifterClientProtocol {
self.credential = SwifterCredential(account: account)
}

func get(path: String, baseURL: NSURL, parameters: Dictionary<String, AnyObject>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: SwifterHTTPRequest.DownloadProgressHandler?, success: SwifterHTTPRequest.SuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest {
func get(path: String, baseURL: NSURL, parameters: Dictionary<String, Any>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: SwifterHTTPRequest.DownloadProgressHandler?, success: SwifterHTTPRequest.SuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest {
let url = NSURL(string: path, relativeToURL: baseURL)

var stringifiedParameters = SwifterAccountsClient.convertDictionaryValuesToStrings(parameters)
Expand All @@ -53,15 +53,15 @@ internal class SwifterAccountsClient: SwifterClientProtocol {
return request
}

func post(path: String, baseURL: NSURL, parameters: Dictionary<String, AnyObject>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: SwifterHTTPRequest.DownloadProgressHandler?, success: SwifterHTTPRequest.SuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest {
func post(path: String, baseURL: NSURL, parameters: Dictionary<String, Any>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: SwifterHTTPRequest.DownloadProgressHandler?, success: SwifterHTTPRequest.SuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest {
let url = NSURL(string: path, relativeToURL: baseURL)

var params = parameters

var postData: NSData?
var postDataKey: String?

if let key: AnyObject = params[Swifter.DataParameters.dataKey] {
if let key: Any = params[Swifter.DataParameters.dataKey] {
if let keyString = key as? String {
postDataKey = keyString
postData = params[postDataKey!] as? NSData
Expand All @@ -72,7 +72,7 @@ internal class SwifterAccountsClient: SwifterClientProtocol {
}

var postDataFileName: String?
if let fileName: AnyObject = params[Swifter.DataParameters.fileNameKey] {
if let fileName: Any = params[Swifter.DataParameters.fileNameKey] {
if let fileNameString = fileName as? String {
postDataFileName = fileNameString
params.removeValueForKey(fileNameString)
Expand Down Expand Up @@ -100,10 +100,10 @@ internal class SwifterAccountsClient: SwifterClientProtocol {
return request
}

class func convertDictionaryValuesToStrings(dictionary: Dictionary<String, AnyObject>) -> Dictionary<String, String> {
class func convertDictionaryValuesToStrings(dictionary: Dictionary<String, Any>) -> Dictionary<String, String> {
var result = Dictionary<String, String>()

for (key, value: AnyObject) in dictionary {
for (key, value: Any) in dictionary {
result[key] = "\(value)"
}

Expand Down
4 changes: 2 additions & 2 deletions Swifter/SwifterAppOnlyClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class SwifterAppOnlyClient: SwifterClientProtocol {
self.dataEncoding = NSUTF8StringEncoding
}

func get(path: String, baseURL: NSURL, parameters: Dictionary<String, AnyObject>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: SwifterHTTPRequest.DownloadProgressHandler?, success: SwifterHTTPRequest.SuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest {
func get(path: String, baseURL: NSURL, parameters: Dictionary<String, Any>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: SwifterHTTPRequest.DownloadProgressHandler?, success: SwifterHTTPRequest.SuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest {
let url = NSURL(string: path, relativeToURL: baseURL)
let method = "GET"

Expand All @@ -58,7 +58,7 @@ internal class SwifterAppOnlyClient: SwifterClientProtocol {
return request
}

func post(path: String, baseURL: NSURL, parameters: Dictionary<String, AnyObject>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: SwifterHTTPRequest.DownloadProgressHandler?, success: SwifterHTTPRequest.SuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest {
func post(path: String, baseURL: NSURL, parameters: Dictionary<String, Any>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: SwifterHTTPRequest.DownloadProgressHandler?, success: SwifterHTTPRequest.SuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest {
let url = NSURL(string: path, relativeToURL: baseURL)
let method = "POST"

Expand Down
6 changes: 3 additions & 3 deletions Swifter/SwifterAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public extension Swifter {
public func postOAuth2BearerTokenWithSuccess(success: JSONSuccessHandler?, failure: FailureHandler?) {
let path = "/oauth2/token"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["grant_type"] = "client_credentials"

self.jsonRequestWithPath(path, baseURL: self.apiURL, method: "POST", parameters: parameters, success: success, failure: failure)
Expand Down Expand Up @@ -140,7 +140,7 @@ public extension Swifter {
public func postOAuthRequestTokenWithCallbackURL(callbackURL: NSURL, success: TokenSuccessHandler, failure: FailureHandler?) {
let path = "/oauth/request_token"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()

if let callbackURLString = callbackURL.absoluteString {
parameters["oauth_callback"] = callbackURLString
Expand All @@ -160,7 +160,7 @@ public extension Swifter {
if let verifier = requestToken.verifier {
let path = "/oauth/access_token"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["oauth_token"] = requestToken.key
parameters["oauth_verifier"] = verifier

Expand Down
4 changes: 2 additions & 2 deletions Swifter/SwifterClientProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public protocol SwifterClientProtocol {

var credential: SwifterCredential? { get set }

func get(path: String, baseURL: NSURL, parameters: Dictionary<String, AnyObject>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: SwifterHTTPRequest.DownloadProgressHandler?, success: SwifterHTTPRequest.SuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest
func get(path: String, baseURL: NSURL, parameters: Dictionary<String, Any>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: SwifterHTTPRequest.DownloadProgressHandler?, success: SwifterHTTPRequest.SuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest

func post(path: String, baseURL: NSURL, parameters: Dictionary<String, AnyObject>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: SwifterHTTPRequest.DownloadProgressHandler?, success: SwifterHTTPRequest.SuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest
func post(path: String, baseURL: NSURL, parameters: Dictionary<String, Any>, uploadProgress: SwifterHTTPRequest.UploadProgressHandler?, downloadProgress: SwifterHTTPRequest.DownloadProgressHandler?, success: SwifterHTTPRequest.SuccessHandler?, failure: SwifterHTTPRequest.FailureHandler?) -> SwifterHTTPRequest

}
10 changes: 5 additions & 5 deletions Swifter/SwifterFavorites.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public extension Swifter {
public func getFavoritesListWithCount(count: Int? = nil, sinceID: String? = nil, maxID: String? = nil, success: ((statuses: [JSONValue]?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "favorites/list.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
if count != nil {
parameters["count"] = count!
}
Expand All @@ -60,7 +60,7 @@ public extension Swifter {
public func getFavoritesListWithUserID(userID: String, count: Int? = nil, sinceID: String? = nil, maxID: String? = nil, success: ((statuses: [JSONValue]?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "favorites/list.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["user_id"] = userID

if count != nil {
Expand All @@ -85,7 +85,7 @@ public extension Swifter {
public func getFavoritesListWithScreenName(screenName: String, count: Int? = nil, sinceID: String? = nil, maxID: String? = nil, success: ((statuses: [JSONValue]?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "favorites/list.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["screen_name"] = screenName

if count != nil {
Expand Down Expand Up @@ -117,7 +117,7 @@ public extension Swifter {
public func postDestroyFavoriteWithID(id: String, includeEntities: Bool? = nil, success: ((status: Dictionary<String, JSONValue>?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "favorites/destroy.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["id"] = id

if includeEntities != nil {
Expand All @@ -143,7 +143,7 @@ public extension Swifter {
public func postCreateFavoriteWithID(id: String, includeEntities: Bool? = nil, success: ((status: Dictionary<String, JSONValue>?) -> Void)? = nil, failure: SwifterHTTPRequest.FailureHandler? = nil) {
let path = "favorites/create.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["id"] = id

if includeEntities != nil {
Expand Down
28 changes: 14 additions & 14 deletions Swifter/SwifterFollowers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public extension Swifter {
public func getFriendshipsNoRetweetsIDsWithStringifyIDs(stringifyIDs: Bool? = nil, success: ((ids: [JSONValue]?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "friendships/no_retweets/ids.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["stringify_ids"] = stringifyIDs!

self.getJSONWithPath(path, baseURL: self.apiURL, parameters: parameters, uploadProgress: nil, downloadProgress: nil, success: {
Expand Down Expand Up @@ -222,7 +222,7 @@ public extension Swifter {
public func postCreateFriendshipWithID(id: String, follow: Bool? = nil, success: ((user: Dictionary<String, JSONValue>?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "friendships/create.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["id"] = id

if follow != nil {
Expand All @@ -241,7 +241,7 @@ public extension Swifter {
public func postCreateFriendshipWithScreenName(screenName: String, follow: Bool? = nil, success: ((user: Dictionary<String, JSONValue>?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "friendships/create.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["screen_name"] = screenName

if follow != nil {
Expand Down Expand Up @@ -269,7 +269,7 @@ public extension Swifter {
public func postDestroyFriendshipWithID(id: String, success: ((user: Dictionary<String, JSONValue>?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "friendships/destroy.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["id"] = id

self.postJSONWithPath(path, baseURL: self.apiURL, parameters: parameters, uploadProgress: nil, downloadProgress: nil, success: {
Expand All @@ -284,7 +284,7 @@ public extension Swifter {
public func postDestroyFriendshipWithScreenName(screenName: String, success: ((user: Dictionary<String, JSONValue>?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "friendships/destroy.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["screen_name"] = screenName

self.postJSONWithPath(path, baseURL: self.apiURL, parameters: parameters, uploadProgress: nil, downloadProgress: nil, success: {
Expand Down Expand Up @@ -326,7 +326,7 @@ public extension Swifter {
public func postUpdateFriendshipWithScreenName(screenName: String, device: Bool? = nil, retweets: Bool? = nil, success: ((user: Dictionary<String, JSONValue>?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "friendships/update.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["screen_name"] = screenName

if device != nil {
Expand All @@ -353,7 +353,7 @@ public extension Swifter {
public func getFriendshipsShowWithSourceID(sourceID: String? = nil, targetID: String? = nil, orTargetScreenName targetScreenName: String? = nil, success: ((user: Dictionary<String, JSONValue>?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "friendships/show.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["source_id"] = sourceID!

if targetID != nil {
Expand All @@ -375,7 +375,7 @@ public extension Swifter {
public func getFriendshipsShowWithSourceScreenName(sourceScreenName: String? = nil, targetID: String? = nil, orTargetScreenName targetScreenName: String? = nil, success: ((user: Dictionary<String, JSONValue>?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "friendships/show.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["source_screen_name"] = sourceScreenName!

if targetID != nil {
Expand Down Expand Up @@ -404,7 +404,7 @@ public extension Swifter {
public func getFriendsListWithID(id: String, cursor: Int? = nil, count: Int? = nil, skipStatus: Bool? = nil, includeUserEntities: Bool? = nil, success: ((users: [JSONValue]?, previousCursor: Int?, nextCursor: Int?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "friends/list.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["id"] = id

if cursor != nil {
Expand All @@ -431,7 +431,7 @@ public extension Swifter {
public func getFriendsListWithScreenName(screenName: String, cursor: Int? = nil, count: Int? = nil, skipStatus: Bool? = nil, includeUserEntities: Bool? = nil, success: ((users: [JSONValue]?, previousCursor: Int?, nextCursor: Int?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "friends/list.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["screen_name"] = screenName

if cursor != nil {
Expand Down Expand Up @@ -465,7 +465,7 @@ public extension Swifter {
public func getFollowersListWithID(id: String, cursor: Int? = nil, count: Int? = nil, skipStatus: Bool? = nil, includeUserEntities: Bool? = nil, success: ((users: [JSONValue]?, previousCursor: Int?, nextCursor: Int?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "followers/list.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["id"] = id

if cursor != nil {
Expand All @@ -492,7 +492,7 @@ public extension Swifter {
public func getFollowersListWithScreenName(screenName: String, cursor: Int? = nil, count: Int? = nil, skipStatus: Bool? = nil, includeUserEntities: Bool? = nil, success: ((users: [JSONValue]?, previousCursor: Int?, nextCursor: Int?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "followers/list.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["screen_name"] = screenName

if cursor != nil {
Expand Down Expand Up @@ -524,7 +524,7 @@ public extension Swifter {
public func getFriendshipsLookupWithScreenNames(screenNames: [String], success: ((friendships: [JSONValue]?) -> Void)? = nil, failure: FailureHandler?) {
let path = "friendships/lookup.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()
parameters["screen_name"] = join(",", screenNames)

self.getJSONWithPath(path, baseURL: self.apiURL, parameters: parameters, uploadProgress: nil, downloadProgress: nil, success: {
Expand All @@ -539,7 +539,7 @@ public extension Swifter {
public func getFriendshipsLookupWithIDs(ids: [Int], success: ((friendships: [JSONValue]?) -> Void)? = nil, failure: FailureHandler? = nil) {
let path = "followers/lookup.json"

var parameters = Dictionary<String, AnyObject>()
var parameters = Dictionary<String, Any>()

let idStrings = ids.map { String($0) }
parameters["id"] = join(",", idStrings)
Expand Down
Loading

0 comments on commit f85a1d8

Please sign in to comment.