Skip to content

Commit

Permalink
feat(AssistantV1): Add option to sort results in getWorkspace()
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Oliveri committed Dec 11, 2018
1 parent 05bac84 commit 5cefc7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Source/AssistantV1/Assistant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,17 @@ public class Assistant {
subelements, is included.
- parameter includeAudit: Whether to include the audit properties (`created` and `updated` timestamps) in the
response.
- parameter sort: Indicates how the returned workspace data will be sorted. This parameter is valid only if
**export**=`true`. Specify `sort=stable` to sort all workspace objects by unique identifier, in ascending
alphabetical order.
- parameter headers: A dictionary of request headers to be sent with this request.
- parameter completionHandler: A function executed when the request completes with a successful result or error
*/
public func getWorkspace(
workspaceID: String,
export: Bool? = nil,
includeAudit: Bool? = nil,
sort: String? = nil,
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<WorkspaceExport>?, WatsonError?) -> Void)
{
Expand All @@ -387,6 +391,10 @@ public class Assistant {
let queryParameter = URLQueryItem(name: "include_audit", value: "\(includeAudit)")
queryParameters.append(queryParameter)
}
if let sort = sort {
let queryParameter = URLQueryItem(name: "sort", value: sort)
queryParameters.append(queryParameter)
}

// construct REST request
let path = "/v1/workspaces/\(workspaceID)"
Expand Down
4 changes: 3 additions & 1 deletion Tests/AssistantV1Tests/AssistantV1UnitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class AssistantV1UnitTests: XCTestCase {
XCTAssertTrue(request.url?.query?.contains("version=\(versionDate)") ?? false)
XCTAssertTrue(request.url?.query?.contains("export=true") ?? false)
XCTAssertTrue(request.url?.query?.contains("include_audit=true") ?? false)
XCTAssertTrue(request.url?.query?.contains("sort=stable") ?? false)

return (dummyResponse, Data())
}
Expand All @@ -223,7 +224,8 @@ class AssistantV1UnitTests: XCTestCase {
assistant.getWorkspace(
workspaceID: self.workspaceID,
export: true,
includeAudit: true) {
includeAudit: true,
sort: "stable") {
_, _ in
expectation.fulfill()
}
Expand Down

0 comments on commit 5cefc7b

Please sign in to comment.