Skip to content

Commit 7781223

Browse files
author
Clément Le Provost
committed
Merge branch 'feat/is-alive'
2 parents 75a0712 + 66543c8 commit 7781223

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
@@ -282,6 +282,17 @@ import Foundation
282282
let body = ["requests": operations]
283283
return performHTTPQuery(path, method: .POST, body: body, hostnames: writeHosts, completionHandler: completionHandler)
284284
}
285+
286+
/// Ping the server.
287+
/// This method returns nothing except a message indicating that the server is alive.
288+
///
289+
/// - parameter completionHandler: Completion handler to be notified of the request's outcome.
290+
/// - returns: A cancellable operation.
291+
///
292+
@objc public func isAlive(completionHandler: CompletionHandler) -> NSOperation {
293+
let path = "1/isalive"
294+
return performHTTPQuery(path, method: .GET, body: nil, hostnames: readHosts, completionHandler: completionHandler)
295+
}
285296

286297
// MARK: - Network
287298

Tests/ClientTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,18 @@ class ClientTests: XCTestCase {
378378
}
379379
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
380380
}
381+
382+
func testIsAlive() {
383+
let expectation = expectationWithDescription(#function)
384+
385+
client.isAlive() { (content, error) -> Void in
386+
if let error = error {
387+
XCTFail(error.description)
388+
} else {
389+
XCTAssertEqual(content?["message"] as? String, "server is alive")
390+
}
391+
expectation.fulfill()
392+
}
393+
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
394+
}
381395
}

0 commit comments

Comments
 (0)