Skip to content

Commit 66543c8

Browse files
author
Clément Le Provost
committed
Implement the “is alive” endpoint
`Client.isAlive()` just pings `/1/isalive`.
1 parent 3e1a65e commit 66543c8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Source/Client.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,17 @@ import Foundation
281281
let body = ["requests": operations]
282282
return performHTTPQuery(path, method: .POST, body: body, hostnames: writeHosts, completionHandler: completionHandler)
283283
}
284+
285+
/// Ping the server.
286+
/// This method returns nothing except a message indicating that the server is alive.
287+
///
288+
/// - parameter completionHandler: Completion handler to be notified of the request's outcome.
289+
/// - returns: A cancellable operation.
290+
///
291+
@objc public func isAlive(completionHandler: CompletionHandler) -> NSOperation {
292+
let path = "1/isalive"
293+
return performHTTPQuery(path, method: .GET, body: nil, hostnames: readHosts, completionHandler: completionHandler)
294+
}
284295

285296
// MARK: - Network
286297

Tests/ClientTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,18 @@ class ClientTests: XCTestCase {
336336
}
337337
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
338338
}
339+
340+
func testIsAlive() {
341+
let expectation = expectationWithDescription(#function)
342+
343+
client.isAlive() { (content, error) -> Void in
344+
if let error = error {
345+
XCTFail(error.description)
346+
} else {
347+
XCTAssertEqual(content?["message"] as? String, "server is alive")
348+
}
349+
expectation.fulfill()
350+
}
351+
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
352+
}
339353
}

0 commit comments

Comments
 (0)