From 200ed12085f0e77a175cc35614ef7b3b869cfaa2 Mon Sep 17 00:00:00 2001 From: David Brownman Date: Thu, 16 Oct 2014 22:23:17 -0700 Subject: [PATCH 1/9] fixed code typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 598616a..6ac939c 100644 --- a/README.md +++ b/README.md @@ -678,7 +678,7 @@ You can issue a query with multiple fields included by passing a comma-separated ```ruby comments = Parse::Query.new("Comment").tap do |q| - q.include("post,author") + q.include = "post,author" end.get ``` From 937e6e5fe8f9b91ae3d8cd149ee744f6bab25df2 Mon Sep 17 00:00:00 2001 From: David Brownman Date: Thu, 16 Oct 2014 23:25:10 -0700 Subject: [PATCH 2/9] added keys code --- lib/parse/query.rb | 3 ++- test/test_query.rb | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/parse/query.rb b/lib/parse/query.rb index 069bc65..ebbe59e 100644 --- a/lib/parse/query.rb +++ b/lib/parse/query.rb @@ -12,6 +12,7 @@ class Query attr_accessor :skip attr_accessor :count attr_accessor :include + attr_accessor :keys def initialize(cls_name) @class_name = cls_name @@ -141,7 +142,7 @@ def get end query = { "where" => where_as_json.to_json } set_order(query) - [:count, :limit, :skip, :include].each {|a| merge_attribute(a, query)} + [:count, :limit, :skip, :include, :keys].each {|a| merge_attribute(a, query)} Parse.client.logger.info{"Parse query for #{uri} #{query.inspect}"} unless Parse.client.quiet response = Parse.client.request uri, :get, nil, query diff --git a/test/test_query.rb b/test/test_query.rb index c9dfb7c..e8fed68 100644 --- a/test/test_query.rb +++ b/test/test_query.rb @@ -101,6 +101,10 @@ def test_include end end + # def test_keys + + # end + def test_or #VCR.use_cassette('test_or', :record => :new_episodes) do foo = Parse::Object.new "Post" From af7e27d8ccf4b513c5d3421f88dd53d5cd31d5d8 Mon Sep 17 00:00:00 2001 From: David Brownman Date: Thu, 16 Oct 2014 23:36:57 -0700 Subject: [PATCH 3/9] added test --- fixtures/vcr_cassettes/test_keys.yml | 56 ++++++++++++++++++++++++++++ test/test_query.rb | 17 +++++++-- 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 fixtures/vcr_cassettes/test_keys.yml diff --git a/fixtures/vcr_cassettes/test_keys.yml b/fixtures/vcr_cassettes/test_keys.yml new file mode 100644 index 0000000..9cdbfe5 --- /dev/null +++ b/fixtures/vcr_cassettes/test_keys.yml @@ -0,0 +1,56 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.parse.com/1/classes/Post + body: + encoding: UTF-8 + string: '{"title":"foo","name":"This is cool"}' + headers: + User-Agent: + - Parse for Ruby, 0.0 + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 401 + message: Unauthorized + headers: + Access-Control-Allow-Methods: + - "*" + Access-Control-Allow-Origin: + - "*" + Cache-Control: + - no-cache + Content-Type: + - application/json; charset=utf-8 + Date: + - Fri, 17 Oct 2014 06:33:04 GMT + Server: + - nginx/1.6.0 + Set-Cookie: + - "" + Status: + - 401 Unauthorized + Www-Authenticate: + - Basic realm="Parse" + X-Content-Type-Options: + - nosniff + X-Runtime: + - '0.004163' + X-Ua-Compatible: + - IE=Edge,chrome=1 + Content-Length: + - '24' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"error":"unauthorized"}' + http_version: + recorded_at: Fri, 17 Oct 2014 06:33:04 GMT +recorded_with: VCR 2.4.0 diff --git a/test/test_query.rb b/test/test_query.rb index e8fed68..7401175 100644 --- a/test/test_query.rb +++ b/test/test_query.rb @@ -101,9 +101,20 @@ def test_include end end - # def test_keys - - # end + def test_keys + VCR.use_cassette('test_keys', :record => :new_episodes) do + post = Parse::Object.new "Post" + post['title'] = 'foo' + post['name'] = "This is cool" + post.save + + q = Parse::Query.new "Post" + q.eq('objectId', post_2.parse_object_id) + q.keys = "title" + + refute q.get.first.include? 'name' + end + end def test_or #VCR.use_cassette('test_or', :record => :new_episodes) do From fb1bc22234b5dec7dc4e20108a55dbf4fbd3e715 Mon Sep 17 00:00:00 2001 From: David Brownman Date: Thu, 16 Oct 2014 23:43:36 -0700 Subject: [PATCH 4/9] changed quote style --- test/test_query.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_query.rb b/test/test_query.rb index 7401175..2a1ea08 100644 --- a/test/test_query.rb +++ b/test/test_query.rb @@ -105,12 +105,12 @@ def test_keys VCR.use_cassette('test_keys', :record => :new_episodes) do post = Parse::Object.new "Post" post['title'] = 'foo' - post['name'] = "This is cool" + post['name'] = 'This is cool' post.save q = Parse::Query.new "Post" q.eq('objectId', post_2.parse_object_id) - q.keys = "title" + q.keys = 'title' refute q.get.first.include? 'name' end From e507562def09e37063f6ecdcffc24a6b34c8d3ff Mon Sep 17 00:00:00 2001 From: David Brownman Date: Fri, 17 Oct 2014 00:17:24 -0700 Subject: [PATCH 5/9] added ds_store to top level so it only needs to be included once --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5940128..3725aed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ /coverage pkg -lib/.DS_Store -lib/parse/.DS_Store +.DS_Store .bundle From 48add33380e168c168ad10bf9b850162de5ccf09 Mon Sep 17 00:00:00 2001 From: David Brownman Date: Fri, 17 Oct 2014 00:17:32 -0700 Subject: [PATCH 6/9] added test for keys --- fixtures/vcr_cassettes/test_keys.yml | 79 ++++++++++++++++++++++++---- test/test_query.rb | 4 +- 2 files changed, 71 insertions(+), 12 deletions(-) diff --git a/fixtures/vcr_cassettes/test_keys.yml b/fixtures/vcr_cassettes/test_keys.yml index 9cdbfe5..01b33c7 100644 --- a/fixtures/vcr_cassettes/test_keys.yml +++ b/fixtures/vcr_cassettes/test_keys.yml @@ -11,14 +11,18 @@ http_interactions: - Parse for Ruby, 0.0 Content-Type: - application/json + X-Parse-Application-Id: + - "" + X-Parse-Rest-Api-Key: + - "" Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 Accept: - "*/*" response: status: - code: 401 - message: Unauthorized + code: 201 + message: Created headers: Access-Control-Allow-Methods: - "*" @@ -29,28 +33,83 @@ http_interactions: Content-Type: - application/json; charset=utf-8 Date: - - Fri, 17 Oct 2014 06:33:04 GMT + - Fri, 17 Oct 2014 07:11:41 GMT + Location: + - https://api.parse.com/1/classes/Post/VJMChhWzgt Server: - nginx/1.6.0 Set-Cookie: - "" Status: - - 401 Unauthorized - Www-Authenticate: - - Basic realm="Parse" + - 201 Created X-Content-Type-Options: - nosniff X-Runtime: - - '0.004163' + - '0.024972' X-Ua-Compatible: - IE=Edge,chrome=1 Content-Length: - - '24' + - '64' Connection: - keep-alive body: encoding: UTF-8 - string: '{"error":"unauthorized"}' + string: '{"createdAt":"2014-10-17T07:11:41.210Z","objectId":"VJMChhWzgt"}' http_version: - recorded_at: Fri, 17 Oct 2014 06:33:04 GMT + recorded_at: Fri, 17 Oct 2014 07:11:41 GMT +- request: + method: get + uri: https://api.parse.com/1/classes/Post?keys=title&where=%7B%22objectId%22:%22VJMChhWzgt%22%7D + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Parse for Ruby, 0.0 + Content-Type: + - application/json + X-Parse-Application-Id: + - "" + X-Parse-Rest-Api-Key: + - "" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Access-Control-Allow-Methods: + - "*" + Access-Control-Allow-Origin: + - "*" + Cache-Control: + - max-age=0, private, must-revalidate + Content-Type: + - application/json; charset=utf-8 + Date: + - Fri, 17 Oct 2014 07:12:41 GMT + Server: + - nginx/1.6.0 + Set-Cookie: + - "" + Status: + - 200 OK + X-Content-Type-Options: + - nosniff + X-Runtime: + - '0.026852' + X-Ua-Compatible: + - IE=Edge,chrome=1 + Content-Length: + - '114' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"results":[{"title":"foo","createdAt":"2014-10-17T07:11:41.210Z","updatedAt":"2014-10-17T07:11:41.210Z","objectId":"VJMChhWzgt"}]}' + http_version: + recorded_at: Fri, 17 Oct 2014 07:12:41 GMT recorded_with: VCR 2.4.0 diff --git a/test/test_query.rb b/test/test_query.rb index 2a1ea08..7595f20 100644 --- a/test/test_query.rb +++ b/test/test_query.rb @@ -109,10 +109,10 @@ def test_keys post.save q = Parse::Query.new "Post" - q.eq('objectId', post_2.parse_object_id) + q.eq('objectId', post.parse_object_id) q.keys = 'title' - refute q.get.first.include? 'name' + assert_equal false, q.get.first.include?('name') end end From c8a417419b324b63abc0cec967d1bc45d8a21c46 Mon Sep 17 00:00:00 2001 From: David Brownman Date: Fri, 17 Oct 2014 01:14:13 -0700 Subject: [PATCH 7/9] updated readme with keys changes --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 6ac939c..f5c0448 100644 --- a/README.md +++ b/README.md @@ -572,6 +572,15 @@ scores = Parse::Query.new("GameScore").tap do |q| end.get ``` +You can use `keys` to only get specified fields back. `objectId`, `createdAt`, and `updatedAt` are always returned, and other fields are supplied as a comma separated string. + +```ruby +scores = Parse::Query.new("GameScore").tap do |q| + q.keys = "score,name" +end.get +``` + + All of these parameters can be used in combination with each other. ### Queries on Array Values From 38d59e45db677a3118cc4f23619f2b5b773bed73 Mon Sep 17 00:00:00 2001 From: David Brownman Date: Tue, 13 Jan 2015 23:50:51 -0800 Subject: [PATCH 8/9] added clarity on init variables --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f5c0448..beb0073 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ parse-ruby-client lets you interact with Parse using Ruby. There are many uses. ```ruby require 'parse-ruby-client' -Parse.init :application_id => "", - :api_key => "", - :quiet => true | false +Parse.init :application_id => "", # required + :api_key => "", # required + :quiet => true | false # optional, defaults to false ``` [![Gem Version](https://badge.fury.io/rb/parse-ruby-client.png)](http://badge.fury.io/rb/parse-ruby-client) From 1698619b22e00ea985136778f89945e20ad957f2 Mon Sep 17 00:00:00 2001 From: David Brownman Date: Wed, 27 May 2015 20:30:10 -0700 Subject: [PATCH 9/9] changed badges to use shields.io --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index beb0073..053c42b 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,11 @@ Parse.init :application_id => "", # required :quiet => true | false # optional, defaults to false ``` -[![Gem Version](https://badge.fury.io/rb/parse-ruby-client.png)](http://badge.fury.io/rb/parse-ruby-client) +[![Gem Version](https://img.shields.io/gem/v/parse-ruby-client.svg)](http://badge.fury.io/rb/parse-ruby-client) -[![Build Status](https://travis-ci.org/adelevie/parse-ruby-client.png?branch=master)](https://travis-ci.org/adelevie/parse-ruby-client) +[![Travis](https://img.shields.io/travis/adelevie/parse-ruby-client.svg)](https://travis-ci.org/adelevie/parse-ruby-client) -[![Code Climate](https://codeclimate.com/github/adelevie/parse-ruby-client.png)](https://codeclimate.com/github/adelevie/parse-ruby-client) +[![Code Climate](https://img.shields.io/codeclimate/github/adelevie/parse-ruby-client.svg)](https://codeclimate.com/github/adelevie/parse-ruby-client) **Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*