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 diff --git a/README.md b/README.md index 598616a..053c42b 100644 --- a/README.md +++ b/README.md @@ -18,16 +18,16 @@ 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) +[![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/)* @@ -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 @@ -678,7 +687,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 ``` diff --git a/fixtures/vcr_cassettes/test_keys.yml b/fixtures/vcr_cassettes/test_keys.yml new file mode 100644 index 0000000..01b33c7 --- /dev/null +++ b/fixtures/vcr_cassettes/test_keys.yml @@ -0,0 +1,115 @@ +--- +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 + 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: 201 + message: Created + 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 07:11:41 GMT + Location: + - https://api.parse.com/1/classes/Post/VJMChhWzgt + Server: + - nginx/1.6.0 + Set-Cookie: + - "" + Status: + - 201 Created + X-Content-Type-Options: + - nosniff + X-Runtime: + - '0.024972' + X-Ua-Compatible: + - IE=Edge,chrome=1 + Content-Length: + - '64' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"createdAt":"2014-10-17T07:11:41.210Z","objectId":"VJMChhWzgt"}' + http_version: + 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/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..7595f20 100644 --- a/test/test_query.rb +++ b/test/test_query.rb @@ -101,6 +101,21 @@ def test_include end 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.parse_object_id) + q.keys = 'title' + + assert_equal false, q.get.first.include?('name') + end + end + def test_or #VCR.use_cassette('test_or', :record => :new_episodes) do foo = Parse::Object.new "Post"