{"action":"created","comment":{"url":"https://api.github.com/repos/cloudant/swift-cloudant/pulls/comments/63196477","id":63196477,"diff_hunk":"@@ -0,0 +1,215 @@\n+//\n+//  FindDocumentsOperation.swift\n+//  SwiftCloudant\n+//\n+//  Created by Rhys Short on 20/04/2016.\n+//  Copyright (c) 2016 IBM Corp.\n+//\n+//  Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file\n+//  except in compliance with the License. You may obtain a copy of the License at\n+//    http://www.apache.org/licenses/LICENSE-2.0\n+//  Unless required by applicable law or agreed to in writing, software distributed under the\n+//  License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\n+//  either express or implied. See the License for the specific language governing permissions\n+//  and limitations under the License.\n+//\n+\n+import Foundation\n+\n+/**\n+ The direction of Sorting\n+ */\n+public enum SortDirection: String {\n+    /**\n+     Sort ascending\n+     */\n+    case Asc = \"asc\"\n+    /**\n+     Sort descending\n+     */\n+    case Desc = \"desc\"\n+}\n+\n+/**\n+ Specfies how a field should be sorted\n+ */\n+public struct Sort {\n+\n+    /**\n+     The field on which to sort\n+     */\n+    let field: String\n+    let sort: SortDirection?\n+}\n+\n+public class FindDocumentsOperation: CouchDatabaseOperation {\n+    /**\n+     The selector for the query. See\n+     [the Cloudant documentation](https://docs.cloudant.com/cloudant_query.html#selector-syntax)\n+     for syntax information.\n+\n+     Required: This needs to be set before the operation can successfully run.\n+     */\n+    public var selector: [String: AnyObject]?;\n+\n+    /**\n+     The fields to include in the results.\n+\n+     Optional: Default is null\n+     */\n+    public var fields: [String]?\n+\n+    /**\n+     The number maximium number of documents to return.\n+\n+     Optional: The database will choose a limit, negative values will\n+     result in the parameter not being included in requests\n+     */\n+    public var limit: Int?\n+\n+    /**\n+     Skip the first _n_ results, where _n_ is specified by skip.\n+\n+     Optional: The database will choose a number of documents to skip,\n+     negative values will result in the parameter not being included in\n+     requests\n+     */\n+    public var skip: Int?\n+\n+    /**\n+     How to sort the results, the array must follow sort syntax as documented in\n+     [the Cloudant documentation](https://docs.cloudant.com/cloudant_query.html#sort-syntax)\n+\n+     Optional: The database will decide how sort results.\n+     */\n+    public var sort: [Sort]?\n+\n+    /**\n+     A string that enables you to specify which page of results you require.\n+\n+     Optional: The database will return the first page without this set.\n+\n+     Note: This is only for valid text indexes.\n+     */\n+    public var bookmark: String?\n+\n+    /**\n+     A specific index to run the query against.\n+\n+     Optional: The Database will determine the index to run the query\n+     against if omitted.\n+     */\n+    public var useIndex: String?\n+\n+    /**\n+     The read quorum for this request.\n+\n+     Optional: The Database will determine the read quorum, negative values will\n+     result in the parameter not being included in requests.\n+\n+     - warning: This is an advanced option and is rarely, if ever, needed. It will be detrimental to\n+     performance.\n+\n+     */\n+    public var r: Int?\n+\n+    /**\n+     Block to run for each document retrived from the database matching the query.\n+\n+     - parameter document: a document matching the query.\n+     */\n+    public var documentFoundHanlder: ((document: [String: AnyObject]) -> Void)?\n+\n+    private var json: [String: AnyObject]?\n+\n+    public override var httpMethod: String {\n+        return \"POST\"\n+    }\n+\n+    public override var httpPath: String {\n+        return \"/\\(self.databaseName!)/_find\"\n+    }\n+\n+    private var jsonData: NSData?\n+    public override var httpRequestBody: NSData? {\n+        return self.jsonData\n+    }\n+\n+    public override func validate() -> Bool {\n+        if !super.validate() {\n+            return false\n+        }\n+\n+        // build the body dict, we will store this to save compute cycles.","path":"Source/FindDocumentsOperation.swift","position":143,"original_position":143,"commit_id":"716b95e9c69f7ef14394b93c2b9edfb2701c3df6","original_commit_id":"10bd4f078b7957d88d7edf24a38dff63dd832b2e","user":{"login":"rhyshort","id":1616727,"avatar_url":"https://avatars.githubusercontent.com/u/1616727?v=3","gravatar_id":"","url":"https://api.github.com/users/rhyshort","html_url":"https://github.com/rhyshort","followers_url":"https://api.github.com/users/rhyshort/followers","following_url":"https://api.github.com/users/rhyshort/following{/other_user}","gists_url":"https://api.github.com/users/rhyshort/gists{/gist_id}","starred_url":"https://api.github.com/users/rhyshort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhyshort/subscriptions","organizations_url":"https://api.github.com/users/rhyshort/orgs","repos_url":"https://api.github.com/users/rhyshort/repos","events_url":"https://api.github.com/users/rhyshort/events{/privacy}","received_events_url":"https://api.github.com/users/rhyshort/received_events","type":"User","site_admin":false},"body":"I don't think so since we need to build the structure to do the isValid so we can fail at validation, then in serialise we fail if we fail to do the seralise into json, if that makes sense","created_at":"2016-05-13T14:52:54Z","updated_at":"2016-05-13T14:52:54Z","html_url":"https://github.com/cloudant/swift-cloudant/pull/35#discussion_r63196477","pull_request_url":"https://api.github.com/repos/cloudant/swift-cloudant/pulls/35","_links":{"self":{"href":"https://api.github.com/repos/cloudant/swift-cloudant/pulls/comments/63196477"},"html":{"href":"https://github.com/cloudant/swift-cloudant/pull/35#discussion_r63196477"},"pull_request":{"href":"https://api.github.com/repos/cloudant/swift-cloudant/pulls/35"}}},"pull_request":{"url":"https://api.github.com/repos/cloudant/swift-cloudant/pulls/35","id":67507612,"html_url":"https://github.com/cloudant/swift-cloudant/pull/35","diff_url":"https://github.com/cloudant/swift-cloudant/pull/35.diff","patch_url":"https://github.com/cloudant/swift-cloudant/pull/35.patch","issue_url":"https://api.github.com/repos/cloudant/swift-cloudant/issues/35","number":35,"state":"open","locked":false,"title":"Implement Querying for Documents","user":{"login":"rhyshort","id":1616727,"avatar_url":"https://avatars.githubusercontent.com/u/1616727?v=3","gravatar_id":"","url":"https://api.github.com/users/rhyshort","html_url":"https://github.com/rhyshort","followers_url":"https://api.github.com/users/rhyshort/followers","following_url":"https://api.github.com/users/rhyshort/following{/other_user}","gists_url":"https://api.github.com/users/rhyshort/gists{/gist_id}","starred_url":"https://api.github.com/users/rhyshort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhyshort/subscriptions","organizations_url":"https://api.github.com/users/rhyshort/orgs","repos_url":"https://api.github.com/users/rhyshort/repos","events_url":"https://api.github.com/users/rhyshort/events{/privacy}","received_events_url":"https://api.github.com/users/rhyshort/received_events","type":"User","site_admin":false},"body":"## What\r\nSupport Querying for documents using the `_find` endpoint.\r\n\r\n##  How\r\n- Created FindDocumentsOperation which represents an operation to find documents using the `_find` endpoint.\r\n\r\n## Testing\r\nNew test case added: FindDocumentsOperationTests, this contains the following:\r\n- Extensive testing against a Mocked HTTP response using `OHHTTPStubs` \r\n- Tests to make sure properties return values expected, eg `POST` for HTTP method the body being sent is correct etc.\r\n\r\n## Reviewers\r\nreviewer @ricellis\r\n\r\n## Issues\r\nFixes #8","created_at":"2016-04-22T13:02:36Z","updated_at":"2016-05-13T14:52:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"54fb1692f51a02c3e4f2c06626541fc6bef220b5","assignee":null,"milestone":{"url":"https://api.github.com/repos/cloudant/swift-cloudant/milestones/3","html_url":"https://github.com/cloudant/swift-cloudant/milestones/0.3.0","labels_url":"https://api.github.com/repos/cloudant/swift-cloudant/milestones/3/labels","id":1746819,"number":3,"title":"0.3.0","description":"","creator":{"login":"ricellis","id":10698320,"avatar_url":"https://avatars.githubusercontent.com/u/10698320?v=3","gravatar_id":"","url":"https://api.github.com/users/ricellis","html_url":"https://github.com/ricellis","followers_url":"https://api.github.com/users/ricellis/followers","following_url":"https://api.github.com/users/ricellis/following{/other_user}","gists_url":"https://api.github.com/users/ricellis/gists{/gist_id}","starred_url":"https://api.github.com/users/ricellis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ricellis/subscriptions","organizations_url":"https://api.github.com/users/ricellis/orgs","repos_url":"https://api.github.com/users/ricellis/repos","events_url":"https://api.github.com/users/ricellis/events{/privacy}","received_events_url":"https://api.github.com/users/ricellis/received_events","type":"User","site_admin":false},"open_issues":13,"closed_issues":0,"state":"open","created_at":"2016-05-04T07:36:26Z","updated_at":"2016-05-13T10:16:41Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/cloudant/swift-cloudant/pulls/35/commits","review_comments_url":"https://api.github.com/repos/cloudant/swift-cloudant/pulls/35/comments","review_comment_url":"https://api.github.com/repos/cloudant/swift-cloudant/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloudant/swift-cloudant/issues/35/comments","statuses_url":"https://api.github.com/repos/cloudant/swift-cloudant/statuses/716b95e9c69f7ef14394b93c2b9edfb2701c3df6","head":{"label":"cloudant:query-documents","ref":"query-documents","sha":"716b95e9c69f7ef14394b93c2b9edfb2701c3df6","user":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"repo":{"id":55980905,"name":"swift-cloudant","full_name":"cloudant/swift-cloudant","owner":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudant/swift-cloudant","description":"A Swift Lang client for Cloudant and CouchDB","fork":false,"url":"https://api.github.com/repos/cloudant/swift-cloudant","forks_url":"https://api.github.com/repos/cloudant/swift-cloudant/forks","keys_url":"https://api.github.com/repos/cloudant/swift-cloudant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudant/swift-cloudant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudant/swift-cloudant/teams","hooks_url":"https://api.github.com/repos/cloudant/swift-cloudant/hooks","issue_events_url":"https://api.github.com/repos/cloudant/swift-cloudant/issues/events{/number}","events_url":"https://api.github.com/repos/cloudant/swift-cloudant/events","assignees_url":"https://api.github.com/repos/cloudant/swift-cloudant/assignees{/user}","branches_url":"https://api.github.com/repos/cloudant/swift-cloudant/branches{/branch}","tags_url":"https://api.github.com/repos/cloudant/swift-cloudant/tags","blobs_url":"https://api.github.com/repos/cloudant/swift-cloudant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudant/swift-cloudant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudant/swift-cloudant/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudant/swift-cloudant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudant/swift-cloudant/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudant/swift-cloudant/languages","stargazers_url":"https://api.github.com/repos/cloudant/swift-cloudant/stargazers","contributors_url":"https://api.github.com/repos/cloudant/swift-cloudant/contributors","subscribers_url":"https://api.github.com/repos/cloudant/swift-cloudant/subscribers","subscription_url":"https://api.github.com/repos/cloudant/swift-cloudant/subscription","commits_url":"https://api.github.com/repos/cloudant/swift-cloudant/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudant/swift-cloudant/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudant/swift-cloudant/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudant/swift-cloudant/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudant/swift-cloudant/contents/{+path}","compare_url":"https://api.github.com/repos/cloudant/swift-cloudant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudant/swift-cloudant/merges","archive_url":"https://api.github.com/repos/cloudant/swift-cloudant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudant/swift-cloudant/downloads","issues_url":"https://api.github.com/repos/cloudant/swift-cloudant/issues{/number}","pulls_url":"https://api.github.com/repos/cloudant/swift-cloudant/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudant/swift-cloudant/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudant/swift-cloudant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudant/swift-cloudant/labels{/name}","releases_url":"https://api.github.com/repos/cloudant/swift-cloudant/releases{/id}","deployments_url":"https://api.github.com/repos/cloudant/swift-cloudant/deployments","created_at":"2016-04-11T14:47:54Z","updated_at":"2016-05-03T15:13:01Z","pushed_at":"2016-05-13T14:13:18Z","git_url":"git://github.com/cloudant/swift-cloudant.git","ssh_url":"git@github.com:cloudant/swift-cloudant.git","clone_url":"https://github.com/cloudant/swift-cloudant.git","svn_url":"https://github.com/cloudant/swift-cloudant","homepage":null,"size":372,"stargazers_count":0,"watchers_count":0,"language":"Swift","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":23,"forks":0,"open_issues":23,"watchers":0,"default_branch":"master"}},"base":{"label":"cloudant:master","ref":"master","sha":"9884591ba6cfc276de92bb966a35084397607c40","user":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"repo":{"id":55980905,"name":"swift-cloudant","full_name":"cloudant/swift-cloudant","owner":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudant/swift-cloudant","description":"A Swift Lang client for Cloudant and CouchDB","fork":false,"url":"https://api.github.com/repos/cloudant/swift-cloudant","forks_url":"https://api.github.com/repos/cloudant/swift-cloudant/forks","keys_url":"https://api.github.com/repos/cloudant/swift-cloudant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudant/swift-cloudant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudant/swift-cloudant/teams","hooks_url":"https://api.github.com/repos/cloudant/swift-cloudant/hooks","issue_events_url":"https://api.github.com/repos/cloudant/swift-cloudant/issues/events{/number}","events_url":"https://api.github.com/repos/cloudant/swift-cloudant/events","assignees_url":"https://api.github.com/repos/cloudant/swift-cloudant/assignees{/user}","branches_url":"https://api.github.com/repos/cloudant/swift-cloudant/branches{/branch}","tags_url":"https://api.github.com/repos/cloudant/swift-cloudant/tags","blobs_url":"https://api.github.com/repos/cloudant/swift-cloudant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudant/swift-cloudant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudant/swift-cloudant/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudant/swift-cloudant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudant/swift-cloudant/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudant/swift-cloudant/languages","stargazers_url":"https://api.github.com/repos/cloudant/swift-cloudant/stargazers","contributors_url":"https://api.github.com/repos/cloudant/swift-cloudant/contributors","subscribers_url":"https://api.github.com/repos/cloudant/swift-cloudant/subscribers","subscription_url":"https://api.github.com/repos/cloudant/swift-cloudant/subscription","commits_url":"https://api.github.com/repos/cloudant/swift-cloudant/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudant/swift-cloudant/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudant/swift-cloudant/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudant/swift-cloudant/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudant/swift-cloudant/contents/{+path}","compare_url":"https://api.github.com/repos/cloudant/swift-cloudant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudant/swift-cloudant/merges","archive_url":"https://api.github.com/repos/cloudant/swift-cloudant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudant/swift-cloudant/downloads","issues_url":"https://api.github.com/repos/cloudant/swift-cloudant/issues{/number}","pulls_url":"https://api.github.com/repos/cloudant/swift-cloudant/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudant/swift-cloudant/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudant/swift-cloudant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudant/swift-cloudant/labels{/name}","releases_url":"https://api.github.com/repos/cloudant/swift-cloudant/releases{/id}","deployments_url":"https://api.github.com/repos/cloudant/swift-cloudant/deployments","created_at":"2016-04-11T14:47:54Z","updated_at":"2016-05-03T15:13:01Z","pushed_at":"2016-05-13T14:13:18Z","git_url":"git://github.com/cloudant/swift-cloudant.git","ssh_url":"git@github.com:cloudant/swift-cloudant.git","clone_url":"https://github.com/cloudant/swift-cloudant.git","svn_url":"https://github.com/cloudant/swift-cloudant","homepage":null,"size":372,"stargazers_count":0,"watchers_count":0,"language":"Swift","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":23,"forks":0,"open_issues":23,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cloudant/swift-cloudant/pulls/35"},"html":{"href":"https://github.com/cloudant/swift-cloudant/pull/35"},"issue":{"href":"https://api.github.com/repos/cloudant/swift-cloudant/issues/35"},"comments":{"href":"https://api.github.com/repos/cloudant/swift-cloudant/issues/35/comments"},"review_comments":{"href":"https://api.github.com/repos/cloudant/swift-cloudant/pulls/35/comments"},"review_comment":{"href":"https://api.github.com/repos/cloudant/swift-cloudant/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloudant/swift-cloudant/pulls/35/commits"},"statuses":{"href":"https://api.github.com/repos/cloudant/swift-cloudant/statuses/716b95e9c69f7ef14394b93c2b9edfb2701c3df6"}}}}