parse-ruby-client 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,7 +19,7 @@ This currently depends on the gems 'json' and 'patron' for JSON support and HTTP
19
19
 
20
20
  ## Installation
21
21
 
22
- `gem "parse-ruby-client", "~> 0.1.7"`
22
+ `gem "parse-ruby-client", "~> 0.1.8"`
23
23
 
24
24
  ---
25
25
 
@@ -48,7 +48,7 @@ Parse.init
48
48
 
49
49
  The test folder assumes this naming convention for environment variables, so if you want to run the tests, you *must* do this. But it's easy. And good for you, too.
50
50
 
51
- ### New: Load API keys from `global.json` created by Cloud Code
51
+ ### Load API keys from `global.json` created by Cloud Code
52
52
 
53
53
  ```ruby
54
54
  Parse.init_from_cloud_code("path/to/global.json")
@@ -155,6 +155,21 @@ push = Parse::Push.new({"alert" => "I'm sending this push to all my app users!"}
155
155
  push.save
156
156
  ```
157
157
 
158
+ ## Batch Requests
159
+
160
+ ```ruby
161
+ batch = Parse::Batch.new
162
+ batch.add_request({
163
+ "method" => "POST",
164
+ "path" => "/1/classes/GameScore",
165
+ "body" => {
166
+ "score" => 1337,
167
+ "playerName" => "Sean Plott"
168
+ }
169
+ })
170
+ resp = batch.run!
171
+ ```
172
+
158
173
  ## Cloud Code
159
174
 
