parsecom 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +58 -6
- data/lib/parse/batch.rb +37 -0
- data/lib/parse/batch_http_client.rb +22 -0
- data/lib/parse/client.rb +15 -14
- data/lib/parse/http_client.rb +3 -1
- data/lib/parse/object.rb +6 -6
- data/lib/parse/op/add.rb +13 -0
- data/lib/parse/op/add_relation.rb +13 -0
- data/lib/parse/op/add_unique.rb +13 -0
- data/lib/parse/op/delete.rb +9 -0
- data/lib/parse/op/increment.rb +13 -0
- data/lib/parse/op/remove.rb +13 -0
- data/lib/parse/op/remove_relation.rb +13 -0
- data/lib/parse/relation.rb +1 -1
- data/lib/parse/version.rb +1 -1
- data/lib/parsecom.rb +9 -0
- data/spec/fixtures/vcr_cassettes/batch.yml +109 -0
- data/spec/fixtures/vcr_cassettes/object_increment.yml +109 -0
- data/spec/parse_batch_spec.rb +26 -0
- data/spec/parse_object_spec.rb +21 -0
- metadata +17 -2
data/README.md
CHANGED
@@ -87,12 +87,12 @@ another is using Parse::Object as a facade of a query object.
|
|
87
87
|
# useing Query object directly
|
88
88
|
query = Parse::Query.new GameScore
|
89
89
|
query.where :objectId => 'Ed1nuqPvcm'
|
90
|
-
results = query.
|
90
|
+
results = query.run
|
91
91
|
|
92
92
|
# using Query object through Parse::Object
|
93
93
|
results = GameScore.find :where => {:objectId => 'Ed1nuqPvcm'}
|
94
94
|
# if you would like to find by objectId, you can easily pass it directly
|
95
|
-
result = GameScore.
|
95
|
+
result = GameScore.find_by_id 'Ed1nuqPvcm'
|
96
96
|
```
|
97
97
|
|
98
98
|
More complex query
|
@@ -123,9 +123,9 @@ To know more about retrieving objects, see spec/parse_query_spec.rb
|
|
123
123
|
To update attributes, just update the attribute and save.
|
124
124
|
|
125
125
|
```ruby
|
126
|
-
|
127
|
-
|
128
|
-
|
126
|
+
game_score = GameScore.find_by_id 'Ed1nuqPvcm'
|
127
|
+
game_score.score = 73453
|
128
|
+
game_score.save
|
129
129
|
```
|
130
130
|
|
131
131
|
If you want to update attributes without retrieving the object, you can use
|
@@ -135,9 +135,61 @@ the Parse::Client object for it.
|
|
135
135
|
Parse::Client.default.update :GaemScore, 'Ed1nuqPvcm', :score => 73453
|
136
136
|
```
|
137
137
|
|
138
|
+
#### Counters
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
game_score = GameScore.find_by_id 'Ed1nuqPvcm'
|
142
|
+
game_score.score = Parse::Op::Increment.new 1
|
143
|
+
game_score.save
|
144
|
+
```
|
145
|
+
|
146
|
+
#### Arrays
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
game_score = GameScore.find_by_id 'Ed1nuqPvcm'
|
150
|
+
game_score.skils = Parse::Op::AddUnique.new 'flying', 'kungfu'
|
151
|
+
game_score.save
|
152
|
+
```
|
153
|
+
|
154
|
+
#### Relations
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
game_score = GameScore.find_by_id 'Ed1nuqPvcm'
|
158
|
+
game_score.opponents = Parse::Op::AddRelation.new player.pointer
|
159
|
+
game_score.save
|
160
|
+
```
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
game_score = GameScore.find_by_id 'Ed1nuqPvcm'
|
164
|
+
game_score.opponents = Parse::Op::RemoveRelation.new player.pointer
|
165
|
+
game_score.save
|
166
|
+
```
|
167
|
+
|
138
168
|
### Deleting Objects
|
139
169
|
|
140
|
-
|
170
|
+
```ruby
|
171
|
+
game_score = GameScore.find_by_id 'Ed1nuqPvcm'
|
172
|
+
game_score.delete
|
173
|
+
```
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
game_score = GameScore.find_by_id 'Ed1nuqPvcm'
|
177
|
+
game_score.opponents = Parse::Op::Delete.new
|
178
|
+
game_score.save
|
179
|
+
```
|
180
|
+
|
181
|
+
### Batch Operations
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
seans_score = GameScore.new 'score' => 1337, 'playerName' => 'Sean Plott'
|
185
|
+
zerocools_score = GameScore.new 'score' => 1338, 'playerName' => 'ZeroCool'
|
186
|
+
batch = Parse::Batch.new
|
187
|
+
batch.add_request do
|
188
|
+
seans_score.save
|
189
|
+
zerocools_score.save
|
190
|
+
end
|
191
|
+
result = batch.run
|
192
|
+
```
|
141
193
|
|
142
194
|
### Sign up
|
143
195
|
|
data/lib/parse/batch.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Parse
|
2
|
+
class Batch
|
3
|
+
def initialize &block
|
4
|
+
@blocks = []
|
5
|
+
@blocks << block if block
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_request &block
|
9
|
+
@blocks << block if block
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
default_client = Parse::Client.default
|
14
|
+
default_http_client = default_client.http_client
|
15
|
+
batch_http_client = Parse::BatchHttpClient.new default_http_client.host
|
16
|
+
default_client.http_client = batch_http_client
|
17
|
+
begin
|
18
|
+
@blocks.map &:call
|
19
|
+
ensure
|
20
|
+
default_client.http_client = default_http_client
|
21
|
+
end
|
22
|
+
|
23
|
+
default_client.call_api :post, 'batch', %Q|{"requests":#{batch_http_client.requests.to_json}}| do |responses|
|
24
|
+
responses.each.with_index do |r, i|
|
25
|
+
if after_block = batch_http_client.after_blocks[i]
|
26
|
+
if r['success']
|
27
|
+
after_block.call r['success']
|
28
|
+
elsif r['error']
|
29
|
+
# do something
|
30
|
+
raise StandardError.new(r['error'].to_s)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Parse
|
2
|
+
class BatchHttpClient < HttpClient
|
3
|
+
attr_accessor :requests, :after_blocks
|
4
|
+
|
5
|
+
def initialize host
|
6
|
+
@host = host
|
7
|
+
@requests = []
|
8
|
+
@after_blocks = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def request method, endpoint, headers={}, body=nil, &block
|
12
|
+
raise 'find cannot be in a batch request.' if method.to_s.upcase == 'GET'
|
13
|
+
|
14
|
+
@after_blocks << block
|
15
|
+
@requests << {
|
16
|
+
"method" => method.to_s.upcase,
|
17
|
+
"path" => endpoint,
|
18
|
+
"body" => JSON.parse(body) # TODO: ??
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/parse/client.rb
CHANGED
@@ -11,6 +11,10 @@ module Parse
|
|
11
11
|
@@default_client ||= new
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.default= default_client
|
15
|
+
@@default_client = default_client
|
16
|
+
end
|
17
|
+
|
14
18
|
def initialize application_id=nil, api_key=nil, master_key=nil, http_client=nil
|
15
19
|
@application_id = application_id || Parse.application_id
|
16
20
|
@api_key = api_key || Parse.api_key
|
@@ -126,22 +130,16 @@ module Parse
|
|
126
130
|
query.invoke
|
127
131
|
end
|
128
132
|
|
129
|
-
def create parse_class_name, values
|
130
|
-
call_api :post, "classes/#{parse_class_name}", values.to_json
|
131
|
-
resp_body
|
132
|
-
end
|
133
|
+
def create parse_class_name, values, &block
|
134
|
+
call_api :post, "classes/#{parse_class_name}", values.to_json, &block
|
133
135
|
end
|
134
136
|
|
135
|
-
def update parse_class_name, parse_object_id, values
|
136
|
-
call_api :put, "classes/#{parse_class_name}/#{parse_object_id}", values.to_json
|
137
|
-
resp_body
|
138
|
-
end
|
137
|
+
def update parse_class_name, parse_object_id, values, &block
|
138
|
+
call_api :put, "classes/#{parse_class_name}/#{parse_object_id}", values.to_json, &block
|
139
139
|
end
|
140
140
|
|
141
|
-
def delete parse_class_name, parse_object_id
|
142
|
-
call_api :delete, "classes/#{parse_class_name}/#{parse_object_id}"
|
143
|
-
resp_body
|
144
|
-
end
|
141
|
+
def delete parse_class_name, parse_object_id, &block
|
142
|
+
call_api :delete, "classes/#{parse_class_name}/#{parse_object_id}", &block
|
145
143
|
end
|
146
144
|
|
147
145
|
def call_function name, param
|
@@ -168,8 +166,11 @@ module Parse
|
|
168
166
|
return @use_master_key unless block
|
169
167
|
|
170
168
|
tmp, @use_master_key = @use_master_key, true
|
171
|
-
|
172
|
-
|
169
|
+
begin
|
170
|
+
ret = block.call
|
171
|
+
ensure
|
172
|
+
@use_master_key = tmp
|
173
|
+
end
|
173
174
|
ret
|
174
175
|
end
|
175
176
|
|
data/lib/parse/http_client.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# coding:utf-8
|
2
2
|
module Parse
|
3
3
|
class HttpClient
|
4
|
+
attr_accessor :host
|
5
|
+
|
4
6
|
def initialize host
|
5
7
|
@host = host
|
6
8
|
end
|
@@ -15,7 +17,7 @@ module Parse
|
|
15
17
|
resp = client.request req
|
16
18
|
resp_body = JSON.parse resp.body
|
17
19
|
raise StandardError.new "error calling #{endpoint}: #{
|
18
|
-
resp_body['error']}" if resp_body.has_key?
|
20
|
+
resp_body['error']}" if resp_body.is_a?(Hash) && resp_body.has_key?('error')
|
19
21
|
block.call resp_body if block
|
20
22
|
end
|
21
23
|
end
|
data/lib/parse/object.rb
CHANGED
@@ -146,7 +146,7 @@ module Parse
|
|
146
146
|
hash = string_keyed_hash hash
|
147
147
|
@updated_hash.update hash
|
148
148
|
method = use_master_key ? :create! : :create
|
149
|
-
parse_client.send(method, self.parse_class_name, @updated_hash)
|
149
|
+
parse_client.send(method, self.parse_class_name, @updated_hash) do |response|
|
150
150
|
@parse_object_id = response['objectId']
|
151
151
|
@created_at = Date.parse response['createdAt']
|
152
152
|
@updated_at = @created_at
|
@@ -163,11 +163,11 @@ module Parse
|
|
163
163
|
def update hash, use_master_key=false
|
164
164
|
check_deleted!
|
165
165
|
hash = string_keyed_hash hash
|
166
|
-
#parse_client.update(self, hash).tap do |response|
|
167
166
|
method = use_master_key ? :update! : :update
|
168
|
-
parse_client.send(method, parse_class_name, parse_object_id, hash)
|
169
|
-
@updated_at = Date.parse response['updatedAt']
|
167
|
+
parse_client.send(method, parse_class_name, parse_object_id, hash) do |response|
|
170
168
|
@raw_hash.update @updated_hash
|
169
|
+
@raw_hash.update response
|
170
|
+
@updated_at = Date.parse response['updatedAt']
|
171
171
|
@updated_hash.clear
|
172
172
|
end
|
173
173
|
end
|
@@ -180,7 +180,7 @@ module Parse
|
|
180
180
|
raise 'You cannot delete new object' if new?
|
181
181
|
check_deleted!
|
182
182
|
method = use_master_key ? :delete! : :delete
|
183
|
-
parse_client.send(method, parse_class_name, parse_object_id)
|
183
|
+
parse_client.send(method, parse_class_name, parse_object_id) do |response|
|
184
184
|
@deleted = true
|
185
185
|
end
|
186
186
|
end
|
@@ -216,7 +216,7 @@ module Parse
|
|
216
216
|
@updated_hash[name] = value
|
217
217
|
end
|
218
218
|
|
219
|
-
def
|
219
|
+
def pointer
|
220
220
|
Pointer.new 'className' => parse_class_name, 'objectId' => parse_object_id
|
221
221
|
end
|
222
222
|
|
data/lib/parse/op/add.rb
ADDED
data/lib/parse/relation.rb
CHANGED
@@ -9,7 +9,7 @@ module Parse
|
|
9
9
|
|
10
10
|
def load parse_client=Parse::Client.default
|
11
11
|
unless @objects
|
12
|
-
pointer = @parent_object.
|
12
|
+
pointer = @parent_object.pointer
|
13
13
|
key = @column_name
|
14
14
|
related_class = Parse::Object @raw_hash['className']
|
15
15
|
@objects = related_class.find :where => proc {
|
data/lib/parse/version.rb
CHANGED
data/lib/parsecom.rb
CHANGED
@@ -18,6 +18,15 @@ require 'parse/installation'
|
|
18
18
|
require 'parse/pointer'
|
19
19
|
require 'parse/relation'
|
20
20
|
require 'parse/file'
|
21
|
+
require 'parse/op/increment'
|
22
|
+
require 'parse/op/add'
|
23
|
+
require 'parse/op/add_unique'
|
24
|
+
require 'parse/op/remove'
|
25
|
+
require 'parse/op/add_relation'
|
26
|
+
require 'parse/op/remove_relation'
|
27
|
+
require 'parse/op/delete'
|
28
|
+
require 'parse/batch'
|
29
|
+
require 'parse/batch_http_client'
|
21
30
|
|
22
31
|
module Parse
|
23
32
|
@@application_id = ENV['PARSE_APPLICATION_ID']
|
@@ -0,0 +1,109 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.parse.com/1/classes/ClassA?limit=1
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
X-Parse-Application-Id:
|
11
|
+
- <X-Parse-Application-Id>
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept:
|
15
|
+
- application/json
|
16
|
+
User-Agent:
|
17
|
+
- A parse.com client for ruby
|
18
|
+
X-Parse-Rest-Api-Key:
|
19
|
+
- <X-Parse-REST-API-Key>
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Access-Control-Allow-Origin:
|
26
|
+
- ! '*'
|
27
|
+
Access-Control-Request-Method:
|
28
|
+
- ! '*'
|
29
|
+
Cache-Control:
|
30
|
+
- max-age=0, private, must-revalidate
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Date:
|
34
|
+
- Tue, 15 Oct 2013 12:50:22 GMT
|
35
|
+
Etag:
|
36
|
+
- ! '"e305fd3b81a57c52f61e6ae93b8eda1f"'
|
37
|
+
Server:
|
38
|
+
- nginx/1.4.2
|
39
|
+
Set-Cookie:
|
40
|
+
- <COOKIE-KEY>
|
41
|
+
Status:
|
42
|
+
- 200 OK
|
43
|
+
X-Runtime:
|
44
|
+
- '0.124765'
|
45
|
+
X-Ua-Compatible:
|
46
|
+
- IE=Edge,chrome=1
|
47
|
+
Content-Length:
|
48
|
+
- '252'
|
49
|
+
Connection:
|
50
|
+
- keep-alive
|
51
|
+
body:
|
52
|
+
encoding: US-ASCII
|
53
|
+
string: ! '{"results":[{"columnA":"Hello, parse.com","columnD":{"__type":"Relation","className":"ClassB"},"columnC":{"__type":"Relation","className":"ClassB"},"createdAt":"2013-10-04T04:25:12.585Z","updatedAt":"2013-10-04T04:25:12.585Z","objectId":"4Ks88ukAUE"}]}'
|
54
|
+
http_version:
|
55
|
+
recorded_at: Tue, 15 Oct 2013 12:50:22 GMT
|
56
|
+
- request:
|
57
|
+
method: post
|
58
|
+
uri: https://api.parse.com/1/batch
|
59
|
+
body:
|
60
|
+
encoding: US-ASCII
|
61
|
+
string: ! '{"requests":[{"method":"POST","path":"/1/classes/ClassA","body":{"columnA":"hello"}},{"method":"POST","path":"/1/classes/ClassA","body":{"columnA":"world"}},{"method":"PUT","path":"/1/classes/ClassA/4Ks88ukAUE","body":{"columnA":"updated!"}}]}'
|
62
|
+
headers:
|
63
|
+
X-Parse-Application-Id:
|
64
|
+
- <X-Parse-Application-Id>
|
65
|
+
Content-Type:
|
66
|
+
- application/json
|
67
|
+
Accept:
|
68
|
+
- application/json
|
69
|
+
User-Agent:
|
70
|
+
- A parse.com client for ruby
|
71
|
+
X-Parse-Rest-Api-Key:
|
72
|
+
- <X-Parse-REST-API-Key>
|
73
|
+
response:
|
74
|
+
status:
|
75
|
+
code: 200
|
76
|
+
message: OK
|
77
|
+
headers:
|
78
|
+
Access-Control-Allow-Origin:
|
79
|
+
- ! '*'
|
80
|
+
Access-Control-Request-Method:
|
81
|
+
- ! '*'
|
82
|
+
Cache-Control:
|
83
|
+
- max-age=0, private, must-revalidate
|
84
|
+
Content-Type:
|
85
|
+
- application/json; charset=utf-8
|
86
|
+
Date:
|
87
|
+
- Tue, 15 Oct 2013 12:50:23 GMT
|
88
|
+
Etag:
|
89
|
+
- ! '"2d26115f97cbd8d4143d8fb6e9a0b296"'
|
90
|
+
Server:
|
91
|
+
- nginx/1.4.2
|
92
|
+
Set-Cookie:
|
93
|
+
- <COOKIE-KEY>
|
94
|
+
Status:
|
95
|
+
- 200 OK
|
96
|
+
X-Runtime:
|
97
|
+
- '0.154472'
|
98
|
+
X-Ua-Compatible:
|
99
|
+
- IE=Edge,chrome=1
|
100
|
+
Content-Length:
|
101
|
+
- '208'
|
102
|
+
Connection:
|
103
|
+
- keep-alive
|
104
|
+
body:
|
105
|
+
encoding: US-ASCII
|
106
|
+
string: ! '[{"success":{"createdAt":"2013-10-15T12:50:23.934Z","objectId":"za4TGQV39W"}},{"success":{"createdAt":"2013-10-15T12:50:23.951Z","objectId":"Y3ypX9OJ0v"}},{"success":{"updatedAt":"2013-10-15T12:50:23.977Z"}}]'
|
107
|
+
http_version:
|
108
|
+
recorded_at: Tue, 15 Oct 2013 12:50:24 GMT
|
109
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,109 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.parse.com/1/classes/ClassA?limit=1
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
X-Parse-Application-Id:
|
11
|
+
- <X-Parse-Application-Id>
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept:
|
15
|
+
- application/json
|
16
|
+
User-Agent:
|
17
|
+
- A parse.com client for ruby
|
18
|
+
X-Parse-Rest-Api-Key:
|
19
|
+
- <X-Parse-REST-API-Key>
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Access-Control-Allow-Origin:
|
26
|
+
- ! '*'
|
27
|
+
Access-Control-Request-Method:
|
28
|
+
- ! '*'
|
29
|
+
Cache-Control:
|
30
|
+
- max-age=0, private, must-revalidate
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Date:
|
34
|
+
- Sun, 13 Oct 2013 08:48:13 GMT
|
35
|
+
Etag:
|
36
|
+
- ! '"21f1d56465316b4627e035fe84754e22"'
|
37
|
+
Server:
|
38
|
+
- nginx/1.4.2
|
39
|
+
Set-Cookie:
|
40
|
+
- <COOKIE-KEY>
|
41
|
+
Status:
|
42
|
+
- 200 OK
|
43
|
+
X-Runtime:
|
44
|
+
- '0.051473'
|
45
|
+
X-Ua-Compatible:
|
46
|
+
- IE=Edge,chrome=1
|
47
|
+
Content-Length:
|
48
|
+
- '199'
|
49
|
+
Connection:
|
50
|
+
- keep-alive
|
51
|
+
body:
|
52
|
+
encoding: US-ASCII
|
53
|
+
string: ! '{"results":[{"columnA":"Hello, parse.com","columnD":{"__type":"Relation","className":"ClassB"},"createdAt":"2013-10-04T04:24:31.089Z","updatedAt":"2013-10-04T04:24:31.089Z","objectId":"OGKnxa5IiZ"}]}'
|
54
|
+
http_version:
|
55
|
+
recorded_at: Sun, 13 Oct 2013 08:48:15 GMT
|
56
|
+
- request:
|
57
|
+
method: put
|
58
|
+
uri: https://api.parse.com/1/classes/ClassA/OGKnxa5IiZ
|
59
|
+
body:
|
60
|
+
encoding: UTF-8
|
61
|
+
string: ! '{"columnB":{"__op":"Increment","amount":1}}'
|
62
|
+
headers:
|
63
|
+
X-Parse-Application-Id:
|
64
|
+
- <X-Parse-Application-Id>
|
65
|
+
Content-Type:
|
66
|
+
- application/json
|
67
|
+
Accept:
|
68
|
+
- application/json
|
69
|
+
User-Agent:
|
70
|
+
- A parse.com client for ruby
|
71
|
+
X-Parse-Rest-Api-Key:
|
72
|
+
- <X-Parse-REST-API-Key>
|
73
|
+
response:
|
74
|
+
status:
|
75
|
+
code: 200
|
76
|
+
message: OK
|
77
|
+
headers:
|
78
|
+
Access-Control-Allow-Origin:
|
79
|
+
- ! '*'
|
80
|
+
Access-Control-Request-Method:
|
81
|
+
- ! '*'
|
82
|
+
Cache-Control:
|
83
|
+
- max-age=0, private, must-revalidate
|
84
|
+
Content-Type:
|
85
|
+
- application/json; charset=utf-8
|
86
|
+
Date:
|
87
|
+
- Sun, 13 Oct 2013 08:48:14 GMT
|
88
|
+
Etag:
|
89
|
+
- ! '"89006920f12e748cde369d09a7b90cd5"'
|
90
|
+
Server:
|
91
|
+
- nginx/1.4.2
|
92
|
+
Set-Cookie:
|
93
|
+
- <COOKIE-KEY>
|
94
|
+
Status:
|
95
|
+
- 200 OK
|
96
|
+
X-Runtime:
|
97
|
+
- '0.045789'
|
98
|
+
X-Ua-Compatible:
|
99
|
+
- IE=Edge,chrome=1
|
100
|
+
Content-Length:
|
101
|
+
- '52'
|
102
|
+
Connection:
|
103
|
+
- keep-alive
|
104
|
+
body:
|
105
|
+
encoding: US-ASCII
|
106
|
+
string: ! '{"columnB":1,"updatedAt":"2013-10-13T08:48:14.448Z"}'
|
107
|
+
http_version:
|
108
|
+
recorded_at: Sun, 13 Oct 2013 08:48:16 GMT
|
109
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding:utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'parsecom'
|
4
|
+
|
5
|
+
describe Parse::Batch, 'when executing a batch request' do
|
6
|
+
it 'should be success' do
|
7
|
+
VCR.use_cassette 'batch' do
|
8
|
+
a1 = ClassA.new 'columnA' => 'hello'
|
9
|
+
a2 = ClassA.new 'columnA' => 'world'
|
10
|
+
a3 = ClassA.find(:all, :limit =>1).first
|
11
|
+
a3.columnA = 'updated!'
|
12
|
+
a3_updated_at = a3.updatedAt
|
13
|
+
batch = Parse::Batch.new
|
14
|
+
batch.add_request do
|
15
|
+
a1.save
|
16
|
+
a2.save
|
17
|
+
a3.save
|
18
|
+
end
|
19
|
+
batch.run
|
20
|
+
a1.parse_object_id.should_not be_nil
|
21
|
+
a2.parse_object_id.should_not be_nil
|
22
|
+
a3.columnA.should == 'updated!'
|
23
|
+
a3.updatedAt.should_not == a3_updated_at
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/parse_object_spec.rb
CHANGED
@@ -60,3 +60,24 @@ describe Parse::Object, 'when it creates a new parse object' do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
describe Parse::Object, 'when it updates an existing parse object' do
|
64
|
+
it 'should increment a field' do
|
65
|
+
VCR.use_cassette 'object_increment' do
|
66
|
+
class_a = ClassA.find(:all, :limit =>1).first
|
67
|
+
val = class_a.columnB || 0
|
68
|
+
class_a.columnB = Parse::Op::Increment.new 1
|
69
|
+
class_a.save
|
70
|
+
class_a.columnB.should == (val + 1)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# it 'should add unique objects to an array field' do
|
75
|
+
# VCR.use_cassette 'object_add_unique' do
|
76
|
+
# class_a = ClassA.find(:all, :limit =>1).first
|
77
|
+
# size = class_a.columnF.size
|
78
|
+
# class_a.columnF = Parse::Op::AddUnique.new 'flying', 'kungfu'
|
79
|
+
# class_a.save
|
80
|
+
# class_a.columnF.size.should == (size + 2)
|
81
|
+
# end
|
82
|
+
# end
|
83
|
+
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -72,6 +72,8 @@ files:
|
|
72
72
|
- LICENSE.txt
|
73
73
|
- README.md
|
74
74
|
- Rakefile
|
75
|
+
- lib/parse/batch.rb
|
76
|
+
- lib/parse/batch_http_client.rb
|
75
77
|
- lib/parse/client.rb
|
76
78
|
- lib/parse/cloud_code.rb
|
77
79
|
- lib/parse/ext/string.rb
|
@@ -79,6 +81,13 @@ files:
|
|
79
81
|
- lib/parse/http_client.rb
|
80
82
|
- lib/parse/installation.rb
|
81
83
|
- lib/parse/object.rb
|
84
|
+
- lib/parse/op/add.rb
|
85
|
+
- lib/parse/op/add_relation.rb
|
86
|
+
- lib/parse/op/add_unique.rb
|
87
|
+
- lib/parse/op/delete.rb
|
88
|
+
- lib/parse/op/increment.rb
|
89
|
+
- lib/parse/op/remove.rb
|
90
|
+
- lib/parse/op/remove_relation.rb
|
82
91
|
- lib/parse/pointer.rb
|
83
92
|
- lib/parse/query.rb
|
84
93
|
- lib/parse/relation.rb
|
@@ -87,11 +96,14 @@ files:
|
|
87
96
|
- lib/parse/version.rb
|
88
97
|
- lib/parsecom.rb
|
89
98
|
- parsecom.gemspec
|
99
|
+
- spec/fixtures/vcr_cassettes/batch.yml
|
90
100
|
- spec/fixtures/vcr_cassettes/object_find.yml
|
101
|
+
- spec/fixtures/vcr_cassettes/object_increment.yml
|
91
102
|
- spec/fixtures/vcr_cassettes/object_new.yml
|
92
103
|
- spec/fixtures/vcr_cassettes/user_find.yml
|
93
104
|
- spec/fixtures/vcr_cassettes/user_log_in.yml
|
94
105
|
- spec/fixtures/vcr_cassettes/user_sign_up.yml
|
106
|
+
- spec/parse_batch_spec.rb
|
95
107
|
- spec/parse_client_spec.rb
|
96
108
|
- spec/parse_object_spec.rb
|
97
109
|
- spec/parse_query_spec.rb
|
@@ -123,11 +135,14 @@ signing_key:
|
|
123
135
|
specification_version: 3
|
124
136
|
summary: Pure Ruby version of parse.com client
|
125
137
|
test_files:
|
138
|
+
- spec/fixtures/vcr_cassettes/batch.yml
|
126
139
|
- spec/fixtures/vcr_cassettes/object_find.yml
|
140
|
+
- spec/fixtures/vcr_cassettes/object_increment.yml
|
127
141
|
- spec/fixtures/vcr_cassettes/object_new.yml
|
128
142
|
- spec/fixtures/vcr_cassettes/user_find.yml
|
129
143
|
- spec/fixtures/vcr_cassettes/user_log_in.yml
|
130
144
|
- spec/fixtures/vcr_cassettes/user_sign_up.yml
|
145
|
+
- spec/parse_batch_spec.rb
|
131
146
|
- spec/parse_client_spec.rb
|
132
147
|
- spec/parse_object_spec.rb
|
133
148
|
- spec/parse_query_spec.rb
|