parsecom 0.5.10 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -56,6 +56,7 @@ Yet-Another Parse.com Library written in Pure Ruby
56
56
  - [GeoPoint](#geopoint)
57
57
  - [Geo Queries](#geo-queries)
58
58
  - [Security](#security)
59
+ - [Debug](#debug)
59
60
 
60
61
  ## Usage
61
62
 
@@ -264,6 +265,12 @@ game_scores = GameScore.find :where => proc {
264
265
  }
265
266
  ```
266
267
 
268
+ ```ruby
269
+ game_scores = GameScore.find :where => proc {
270
+ column(:score).between(1000..3000)
271
+ }
272
+ ```
273
+
267
274
  ```ruby
268
275
  game_scores = GameScore.find :where => proc {
269
276
  column(:score).in(1, 3, 5, 7, 9)
@@ -623,3 +630,61 @@ If you want to use the master key for all API calls, set the use_master_key flag
623
630
  ```ruby
624
631
  Parse.use_master_key!
625
632
  ```
633
+
634
+ ### Debug
635
+
636
+ To see debug output, set $DEBUG true.
637
+
638
+ ```ruby
639
+ $DEBUG = true
640
+ Post.find :all
641
+ ```
642
+
643
+ You can see something like the following in $stderr.
644
+
645
+ ```
646
+ opening connection to api.parse.com...
647
+ opened
648
+ <- "GET /1/classes/Post? HTTP/1.1\r\nX-Parse-Application-Id: abcdefghijklmnopqrstuvwxyz0123456789ABCD\r\nContent-Type: application/json\r\nAccept: application/json\r\nUser-Agent: A parse.com client for ruby\r\nX-Parse-Rest-Api-Key: abcdefghijklmnopqrstuvwxyz0123456789ABCD\r\nHost: api.parse.com\r\n\r\n"
649
+ -> "HTTP/1.1 200 OK\r\n"
650
+ -> "Access-Control-Allow-Origin: *\r\n"
651
+ -> "Access-Control-Request-Method: *\r\n"
652
+ -> "Cache-Control: max-age=0, private, must-revalidate\r\n"
653
+ -> "Content-Type: application/json; charset=utf-8\r\n"
654
+ -> "Date: Sun, 08 Dec 2013 08:14:40 GMT\r\n"
655
+ -> "ETag: \"abcdefghijklmnopqrstuvwxyz012345\"\r\n"
656
+ -> "Server: nginx/1.4.2\r\n"
657
+ -> "Set-Cookie: _parse_session=abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789; domain=.parse.com; path=/; expires=Tue, 07-Jan-2014 08:14:40 GMT; secure; HttpOnly\r\n"
658
+ -> "Status: 200 OK\r\n"
659
+ -> "X-Runtime: 0.116322\r\n"
660
+ -> "X-UA-Compatible: IE=Edge,chrome=1\r\n"
661
+ -> "Content-Length: 603\r\n"
662
+ -> "Connection: keep-alive\r\n"
663
+ -> "\r\n"
664
+ reading 603 bytes...
665
+ -> "{\"results\":[{\"author\":{\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"xWJVfYPbBP\"},\"body\":\"\xE6\x9C\xAC\xE6\x96\x87\",\"title\":\"\xE3\x82\xBF\xE3\x82\xA4\xE3\x83\x88
666
+ \xE3\x83\xAB\",\"comments\":{\"__type\":\"Relation\",\"className\":\"Comment\"},\"createdAt\":\"2013-10-29T15:06:45.872Z\",\"updatedAt\":\"2013-10-29T15:09:01.111Z\",\"objectId\":\"6EyX2aypgD\"
667
+ },{\"comments\":{\"__type\":\"Relation\",\"className\":\"Comment\"},\"createdAt\":\"2013-10-30T04:38:47.068Z\",\"updatedAt\":\"2013-10-30T04:38:47.068Z\",\"objectId\":\"njvHr4aelZ\"},{\"comment
668
+ s\":{\"__type\":\"Relation\",\"className\":\"Comment\"},\"createdAt\":\"2013-10-30T04:40:37.397Z\",\"updatedAt\":\"2013-10-30T04:40:37.397Z\",\"objectId\":\"EDdGtur3vY\"}]}"
669
+ read 603 bytes
670
+ Conn keep-alive
671
+ ```
672
+
673
+ Also you can do dry-run.
674
+
675
+ ```ruby
676
+ Parse.dry_run!
677
+ Post.find :all
678
+ ```
679
+
680
+ This does not call any API and shows something like the following in $stderr.
681
+
682
+ ```
683
+ get /1/classes/Post?
684
+ X-Parse-Application-Id: abcdefghijklmnopqrstuvwxyz0123456789ABCD
685
+ Content-Type: application/json
686
+ Accept: application/json
687
+ User-Agent: A parse.com client for ruby
688
+ X-Parse-REST-API-Key: abcdefghijklmnopqrstuvwxyz0123456789ABCD
689
+
690
+ ```
@@ -193,6 +193,31 @@ module Parse
193
193
  EOS
194
194
  end
195
195
 
196
+ def dry_run?
197
+ @http_client.dry_run?
198
+ end
199
+
200
+ def dry_run!
201
+ @http_client.dry_run!
202
+ end
203
+
204
+ def dry_run= val
205
+ @http_client = val
206
+ end
207
+
208
+ def dry_run &block
209
+ return dry_run? unless block
210
+
211
+ tmp = dry_run?
212
+ dry_run!
213
+ begin
214
+ block.call
215
+ ensure
216
+ self.dry_run = tmp
217
+ end
218
+ nil
219
+ end
220
+
196
221
  def method_missing name, *args, &block
197
222
  call_function name, args.first
198
223
  end
@@ -1,13 +1,32 @@
1
1
  # coding:utf-8
2
2
  module Parse
3
3
  class HttpClient
4
- attr_accessor :host
4
+ attr_accessor :host, :dry_run
5
5
 
6
6
  def initialize host
7
7
  @host = host
8
+ @dry_run = false
9
+ end
10
+
11
+ def dry_run?
12
+ !!@dry_run
13
+ end
14
+
15
+ def dry_run!
16
+ @dry_run = true
8
17
  end
9
18
 
10
19
  def request method, endpoint, headers={}, body=nil, &block
20
+ if dry_run
21
+ $stderr.puts "#{
22
+ method} #{endpoint}\n#{
23
+ headers.to_a.map{|k,v| "#{k}: #{v}"}.join "\n"
24
+ }\n\n#{
25
+ body}"
26
+ block.call({}) if block
27
+ return
28
+ end
29
+
11
30
  req = eval("Net::HTTP::#{method.to_s.capitalize}").new endpoint, headers
12
31
  req.body = body if body
13
32
  client = Net::HTTP.new @host, 443
@@ -19,7 +19,7 @@ module Parse
19
19
  block = proc do |body|
20
20
  # TODO: should handle error
21
21
  results = body['results']
22
- results.query_count = body['count']
22
+ results.query_count = body['count'] if results
23
23
  results
24
24
  end unless block
25
25
  endpoint = %w(User).include?(@parse_class_name) \
@@ -2,7 +2,7 @@ module Parse
2
2
  module Util
3
3
  def string_keyed_hash hash
4
4
  new_hash = {}
5
- hash.each do |k, v|
5
+ (hash || {}).each do |k, v|
6
6
  new_hash[k.to_s] = v
7
7
  end
8
8
  new_hash
@@ -1,3 +1,3 @@
1
1
  module Parse
2
- VERSION = "0.5.10"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -91,4 +91,8 @@ module Parse
91
91
  def use_master_key!
92
92
  Parse::Client.default.use_master_key!
93
93
  end
94
+
95
+ def dry_run!
96
+ Parse::Client.default.dry_run!
97
+ end
94
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsecom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.10
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: