Skip to content

Commit c6c5dcb

Browse files
author
Clément Le Provost
committed
Merge branch 'feat/forwardToSlaves'
2 parents 0c1cdd3 + b7b94d2 commit c6c5dcb

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

Source/Index.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,22 @@ import Foundation
296296
let path = "1/indexes/\(urlEncodedIndexName)/settings"
297297
return client.performHTTPQuery(path, method: .PUT, body: settings, hostnames: client.writeHosts, completionHandler: completionHandler)
298298
}
299-
299+
300+
/// Set this index's settings, optionally forwarding the change to slave indices.
301+
///
302+
/// Please refer to our [API documentation](https://www.algolia.com/doc/swift#index-settings) for the list of
303+
/// supported settings.
304+
///
305+
/// - parameter settings: New settings.
306+
/// - parameter forwardToSlaves: When true, the change is also applied to slaves of this index.
307+
/// - parameter completionHandler: Completion handler to be notified of the request's outcome.
308+
/// - returns: A cancellable operation.
309+
///
310+
@objc public func setSettings(settings: [String: AnyObject], forwardToSlaves: Bool, completionHandler: CompletionHandler? = nil) -> NSOperation {
311+
let path = "1/indexes/\(urlEncodedIndexName)/settings?forwardToSlaves=\(forwardToSlaves)"
312+
return client.performHTTPQuery(path, method: .PUT, body: settings, hostnames: client.writeHosts, completionHandler: completionHandler)
313+
}
314+
300315
/// Delete the index content without removing settings and index specific API keys.
301316
///
302317
/// - parameter completionHandler: Completion handler to be notified of the request's outcome.

Tests/IndexTests.swift

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,39 @@ class IndexTests: XCTestCase {
581581

582582
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
583583
}
584-
584+
585+
func testSettings_forwardToSlaves() {
586+
let expectation = expectationWithDescription("testSettings")
587+
let settings = ["attributesToRetrieve": ["name"]]
588+
589+
index.setSettings(settings, forwardToSlaves: true, completionHandler: { (content, error) -> Void in
590+
if let error = error {
591+
XCTFail("Error during setSettings: \(error)")
592+
expectation.fulfill()
593+
} else {
594+
self.index.waitTask(content!["taskID"] as! Int, completionHandler: { (content, error) -> Void in
595+
if let error = error {
596+
XCTFail("Error during waitTask: \(error)")
597+
expectation.fulfill()
598+
} else {
599+
self.index.getSettings({ (content, error) -> Void in
600+
if let error = error {
601+
XCTFail("Error during getSettings: \(error)")
602+
} else {
603+
let attributesToRetrieve = content!["attributesToRetrieve"] as! [String]
604+
XCTAssertEqual(attributesToRetrieve, settings["attributesToRetrieve"]!, "Set settings failed")
605+
}
606+
607+
expectation.fulfill()
608+
})
609+
}
610+
})
611+
}
612+
})
613+
614+
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
615+
}
616+
585617
func testBrowse() {
586618
let expectation = expectationWithDescription("testBrowseWithQuery")
587619
var objects: [[String: AnyObject]] = []

0 commit comments

Comments
 (0)