diff --git a/ChangeLog b/ChangeLog index 50416ec26..e75dd3583 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,6 @@ CHANGELOG -2015-05-04 1.2.0 +2015-06-08 1.2.0 * new retry logic * add new parameter on the Query: setMinProximity & setHighlightingTags * add new method on the Query: resetLocationParameters diff --git a/Source/Client.swift b/Source/Client.swift index 105ba4484..a98a37034 100644 --- a/Source/Client.swift +++ b/Source/Client.swift @@ -74,7 +74,8 @@ public class Client { /// :param: apiKey a valid API key for the service /// :param: tagFilters value of the header X-Algolia-TagFilters /// :param: userToken value of the header X-Algolia-UserToken - public init(appID: String, apiKey: String, tagFilters: String? = nil, userToken: String? = nil) { + /// :param: hostnames the list of hosts that you have received for the service + public init(appID: String, apiKey: String, tagFilters: String? = nil, userToken: String? = nil, hostnames: [String]? = nil) { if count(appID) == 0 { NSException(name: "InvalidArgument", reason: "Application ID must be set", userInfo: nil).raise() } else if count(apiKey) == 0 { @@ -86,20 +87,25 @@ public class Client { self.tagFilters = tagFilters self.userToken = userToken - readQueryHostnames = [ - "\(appID)-DSN.algolia.net", - "\(appID)-1.algolianet.com", - "\(appID)-2.algolianet.com", - "\(appID)-3.algolianet.com" - ] - - writeQueryHostnames = [ - "\(appID).algolia.net", - "\(appID)-1.algolianet.com", - "\(appID)-2.algolianet.com", - "\(appID)-3.algolianet.com" - ] - + if let hostnames = hostnames { + readQueryHostnames = hostnames + writeQueryHostnames = hostnames + } else { + readQueryHostnames = [ + "\(appID)-DSN.algolia.net", + "\(appID)-1.algolianet.com", + "\(appID)-2.algolianet.com", + "\(appID)-3.algolianet.com" + ] + + writeQueryHostnames = [ + "\(appID).algolia.net", + "\(appID)-1.algolianet.com", + "\(appID)-2.algolianet.com", + "\(appID)-3.algolianet.com" + ] + } + let version = NSBundle(forClass: self.dynamicType).infoDictionary!["CFBundleShortVersionString"] as! String var HTTPHeaders = [ @@ -179,7 +185,7 @@ public class Client { /// Return 10 last log entries. public func getLogs(block: CompletionHandler) { - performHTTPQuery("1/logs", method: .GET, body: nil, hostnames: readQueryHostnames, block: block) + performHTTPQuery("1/logs", method: .GET, body: nil, hostnames: writeQueryHostnames, block: block) } /// Return last logs entries. diff --git a/Source/Extension.swift b/Source/Extension.swift index e9722545f..7823d0ad9 100644 --- a/Source/Extension.swift +++ b/Source/Extension.swift @@ -23,16 +23,6 @@ import Foundation -extension Array { - /// Shuffle the array - mutating func shuffle() { - for i in 0..<(count - 1) { - let j = Int(arc4random_uniform(UInt32(count - i))) + i - swap(&self[i], &self[j]) - } - } -} - extension String { /// Return URL encoded version of the string func urlEncode() -> String {