160
175
  ```ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.8
@@ -0,0 +1,83 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.parse.com/1/batch
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"requests":[{"method":"POST","path":"/1/classes/GameScore","body":{"score":1337,"playerName":"Sean
9
+ Plott"}}]}'
10
+ headers:
11
+ Content-Type:
12
+ - application/json
13
+ Accept:
14
+ - application/json
15
+ User-Agent:
16
+ - Parse for Ruby, 0.0
17
+ X-Parse-Master-Key:
18
+ - ''
19
+ X-Parse-Rest-Api-Key:
20
+ - D3Y8jNCQk6kpkKhpRGnWLYTrFGQ7j8dtDVnWZRnZ
21
+ X-Parse-Application-Id:
22
+ - PPVk6L5M9R1R8GVk8Ye9jT8f5SQNBIeoJUDJLmkT
23
+ X-Parse-Session-Token:
24
+ - ''
25
+ Expect:
26
+ - ''
27
+ response:
28
+ status:
29
+ code: 200
30
+ message: !binary |-
31
+ T0s=
32
+ headers:
33
+ !binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctT3JpZ2lu":
34
+ - !binary |-
35
+ Kg==
36
+ !binary "QWNjZXNzLUNvbnRyb2wtUmVxdWVzdC1NZXRob2Q=":
37
+ - !binary |-
38
+ Kg==
39
+ !binary "Q2FjaGUtQ29udHJvbA==":
40
+ - !binary |-
41
+ bWF4LWFnZT0wLCBwcml2YXRlLCBtdXN0LXJldmFsaWRhdGU=
42
+ !binary "Q29udGVudC1UeXBl":
43
+ - !binary |-
44
+ YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
45
+ !binary "RGF0ZQ==":
46
+ - !binary |-
47
+ U2F0LCAwNSBKYW4gMjAxMyAyMjo1NToyMSBHTVQ=
48
+ !binary "RXRhZw==":
49
+ - !binary |-
50
+ IjYyYTEwM2MzYmY1ZGFlMDM4M2ZkYWQ4NTM1MTE0ZmUzIg==
51
+ !binary "U2VydmVy":
52
+ - !binary |-
53
+ bmdpbngvMS4yLjI=
54
+ !binary "U2V0LUNvb2tpZQ==":
55
+ - !binary |-
56
+ X3BhcnNlX3Nlc3Npb249QkFoN0Jra2lEM05sYzNOcGIyNWZhV1FHT2daRlJp
57
+ SWxOV05qTlRnNU1XWTVNVEEzWVRRMU9UQmlOak15WmpNd1lXTXdNMkUyTVdJ
58
+ JTNELS03YTZlOGQyNmFhMTlhOWMzNTJiNWMzYzgxZGNjNWE0ZGY5NTgxYWRk
59
+ OyBkb21haW49LnBhcnNlLmNvbTsgcGF0aD0vOyBleHBpcmVzPVRodSwgMDUt
60
+ SmFuLTIwMjMgMjI6NTU6MjEgR01UOyBzZWN1cmU7IEh0dHBPbmx5
61
+ !binary "U3RhdHVz":
62
+ - !binary |-
63
+ MjAwIE9L
64
+ !binary "WC1SdW50aW1l":
65
+ - !binary |-
66
+ MC44NjczMjQ=
67
+ !binary "WC1VYS1Db21wYXRpYmxl":
68
+ - !binary |-
69
+ SUU9RWRnZSxjaHJvbWU9MQ==
70
+ !binary "Q29udGVudC1MZW5ndGg=":
71
+ - !binary |-
72
+ Nzg=
73
+ !binary "Q29ubmVjdGlvbg==":
74
+ - !binary |-
75
+ a2VlcC1hbGl2ZQ==
76
+ body:
77
+ encoding: ASCII-8BIT
78
+ string: !binary |-
79
+ W3sic3VjY2VzcyI6eyJjcmVhdGVkQXQiOiIyMDEzLTAxLTA1VDIyOjU1OjIx
80
+ LjA3NloiLCJvYmplY3RJZCI6Imh4dTVaeVdNZDgifX1d
81
+ http_version:
82
+ recorded_at: Sat, 05 Jan 2013 22:55:24 GMT
83
+ recorded_with: VCR 2.0.1
@@ -80,4 +80,76 @@ http_interactions:
80
80
  Y3RJZCI6IlJMTlVHakswek0ifQ==
81
81
  http_version:
82
82
  recorded_at: Sat, 05 Jan 2013 17:09:06 GMT
83
+ - request:
84
+ method: get
85
+ uri: https://api.parse.com/1/batch
86
+ body:
87
+ encoding: US-ASCII
88
+ string: ''
89
+ headers:
90
+ Content-Type:
91
+ - application/json
92
+ Accept:
93
+ - application/json
94
+ User-Agent:
95
+ - Parse for Ruby, 0.0
96
+ X-Parse-Master-Key:
97
+ - ''
98
+ X-Parse-Rest-Api-Key:
99
+ - D3Y8jNCQk6kpkKhpRGnWLYTrFGQ7j8dtDVnWZRnZ
100
+ X-Parse-Application-Id:
101
+ - PPVk6L5M9R1R8GVk8Ye9jT8f5SQNBIeoJUDJLmkT
102
+ X-Parse-Session-Token:
103
+ - ''
104
+ Expect:
105
+ - ''
106
+ response:
107
+ status:
108
+ code: 404
109
+ message: !binary |-
110
+ Tm90IEZvdW5k
111
+ headers:
112
+ !binary "Q29udGVudC1UeXBl":
113
+ - !binary |-
114
+ dGV4dC9odG1sOyBjaGFyc2V0PXV0Zi04
115
+ !binary "RGF0ZQ==":
116
+ - !binary |-
117
+ U2F0LCAwNSBKYW4gMjAxMyAyMjozNjo0MiBHTVQ=
118
+ !binary "U2VydmVy":
119
+ - !binary |-
120
+ bmdpbngvMS4yLjI=
121
+ !binary "U3RhdHVz":
122
+ - !binary |-
123
+ NDA0IE5vdCBGb3VuZA==
124
+ !binary "WC1SdW50aW1l":
125
+ - !binary |-
126
+ MC4wMDQwMzY=
127
+ !binary "Q29udGVudC1MZW5ndGg=":
128
+ - !binary |-
129
+ NzI4
130
+ !binary "Q29ubmVjdGlvbg==":
131
+ - !binary |-
132
+ a2VlcC1hbGl2ZQ==
133
+ body:
134
+ encoding: ASCII-8BIT
135
+ string: !binary |-
136
+ PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8aGVhZD4KICA8dGl0bGU+VGhlIHBh
137
+ Z2UgeW91IHdlcmUgbG9va2luZyBmb3IgZG9lc24ndCBleGlzdCAoNDA0KTwv
138
+ dGl0bGU+CiAgPHN0eWxlIHR5cGU9InRleHQvY3NzIj4KICAgIGJvZHkgeyBi
139
+ YWNrZ3JvdW5kLWNvbG9yOiAjZmZmOyBjb2xvcjogIzY2NjsgdGV4dC1hbGln
140
+ bjogY2VudGVyOyBmb250LWZhbWlseTogYXJpYWwsIHNhbnMtc2VyaWY7IH0K
141
+ ICAgIGRpdi5kaWFsb2cgewogICAgICB3aWR0aDogMjVlbTsKICAgICAgcGFk
142
+ ZGluZzogMCA0ZW07CiAgICAgIG1hcmdpbjogNGVtIGF1dG8gMCBhdXRvOwog
143
+ ICAgICBib3JkZXI6IDFweCBzb2xpZCAjY2NjOwogICAgICBib3JkZXItcmln
144
+ aHQtY29sb3I6ICM5OTk7CiAgICAgIGJvcmRlci1ib3R0b20tY29sb3I6ICM5
145
+ OTk7CiAgICB9CiAgICBoMSB7IGZvbnQtc2l6ZTogMTAwJTsgY29sb3I6ICNm
146
+ MDA7IGxpbmUtaGVpZ2h0OiAxLjVlbTsgfQogIDwvc3R5bGU+CjwvaGVhZD4K
147
+ Cjxib2R5PgogIDwhLS0gVGhpcyBmaWxlIGxpdmVzIGluIHB1YmxpYy80MDQu
148
+ aHRtbCAtLT4KICA8ZGl2IGNsYXNzPSJkaWFsb2ciPgogICAgPGgxPlRoZSBw
149
+ YWdlIHlvdSB3ZXJlIGxvb2tpbmcgZm9yIGRvZXNuJ3QgZXhpc3QuPC9oMT4K
150
+ ICAgIDxwPllvdSBtYXkgaGF2ZSBtaXN0eXBlZCB0aGUgYWRkcmVzcyBvciB0
151
+ aGUgcGFnZSBtYXkgaGF2ZSBtb3ZlZC48L3A+CiAgPC9kaXY+CjwvYm9keT4K
152
+ PC9odG1sPgo=
153
+ http_version:
154
+ recorded_at: Sat, 05 Jan 2013 22:36:45 GMT
83
155
  recorded_with: VCR 2.0.1
@@ -24,4 +24,5 @@ require 'parse/protocol'
24
24
  require 'parse/user'
25
25
  require 'parse/push'
26
26
  require 'parse/cloud'
27
- require 'parse/model'
27
+ require 'parse/model'
28
+ require 'parse/batch'
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+
3
+ module Parse
4
+ class Batch
5
+ attr_reader :requests
6
+
7
+ def initialize
8
+ @requests ||= []
9
+ end
10
+
11
+ def add_request(request)
12
+ @requests << request
13
+ end
14
+
15
+ def run!
16
+ uri = Parse::Protocol.batch_request_uri
17
+ body = {:requests => @requests}.to_json
18
+ Parse.client.request(uri, :post, body)
19
+ end
20
+ end
21
+ end
@@ -122,6 +122,8 @@ module Parse
122
122
 
123
123
  CLOUD_FUNCTIONS_PATH = "functions"
124
124
 
125
+ BATCH_REQUEST_URI = "batch"
126
+
125
127
  # URI Helpers
126
128
  # ----------------------------------------
127
129
 
@@ -159,5 +161,9 @@ module Parse
159
161
  def Protocol.cloud_function_uri(function_name)
160
162
  "/#{VERSION}/#{CLOUD_FUNCTIONS_PATH}/#{function_name}"
161
163
  end
164
+
165
+ def Protocol.batch_request_uri
166
+ "/#{VERSION}/#{BATCH_REQUEST_URI}"
167
+ end
162
168
  end
163
169
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "parse-ruby-client"
8
- s.version = "0.1.7"
8
+ s.version = "0.1.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alan deLevie", "Adam Alpern"]
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "example.rb",
28
28
  "fixtures/vcr_cassettes/test_array_add.yml",
29
+ "fixtures/vcr_cassettes/test_batch_run.yml",
29
30
  "fixtures/vcr_cassettes/test_cloud_function.yml",
30
31
  "fixtures/vcr_cassettes/test_created_at.yml",
31
32
  "fixtures/vcr_cassettes/test_deep_parse.yml",
@@ -43,6 +44,7 @@ Gem::Specification.new do |s|
43
44
  "fixtures/vcr_cassettes/test_updated_at.yml",
44
45
  "fixtures/vcr_cassettes/test_user_save.yml",
45
46
  "lib/parse-ruby-client.rb",
47
+ "lib/parse/batch.rb",
46
48
  "lib/parse/client.rb",
47
49
  "lib/parse/cloud.rb",
48
50
  "lib/parse/datatypes.rb",
@@ -58,6 +60,7 @@ Gem::Specification.new do |s|
58
60
  "test/cloud_functions/MyCloudCode/cloud/main.js",
59
61
  "test/config/global.json",
60
62
  "test/helper.rb",
63
+ "test/test_batch.rb",
61
64
  "test/test_client.rb",
62
65
  "test/test_cloud.rb",
63
66
  "test/test_datatypes.rb",
@@ -0,0 +1,59 @@
1
+ require 'helper'
2
+
3
+ class TestBatch < Test::Unit::TestCase
4
+ def setup
5
+ Parse.init
6
+ end
7
+
8
+ def test_initialize
9
+ batch = Parse::Batch.new
10
+ assert_equal batch.class, Parse::Batch
11
+ end
12
+
13
+ def test_add_request
14
+ batch = Parse::Batch.new
15
+ batch.add_request({
16
+ :method => "POST",
17
+ :path => "/1/classes/GameScore",
18
+ :body => {
19
+ :score => 1337,
20
+ :playerName => "Sean Plott"
21
+ }
22
+ })
23
+ batch.add_request({
24
+ :method => "POST",
25
+ :path => "/1/classes/GameScore",
26
+ :body => {
27
+ :score => 1338,
28
+ :playerName => "ZeroCool"
29
+ }
30
+ })
31
+ assert_equal batch.requests.class, Array
32
+ assert_equal batch.requests.length, 2
33
+ assert_equal batch.requests.first[:path], "/1/classes/GameScore"
34
+ end
35
+
36
+ def test_protocol_uri
37
+ uri = Parse::Protocol.batch_request_uri
38
+ assert_equal uri, "/1/batch"
39
+ end
40
+
41
+ def test_run
42
+ VCR.use_cassette('test_batch_run', :record => :new_episodes) do
43
+ batch = Parse::Batch.new
44
+ batch.add_request({
45
+ "method" => "POST",
46
+ "path" => "/1/classes/GameScore",
47
+ "body" => {
48
+ "score" => 1337,
49
+ "playerName" => "Sean Plott"
50
+ }
51
+ })
52
+ resp = batch.run!
53
+ assert_equal resp.length, batch.requests.length
54
+ assert resp.first["success"]
55
+ assert_equal resp.first["success"]["objectId"].class, String
56
+ end
57
+ end
58
+
59
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -173,6 +173,7 @@ files:
173
173
  - VERSION
174
174
  - example.rb
175
175
  - fixtures/vcr_cassettes/test_array_add.yml
176
+ - fixtures/vcr_cassettes/test_batch_run.yml
176
177
  - fixtures/vcr_cassettes/test_cloud_function.yml
177
178
  - fixtures/vcr_cassettes/test_created_at.yml
178
179
  - fixtures/vcr_cassettes/test_deep_parse.yml
@@ -190,6 +191,7 @@ files:
190
191
  - fixtures/vcr_cassettes/test_updated_at.yml
191
192
  - fixtures/vcr_cassettes/test_user_save.yml
192
193
  - lib/parse-ruby-client.rb
194
+ - lib/parse/batch.rb
193
195
  - lib/parse/client.rb
194
196
  - lib/parse/cloud.rb
195
197
  - lib/parse/datatypes.rb
@@ -205,6 +207,7 @@ files:
205
207
  - test/cloud_functions/MyCloudCode/cloud/main.js
206
208
  - test/config/global.json
207
209
  - test/helper.rb
210
+ - test/test_batch.rb
208
211
  - test/test_client.rb
209
212
  - test/test_cloud.rb
210
213
  - test/test_datatypes.rb
@@ -230,7 +233,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
233
  version: '0'
231
234
  segments:
232
235
  - 0
233
- hash: -55766238074805369
236
+ hash: 3206718523214024845
234
237
  required_rubygems_version: !ruby/object:Gem::Requirement
235
238
  none: false
236
239
  requirements: