parse-ruby-client 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -16,4 +16,5 @@ group :development do
16
16
  gem "vcr"
17
17
  end
18
18
 
19
- gem "patron"
19
+ gem "patron"
20
+ gem "iron_mq"
data/Gemfile.lock CHANGED
@@ -4,16 +4,27 @@ GEM
4
4
  addressable (2.3.2)
5
5
  crack (0.3.1)
6
6
  git (1.2.5)
7
+ iron_core (0.5.1)
8
+ rest (>= 2.2.0)
9
+ iron_mq (2.1.3)
10
+ iron_core (>= 0.4.2)
7
11
  jeweler (1.6.4)
8
12
  bundler (~> 1.0)
9
13
  git (>= 1.2.5)
10
14
  rake
11
15
  metaclass (0.0.1)
16
+ mime-types (1.20.1)
12
17
  mocha (0.12.0)
13
18
  metaclass (~> 0.0.1)
19
+ net-http-persistent (2.8)
14
20
  patron (0.4.17)
15
21
  rake (0.9.2.2)
16
22
  rcov (0.9.11)
23
+ rest (2.2.0)
24
+ net-http-persistent
25
+ rest-client (>= 0.3.0)
26
+ rest-client (1.6.7)
27
+ mime-types (>= 1.16)
17
28
  shoulda (2.11.3)
18
29
  test-unit (2.5.0)
19
30
  vcr (2.0.1)
@@ -26,6 +37,7 @@ PLATFORMS
26
37
 
27
38
  DEPENDENCIES
28
39
  bundler (~> 1.1.5)
40
+ iron_mq
29
41
  jeweler (~> 1.6.4)
30
42
  mocha (= 0.12.0)
31
43
  patron
data/README.md CHANGED
@@ -1,6 +1,25 @@
1
- [![Build Status](https://secure.travis-ci.org/adelevie/parse-ruby-client.png?branch=master)](http://travis-ci.org/adelevie/parse-ruby-client)
2
-
3
- The original creator of parse-ruby-client, [aalpern](http://github.com/aalpern), has decided to stop work on the project. I'm going to give the project new life, first by maintaining the project as a gem, and second by eventually making it power [parse_resource](http://github.com/adelevie/parse_resource) under the hood.
1
+ **Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
2
+
3
+ - [Ruby Client for parse.com REST API](#ruby-client-for-parsecom-rest-api)
4
+ - [Dependencies](#dependencies)
5
+ - [Getting Started](#getting-started)
6
+ - [Installation](#installation)
7
+ - [Load API keys from `global.json` created by Cloud Code](#load-api-keys-from-globaljson-created-by-cloud-code)
8
+ - [Creating and Saving Objects](#creating-and-saving-objects)
9
+ - [ActiveRecord-style Models](#activerecord-style-models)
10
+ - [Retrieving Objects](#retrieving-objects)
11
+ - [Queries](#queries)
12
+ - [Create some simple objects to query](#create-some-simple-objects-to-query)
13
+ - [Retrieve all scores between 10 & 20 inclusive](#retrieve-all-scores-between-10-&-20-inclusive)
14
+ - [Retrieve a set of specific scores](#retrieve-a-set-of-specific-scores)
15
+ - [Relational Data](#relational-data)
16
+ - [Push Notifications](#push-notifications)
17
+ - [Batch Requests](#batch-requests)
18
+ - [Cloud Code](#cloud-code)
19
+ - [assumes you have a function named "trivial"](#assumes-you-have-a-function-named-"trivial")
20
+ - [TODO](#todo)
21
+ - [Resources](#resources)
22
+ - [](#)
4
23
 
5
24
  # Ruby Client for parse.com REST API
6
25
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.12
1
+ 0.1.13
data/features.md CHANGED
@@ -1,3 +1,66 @@
1
+ **Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
2
+
3
+ - [Summary](#summary)
4
+ - [Quick Reference](#quick-reference)
5
+ - [Installation](#installation)
6
+ - [Configuration](#configuration)
7
+ - [Objects](#objects)
8
+ - [Creating Objects](#creating-objects)
9
+ - [Retrieving Objects](#retrieving-objects)
10
+ - [Updating Objects](#updating-objects)
11
+ - [Counters](#counters)
12
+ - [Arrays](#arrays)
13
+ - [Relations](#relations)
14
+ - [TODO: This method is not yet implemented.](#todo:-this-method-is-not-yet-implemented)
15
+ - [Deleting Objects](#deleting-objects)
16
+ - [TODO: This method is not yet implemented.](#todo:-this-method-is-not-yet-implemented)
17
+ - [Batch Operations](#batch-operations)
18
+ - [making a few GameScore objects](#making-a-few-gamescore-objects)
19
+ - [Data Types](#data-types)
20
+ - [Dates](#dates)
21
+ - [Bytes](#bytes)
22
+ - [Pointers](#pointers)
23
+ - [Relation](#relation)
24
+ - [TODO: There is no Ruby object representation of this type, yet.](#todo:-there-is-no-ruby-object-representation-of-this-type-yet)
25
+ - [Future data types and namespacing](#future-data-types-and-namespacing)
26
+ - [Queries](#queries)
27
+ - [Basic Queries](#basic-queries)
28
+ - [Query Contraints](#query-contraints)
29
+ - [Queries on Array Values](#queries-on-array-values)
30
+ - [Relational Queries](#relational-queries)
31
+ - [Counting Objects](#counting-objects)
32
+ - [Compound Queries](#compound-queries)
33
+ - [Users](#users)
34
+ - [Signing Up](#signing-up)
35
+ - [Logging In](#logging-in)
36
+ - [Verifying Emails](#verifying-emails)
37
+ - [Requesting A Password Reset](#requesting-a-password-reset)
38
+ - [Retrieving Users](#retrieving-users)
39
+ - [Updating Users](#updating-users)
40
+ - [Querying](#querying)
41
+ - [Deleting Users](#deleting-users)
42
+ - [Linking Users](#linking-users)
43
+ - [Signing Up and Logging In](#signing-up-and-logging-in)
44
+ - [should look something like this:](#should-look-something-like-this:)
45
+ - [Linking](#linking)
46
+ - [should look something like this:](#should-look-something-like-this:)
47
+ - [or](#or)
48
+ - [Unlinking](#unlinking)
49
+ - [should look something like this:](#should-look-something-like-this:)
50
+ - [Security](#security)
51
+ - [Roles](#roles)
52
+ - [Files](#files)
53
+ - [Uploading Files](#uploading-files)
54
+ - [Associating with Objects](#associating-with-objects)
55
+ - [Deleting Files](#deleting-files)
56
+ - [Push Notifications](#push-notifications)
57
+ - [Installations](#installations)
58
+ - [GeoPoints](#geopoints)
59
+ - [GeoPoint](#geopoint)
60
+ - [GeoQueries](#geoqueries)
61
+ - [should look something like this:](#should-look-something-like-this:)
62
+ - [Caveats](#caveats)
63
+
1
64
  ## Summary
2
65
 
3
66
  parse-ruby-client lets you interact with Parse using Ruby. There are many uses. For example:
@@ -120,16 +183,929 @@ You can also use `Parse::Decrement.new(amount)`.
120
183
 
121
184
  #### Arrays
122
185
 
186
+ To help with storing array data, there are three operations that can be used to atomically change an array field:
187
+
188
+ 1. `Parse::Object#array_add(field, value)` appends the given array of objects to the end of an array field.
189
+ 2. `Parse::Object#array_add_unique(field, value)` adds only the given objects which aren't already contained in an array field to that field. The position of the insert is not guaranteed.
190
+ 3. `Parse::Object#array_remove(field, value)` removes all instances of each given object from an array field.
191
+
192
+ Each method takes an array of objects to add or remove in the "objects" key. For example, we can add items to the set-like "skills" field like so:
193
+
194
+ ```ruby
195
+ game_score = Parse::Query.new("GameScore").eq("objectId", "5iEEIxM4MW").get.first
196
+ game_score.array_add_unique("skills", ["flying", "kungfu"])
197
+ game_score.save
198
+ puts game_score["skills"]
199
+ ```
200
+
201
+ This will return:
202
+
203
+ ```ruby
204
+ [["flying", "kungfu"]]
205
+ ```
206
+
207
+ #### Relations
208
+
209
+ In order to update Relation types, Parse provides special operators to atomically add and remove objects to a relation. So, we can add an object to a relation like so:
210
+
211
+ ```ruby
212
+ game_score = Parse::Query.new("GameScore").eq("objectId", "5iEEIxM4MW").get.first
213
+ player = Parse::Query.new("Player").eq("objectId", "GLtvtEaGKa").get.first
214
+ game_score.array_add_relation("opponents", player.pointer)
215
+ game_score.save
216
+ game_score["opponents"] #=> #<Parse::ArrayOp:0x007fbe98931508 @operation="AddRelation", @objects=[Player:GLtvtEaGKa]>
217
+ game_score["opponents"].objects.first #=> Player:GLtvtEaGKa
218
+ ```
219
+
220
+ To remove an object from a relation, you can do:
221
+
222
+ ```ruby
223
+ # TODO: This method is not yet implemented.
224
+ ```
225
+
226
+ ### Deleting Objects
227
+
228
+ To delete an object from the Parse Cloud, call `Parse::Object#parse_delete`. For example:
229
+
230
+ ```ruby
231
+ game_score = Parse::Query.new("GameScore").eq("objectId", "5iEEIxM4MW").get.first
232
+ game_score.parse_delete
233
+ Parse::Query.new("GameScore").eq("objectId", "5iEEIxM4MW").get.length #=> 0
234
+ ```
235
+
236
+ You can delete a single field from an object by using the `Parse::Object#delete_field` operation:
237
+
238
+ ```ruby
239
+ # TODO: This method is not yet implemented.
240
+ ```
241
+
242
+ ### Batch Operations
243
+
244
+ To reduce the amount of time spent on network round trips, you can create, update, or delete several objects in one call, using the batch endpoint.
245
+
246
+ parse-ruby-client provides a "manual" way to construct Batch Operations, as well as some convenience methods. The commands are run in the order they are given. For example, to create a couple of GameScore objects using the "manual" style, use `Parse::Batch#add_request`. `#add_request` takes a `Hash` with `"method"`, `"path"`, and `"body"` keys that specify the HTTP command that would normally be used for that command.
247
+
248
+ ```ruby
249
+ batch = Parse::Batch.new
250
+ batch.add_request({
251
+ "method" => "POST",
252
+ "path" => "/1/classes/GameScore"
253
+ "body" => {
254
+ "score" => 1337,
255
+ "playerName" => "Sean Plott"
256
+ }
257
+ })
258
+ batch.add_request({
259
+ "method" => "POST",
260
+ "path" => "/1/classes/GameScore"
261
+ "body" => {
262
+ "score" => 1338,
263
+ "playerName" => "ZeroCool"
264
+ }
265
+ })
266
+ batch.run!
267
+ ```
268
+
269
+ Because manually constructing `"path"` values is repetitive, you can use `Parse::Batch#create_object`, `Parse::Batch#update_object`, and `Parse::Batch#delete_object`. Each of these methods takes an instance of `Parse::Object` as the only argument. Then you just call `Parse::Batch#run!`. For example:
270
+
271
+ ```ruby
272
+ # making a few GameScore objects
273
+ game_scores = [1, 2, 3, 4, 5].map do |i|
274
+ gs = Parse::Object.new("GameScore")
275
+ gs["score"] = "#{i}"
276
+ gs
277
+ end
278
+
279
+ batch = Parse::Batch.new
280
+ game_scores.each do |gs|
281
+ batch.create_object(gs)
282
+ end
283
+ batch.run!
284
+ ```
285
+
286
+ The response from batch will be an `Array` with the same number of elements as the input list. Each item in the `Array` with be a `Hash` with either the `"success"` or `"error"` field set. The value of success will be the normal response to the equivalent REST command:
287
+
288
+ ```ruby
289
+ {
290
+ "success" => {
291
+ "createdAt" => "2012-06-15T16:59:11.276Z",
292
+ "objectId" => "YAfSAWwXbL"
293
+ }
294
+ }
295
+ ```
296
+
297
+ The value of `"error"` will be a `Hash` with a numeric code and error string:
298
+
299
+ ```ruby
300
+ {
301
+ "error" => {
302
+ "code" => 101,
303
+ "error" => "object not found for delete"
304
+ }
305
+ }
306
+ ```
307
+
308
+ ### Data Types
309
+
310
+ So far we have only used values that can be encoded with standard JSON. The Parse mobile client libraries also support dates, binary data, and relational data. In parse-ruby-client, these values are encoded as JSON hashes with the __type field set to indicate their type, so you can read or write these fields if you use the correct encoding. See https://github.com/adelevie/parse-ruby-client/blob/master/lib/parse/datatypes.rb for implementation details of several common data types.
311
+
312
+ #### Dates
313
+
314
+ Use `Parse::Date::new` to create a date object:
315
+
316
+ ```ruby
317
+ date_time = DateTime.now
318
+ parse_date = Parse::Date.new(date_time)
319
+ ```
320
+
321
+ Dates are useful in combination with the built-in createdAt and updatedAt fields. For example, to retrieve objects created since a particular time, just encode a Date in a comparison query:
322
+
323
+ ```ruby
324
+ game_score = Parse::Query.new("GameScore").tap do |q|
325
+ g.greater_than("createdAt", Parse::Object.new(DateTime.now)) # query options explained in more detail later in this document
326
+ end.get.first
327
+ ```
328
+
329
+ `Parse::Date::new` can take a `DateTime`, iso `Hash`, or a `String` that can be parsed by `DateTime#parse` as the sole argument.
330
+
331
+ The `Parse::Date` API is not set in stone and will likely change following the suggestions discussed here: https://github.com/adelevie/parse-ruby-client/issues/35. The current methods probably will not go away, but some newer, easier methods will be added.
332
+
333
+ #### Bytes
334
+
335
+ `Parse::Bytes` contains an attribute, `base64`, which contains a base64 encoding of binary data. The specific base64 encoding is the one used by MIME, and does not contain whitespace.
336
+
337
+ ```ruby
338
+ data = "TG9va3MgbGlrZSB5b3UgZm91bmQgYW4gZWFzdGVyIEVnZy4gTWF5YmUgaXQn\ncyB0aW1lIHlvdSB0b29rIGEgTWluZWNyYWZ0IGJyZWFrPw==\n" # base64 encoded data
339
+ bytes = Parse::Bytes.new(data)
340
+ ```
341
+
342
+ #### Pointers
343
+
344
+ The `Pointer` type is used when mobile code sets a `PFObject` (iOS SDK) or `ParseObject` (Android SDK) as the value of another object. It contains the `className` and `objectId` of the referred-to value.
345
+
346
+ ```ruby
347
+ pointer = Parse::Pointer.new({"className => gameScore", "objectId" => "GeqPWJdNqp"})
348
+ ```
349
+
350
+ Pointers to `user` objects have a `className` of `_User`. Prefixing with an underscore is forbidden for developer-defined classes and signifies the class is a special built-in.
351
+
352
+ If you already have a `Parse::Object`, you can get its `Pointer` very easily:
353
+
354
+ ```ruby
355
+ game_score.pointer
356
+ ```
357
+
358
+ #### Relation
359
+
360
+ The `Relation` type is used for many-to-many relations when the mobile uses `PFRelation` (iOS SDK) or `ParseRelation` (Android SDK) as a value. It has a `className` that is the class name of the target objects.
361
+
362
+ ```ruby
363
+ # TODO: There is no Ruby object representation of this type, yet.
364
+ ```
365
+
366
+ #### Future data types and namespacing
367
+
368
+ Though this is something parse-ruby-client will take care for you, it's worth noting:
369
+
370
+ When more data types are added, they will also be represented as hashes with a `__type` field set, so you may not use this field yourself on JSON objects.
371
+
372
+
123
373
  ## Queries
124
374
 
375
+ Queries are created like so:
376
+
377
+ ```ruby
378
+ query = Parse::Query.new("GameScore")
379
+ ```
380
+
381
+
382
+
383
+ ### Basic Queries
384
+
385
+ You can retrieve multiple objects at once by calling `#get`:
386
+
387
+ ```ruby
388
+ query.get
389
+ ```
390
+
391
+ The return value is an `Array` of `Parse::Object` instances:
392
+
393
+ ```ruby
394
+ [{"score"=>100,
395
+ "player"=>player:qPHDUbBbjj,
396
+ "createdAt"=>"2012-10-10T00:16:10.846Z",
397
+ "updatedAt"=>"2012-10-10T00:16:10.846Z",
398
+ "objectId"=>"6ff54A5OCY"},
399
+ {"score"=>1337,
400
+ "playerName"=>"Sean Plott",
401
+ "createdAt"=>"2013-01-05T22:51:56.033Z",
402
+ "updatedAt"=>"2013-01-05T22:51:56.033Z",
403
+ "objectId"=>"MpPBAHsqNg"},
404
+ {"score"=>1337,
405
+ "playerName"=>"Sean Plott",
406
+ "createdAt"=>"2013-01-05T22:53:22.609Z",
407
+ "updatedAt"=>"2013-01-05T22:53:22.609Z",
408
+ "objectId"=>"T1dj8cWwYJ"}]]
409
+ ```
410
+
411
+ ### Query Contraints
412
+
413
+ There are several ways to put constraints on the objects found, using various methods of `Parse::Query`. The most basic is `Parse::Query#eq`:
414
+
415
+ ```ruby
416
+ query = Parse::Query.new("GameScore").eq("playerName", "Sean Plott")
417
+ ```
418
+
419
+ Other constraint methods include:
420
+
421
+ <table>
422
+ <tr>
423
+ <td>`Parse::Query#less_than(field, value)`</td>
424
+ <td>Less Than</td>
425
+ </tr>
426
+ <tr>
427
+ <td>`Parse::Query#less_eq(field, value)`</td>
428
+ <td>Less Than or Equal To</td>
429
+ </tr>
430
+ <tr>
431
+ <td>`Parse::Query#greater_than(field, value)`</td>
432
+ <td>Greater Than</td>
433
+ </tr>
434
+ <tr>
435
+ <td>`Parse::Query#greater_eq(field, value)`</td>
436
+ <td>Greater Than Or Equal To</td>
437
+ </tr>
438
+ <tr>
439
+ <td>`Parse::Query#not_eq(field, value)`</td>
440
+ <td>Not Equal To</td>
441
+ </tr>
442
+ <tr>
443
+ <td>`Parse::Query#value_in(field, values)`</td>
444
+ <td>Contained In</td>
445
+ </tr>
446
+ <tr>
447
+ <td>`Parse::Query#value_not_in(field, values)`</td>
448
+ <td>Not Contained in</td>
449
+ </tr>
450
+ <tr>
451
+ <td>`Parse::Query#exists(field, value=true)`</td>
452
+ <td>A value is set for the key</td>
453
+ </tr>
454
+ <tr>
455
+ <td>`Parse::Query#select`</td>
456
+ <td>TODO: `$select` not yet implemented. This matches a value for a key in the result of a different query</td>
457
+ </tr>
458
+ </table>
459
+
460
+ For example, to retrieve scores between 1000 and 3000, including the endpoints, we could issue:
461
+
462
+ ```ruby
463
+ scores = Parse::Query.new("GameScore").tap do |q|
464
+ q.greater_eq("score", 1000)
465
+ q.less_eq("score", 3000)
466
+ end.get
467
+ ```
468
+
469
+ To retrieve scores equal to an odd number below 10, we could issue:
470
+
471
+ ```ruby
472
+ scores = Parse::Query.new("GameScore").tap do |q|
473
+ q.value_in("score", [1,3,5,7,9])
474
+ end.get
475
+ ```
476
+
477
+ To retrieve scores not by a given list of players we could issue:
478
+
479
+ ```ruby
480
+ scores = Parse::Query.new("GameScore").tap do |q|
481
+ q.value_not_in("playerName", ["Jonathan Walsh","Dario Wunsch","Shawn Simon"])
482
+ end.get
483
+ ```
484
+
485
+ To retrieve documents with the score set, we could issue:
486
+
487
+ ```ruby
488
+ scores = Parse::Query.new("GameScore").tap do |q|
489
+ q.exists("score") # defaults to `true`
490
+ end.get
491
+ ```
492
+
493
+ To retrieve documents without the score set, we could issue:
494
+
495
+ ```ruby
496
+ scores = Parse::Query.new("GameScore").tap do |q|
497
+ q.exists("score", false)
498
+ end.get
499
+ ```
500
+
501
+ If you have a class containing sports teams and you store a user's hometown in the user class, you can issue one query to find the list of users whose hometown teams have winning records. The query would look like:
502
+
503
+ ```ruby
504
+ users = Parse::Query.new("_User").tap do |users_query|
505
+ users_query.eq("hometown", {
506
+ "$select" => {
507
+ "query" => {
508
+ "className" => "Team",
509
+ "where" => {
510
+ "winPct" => {"$gt" => 0.5}
511
+ }
512
+ },
513
+ "key" => "city"
514
+ }
515
+ })
516
+ end.get
517
+ ```
518
+
519
+ Currently, there is no convenience method provided for `$select` queries. However, they are still possible. This is a good example of the flexibility of parse-ruby-client. You usually do not need to wait for a feature to be added in order to user it. If you have a good idea on what a convencience method for this should look like, please file an issue, or even better, submit a pull request.
520
+
521
+ You can use the `Parse::Query#order_by` method to specify a field to sort by. By default, everything is ordered ascending. Thus, to retrieve scores in ascending order:
522
+
523
+ ```ruby
524
+ scores = Parse::Query.new("GameScore").tap do |q|
525
+ q.order_by = "score"
526
+ end.get
527
+ ```
528
+
529
+ And to retrieve scores in descending order:
530
+
531
+ ```ruby
532
+ scores = Parse::Query.new("GameScore").tap do |q|
533
+ q.order_by = "score"
534
+ q.order = :descending
535
+ end.get
536
+ ```
537
+
538
+ You can sort by multiple fields by passing order a comma-separated list. Currently, there is no convenience method to accomplish this. However, you can still manually construct an `order` string. To retrieve documents that are ordered by scores in ascending order and the names in descending order:
539
+
540
+ ```ruby
541
+ scores = Parse::Query.new("GameScore").tap do |q|
542
+ q.order_by = "score,-name"
543
+ end.get
544
+ ```
545
+
546
+ You can use the `limit` and `skip` parameters for pagination. `limit` defaults to 100, but anything from 1 to 1000 is a valid limit. Thus, to retrieve 200 objects after skipping the first 400:
547
+
548
+ ```ruby
549
+ scores = Parse::Query.new("GameScore").tap do |q|
550
+ q.limit = 200
551
+ q.skip = 400
552
+ end.get
553
+ ```
554
+
555
+ All of these parameters can be used in combination with each other.
556
+
557
+ ### Queries on Array Values
558
+
559
+ For keys with an array type, you can find objects where the key's array value contains 2 by:
560
+
561
+ ```ruby
562
+ randos = Parse::Query.new("RandomObject").eq("arrayKey", 2).get
563
+ ```
564
+
565
+ ### Relational Queries
566
+
567
+ There are several ways to issue queries for relational data. For example, if each `Comment` has a `Post` object in its `post` field, you can fetch comments for a particular `Post`:
568
+
569
+ ```ruby
570
+ comments = Parse::Query.new("Comment").tap do |q|
571
+ q.eq("post", Parse::Pointer.new({
572
+ "className" => "Post",
573
+ "objectId" => "8TOXdXf3tz"
574
+ }))
575
+ end.get
576
+ ```
577
+
578
+ If you want to retrieve objects where a field contains an object that matches another query, you can use the `Parse::Query#in_query(field, query=nil)` method. Note that the default limit of 100 and maximum limit of 1000 apply to the inner query as well, so with large data sets you may need to construct queries carefully to get the desired behavior. For example, imagine you have `Post` class and a `Comment` class, where each `Comment` has a relation to its parent `Post`. You can find comments on posts with images by doing:
579
+
580
+ ```ruby
581
+ comments = Parse::Query.new("Comment").tap do |comments_query|
582
+ comments_query.in_query("post", Parse::Query.new("Post").tap do |posts_query|
583
+ posts_query.exists("image")
584
+ end)
585
+ end.get
586
+ ```
587
+
588
+ Note: You must pass an instance of `Parse::Query` as the second argument for `Parse::Query#query_in`. You cannot manually construct queries for this.
589
+
590
+ TODO: Implement this:
591
+ ```
592
+ If you want to retrieve objects where a field contains an object that does not match another query, you can use the $notInQuery operator. Imagine you have Post class and a Comment class, where each Comment has a relation to its parent Post. You can find comments on posts without images by doing:
593
+ ```
594
+
595
+ If you want to retrieve objects that are members of `Relation` field of a parent object, you can use the `Parse::Query#related_to(field, value)` method. Imagine you have a `Post `class and `User` class, where each `Post` can be liked by many users. If the `Users` that liked a Post was stored in a `Relation` on the post under the key likes, you, can the find the users that liked a particular post by:
596
+
597
+ ```ruby
598
+ users = Parse::Query.new("_User").tap do |q|
599
+ q.related_to("likes", Parse::Pointer.new({
600
+ "className" => "Post",
601
+ "objectId" => "8TOXdXf3tz"
602
+ }))
603
+ end.get
604
+ ```
605
+
606
+ In some situations, you want to return multiple types of related objects in one query. You can do this by passing the field to include in the `include` parameter. For example, let's say you are retrieving the last ten comments, and you want to retrieve their related posts at the same time:
607
+
608
+ ```ruby
609
+ comments = Parse::Query.new("Comment").tap do |q|
610
+ q.order_by = "createdAt"
611
+ q.order = :descending
612
+ q.limit = 10
613
+ q.include = "post"
614
+ end.get
615
+ ```
616
+
617
+ Instead of being represented as a `Pointer`, the `post` field is now expanded into the whole object. `__type` is set to `Object` and `className` is provided as well. For example, a `Pointer` to a `Post` could be represented as:
618
+
619
+ ```ruby
620
+ {
621
+ "__type" => "Pointer",
622
+ "className" => "Post",
623
+ "objectId" => "8TOXdXf3tz"
624
+ }
625
+ ```
626
+
627
+ When the query is issued with an `include` parameter for the key holding this pointer, the pointer will be expanded to:
628
+
629
+ ```ruby
630
+ {
631
+ "__type" => "Object",
632
+ "className" => "Post",
633
+ "objectId" => "8TOXdXf3tz",
634
+ "createdAt" => "2011-12-06T20:59:34.428Z",
635
+ "updatedAt" => "2011-12-06T20:59:34.428Z",
636
+ "otherFields" => "willAlsoBeIncluded"
637
+ }
638
+ ```
639
+
640
+ You can also do multi level includes using dot notation. If you wanted to include the post for a comment and the post's author as well you can do:
641
+
642
+ ```ruby
643
+ comments = Parse::Query.new("Comment").tap do |q|
644
+ q.order_by = "createdAt"
645
+ q.order = :descending
646
+ q.limit = 10
647
+ q.include = "post.author"
648
+ end.get
649
+ ```
650
+
651
+ You can issue a query with multiple fields included by passing a comma-separated list of keys as the include parameter:
652
+
653
+ ```ruby
654
+ comments = Parse::Query.new("Comment").tap do |q|
655
+ q.include("post,author")
656
+ end.get
657
+ ```
658
+
659
+ ### Counting Objects
660
+
661
+ If you are limiting your query, or if there are a very large number of results, and you want to know how many total results there are without returning them all, you can use the `count` parameter. For example, if you only care about the number of games played by a particular player:
662
+
663
+ ```ruby
664
+ count = Parse::Query.new("GameScore").tap do |q|
665
+ q.eq("playerName", "Jonathan Walsh")
666
+ q.limit = 0
667
+ q.count
668
+ end.get
669
+ ```
670
+
671
+ With a nonzero limit, that request would return results as well as the count.
672
+
673
+ ### Compound Queries
674
+
675
+ If you want to find objects that match one of several queries, you can use `Parse::Quer#or` method, with an `Array` as its value. For instance, if you want to find players with either have a lot of wins or a few wins, you can do:
676
+
677
+ ```ruby
678
+
679
+ players = Parse::Query.new("Player").tap do |q|
680
+ q.greater_than("wins", 150)
681
+ q.or(Parse::Query.new("Player").tap do |or_query|
682
+ or_query.less_than("wins, 5")
683
+ end)
684
+ end.get
685
+ ```
686
+
125
687
  ## Users
126
688
 
689
+ Many apps have a unified login that works across the mobile app and other systems. Accessing user accounts through parse-ruby-client lets you build this functionality on top of Parse.
690
+
691
+ In general, users have the same features as other objects, such as the flexible schema. The differences are that user objects must have a username and password, the password is automatically encrypted and stored securely, and Parse enforces the uniqueness of the `username` and `email` fields.
692
+
693
+ ### Signing Up
694
+
695
+ Signing up a new user differs from creating a generic object in that the `username` and `password` fields are required. The password field is handled differently than the others; it is encrypted when stored in the Parse Cloud and never returned to any client request.
696
+
697
+ You can ask Parse to verify user email addresses in your application settings page. With this setting enabled, all new user registrations with an `email` field will generate an email confirmation at that address. You can check whether the user has verified their `email` with the `emailVerified` field.
698
+
699
+ To sign up a new user, create a new `Parse::User` object and then call `#save` on it:
700
+
701
+ ```ruby
702
+ user = Parse::User.new({
703
+ :username => "cooldude6",
704
+ :password => "p_n7!-e8",
705
+ :phone => "415-392-0202"
706
+ })
707
+ user.save
708
+ ```
709
+
710
+ The response body is a `Parse::User` object containing the `objectId`, the `createdAt` timestamp of the newly-created object, and the `sessionToken` which can be used to authenticate subsequent requests as this user:
711
+
712
+ ```ruby
713
+ {"username"=>"cooldude6",
714
+ "phone"=>"415-392-0202",
715
+ "createdAt"=>"2013-01-31T15:22:40.339Z",
716
+ "objectId"=>"2bMfWZQ9Ob",
717
+ "sessionToken"=>"zrGuvs3psdndaqswhf0smupsodflkqbFdwRs"}
718
+ ```
719
+
720
+ ### Logging In
721
+
722
+ After you allow users to sign up, you need to let them log in to their account with a username and password in the future. To do this, call `Parse::User#authenticate(username, password)`:
723
+
724
+ ```ruby
725
+ user = Parse::User.authenticate("cooldude6", "p_n7!-e8")
726
+ ```
727
+
728
+ The response body is a `Parse::User` object containing all the user-provided fields except `password`. It also contains the `createdAt`, `updatedAt`, `objectId`, and `sessionToken` fields:
729
+
730
+ ```ruby
731
+ {"username"=>"cooldude6",
732
+ "phone"=>"415-392-0202",
733
+ "createdAt"=>"2013-01-31T15:22:40.339Z",
734
+ "updatedAt"=>"2013-01-31T15:22:40.339Z",
735
+ "objectId"=>"2bMfWZQ9Ob",
736
+ "sessionToken"=>"uvs3aspasdnlksdasqu178qaq0smupso"}
737
+ ```
738
+
739
+ ### Verifying Emails
740
+
741
+ Enabling email verification in an application's settings allows the application to reserve part of its experience for users with confirmed email addresses. Email verification adds the `emailVerified` field to the `User` object. When a `User`'s `email` is set or modified, `emailVerified` is set to false. Parse then emails the user a link which will set `emailVerified` to `true`.
742
+
743
+ There are three `emailVerified` states to consider:
744
+
745
+ 1. `true` - the user confirmed his or her email address by clicking on the link Parse emailed them. `Users` can never have a `true` value when the user account is first created.
746
+
747
+ 2. `false` - at the time the `User` object was last refreshed, the user had not confirmed his or her email address. If `emailVerified` is `false`, consider refreshing the `User` object.
748
+
749
+ 3. *missing* - the `User` was created when email verification was off or the `User` does not have an `email`.
750
+
751
+ ### Requesting A Password Reset
752
+
753
+ You can initiate password resets for users who have emails associated with their account. To do this, use `Parse::User::reset_password`:
754
+
755
+ ```ruby
756
+ resp = Parse::User.reset_password("coolguy@iloveapps.com")
757
+ puts resp #=> {}
758
+ ```
759
+
760
+ If successful, the response body is an empty `Hash` object.
761
+
762
+ ### Retrieving Users
763
+
764
+ You can also retrieve the contents of a user object by using `Parse::Query`. For example, to retrieve the user created above:
765
+
766
+ ```ruby
767
+ user = Parse::Query.new("_User").eq("objectId", "2bMfWZQ9Ob").get.first
768
+ ```
769
+
770
+ The response body is a `Parse::User` object containing all the user-provided fields except `password`. It also contains the `createdAt`, `updatedAt`, and `objectId` fields:
771
+
772
+ ```ruby
773
+ {"username"=>"cooldude6",
774
+ "phone"=>"415-392-0202",
775
+ "createdAt"=>"2013-01-31T15:22:40.339Z",
776
+ "updatedAt"=>"2013-01-31T15:22:40.339Z",
777
+ "objectId"=>"2bMfWZQ9Ob"}
778
+ ```
779
+
780
+ ### Updating Users
781
+
782
+ TODO: Implement this!
783
+
784
+ In normal usage, nobody except the user is allowed to modify their own data. To authenticate themselves, the user must add a `X-Parse-Session-Token` header to the request with the session token provided by the signup or login method.
785
+
786
+ To change the data on a user that already exists, send a PUT request to the user URL. Any keys you don't specify will remain unchanged, so you can update just a subset of the user's data. `username` and `password` may be changed, but the new username must not already be in use.
787
+
788
+ For example, if we wanted to change the phone number for cooldude6:
789
+
790
+ ```ruby
791
+ user = Parse::Query.new("_User").eq("objectId", "2bMfWZQ9Ob").get.first
792
+ user["phone"] = "415-369-6201"
793
+ user.save
794
+ ```
795
+
796
+ Currently returns the following error:
797
+
798
+ ```
799
+ Parse::ParseProtocolError: 206: Parse::UserCannotBeAlteredWithoutSessionError
800
+ ```
801
+
802
+ ### Querying
803
+
804
+ You can retrieve multiple users at once by using `Parse::Query`:
805
+
806
+ ```ruby
807
+ users = Parse::Query.new("_User").get
808
+ ```
809
+
810
+ The return value is an `Array` of `Parse::User` objects:
811
+
812
+ ```ruby
813
+ [{"username"=>"fake_person",
814
+ "createdAt"=>"2012-04-20T20:07:32.295Z",
815
+ "updatedAt"=>"2012-04-20T20:07:32.295Z",
816
+ "objectId"=>"AAVwfClOx9"},
817
+ {"username"=>"fake_person222",
818
+ "createdAt"=>"2012-04-20T20:07:32.946Z",
819
+ "updatedAt"=>"2012-04-20T20:07:32.946Z",
820
+ "objectId"=>"0W1Gj1CXqU"}]
821
+ ```
822
+
823
+ All of the options for queries that work for regular objects also work for user objects, so check the section on Querying Objects for more details.
824
+
825
+ ### Deleting Users
826
+
827
+ TODO: Implement this!
828
+
829
+ Proposed api:
830
+
831
+ To delete a user from the Parse Cloud, call `#parse_delete` on it:
832
+
833
+ ```ruby
834
+ user.parse_delete
835
+ ```
836
+
837
+ ### Linking Users
838
+
839
+ TODO: Implement this! See https://parse.com/docs/rest#users-linking
840
+
841
+ Parse allows you to link your users with services like Twitter and Facebook, enabling your users to sign up or log into your application using their existing identities. This is accomplished through the sign-up and update REST endpoints by providing authentication data for the service you wish to link to a user in the authData field. Once your user is associated with a service, the authData for the service will be stored with the user and is retrievable by logging in.
842
+
843
+ authData is a JSON object with keys for each linked service containing the data below. In each case, you are responsible for completing the authentication flow (e.g. OAuth 1.0a) to obtain the information the the service requires for linking.
844
+
845
+ Facebook authData contents:
846
+
847
+ ```ruby
848
+ {
849
+ "facebook" => {
850
+ "id" => "user's Facebook id number as a string",
851
+ "access_token" => "an authorized Facebook access token for the user",
852
+ "expiration_date" => "token expiration date of the format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
853
+ }
854
+ }
855
+ ```
856
+
857
+ Twitter authData contents:
858
+
859
+ ```ruby
860
+ {
861
+ "twitter" => {
862
+ "id" => "user's Twitter id number as a string",
863
+ "screen_name" => "user's Twitter screen name",
864
+ "consumer_key" => "your application's consumer key",
865
+ "consumer_secret" => "your application's consumer secret",
866
+ "auth_token" => "an authorized Twitter token for the user with your application",
867
+ "auth_token_secret" => "the secret associated with the auth_token"
868
+ }
869
+ }
870
+ ```
871
+
872
+ Anonymous user authData contents:
873
+
874
+ ```ruby
875
+ {
876
+ "anonymous" => {
877
+ "id" => "random UUID with lowercase hexadecimal digits"
878
+ }
879
+ }
880
+ ```
881
+
882
+ #### Signing Up and Logging In
883
+
884
+ Todo: Implement this!
885
+
886
+ Signing a user up with a linked service and logging them in with that service uses the same POST request, in which the authData for the user is specified. For example, to sign up or log in with a user's Twitter account:
887
+
888
+ ```ruby
889
+ # should look something like this:
890
+ twitter_user = Parse::User::Twitter.new({
891
+ "id" => "12345678",
892
+ "screen_name" => "ParseIt",
893
+ "consumer_key" => "SaMpLeId3X7eLjjLgWEw",
894
+ "consumer_secret" => "SaMpLew55QbMR0vTdtOACfPXa5UdO2THX1JrxZ9s3c",
895
+ "auth_token" => "12345678-SaMpLeTuo3m2avZxh5cjJmIrAfx4ZYyamdofM7IjU",
896
+ "auth_token_secret" => "SaMpLeEb13SpRzQ4DAIzutEkCE2LBIm2ZQDsP3WUU"
897
+ })
898
+ twitter_user.save
899
+ ```
900
+
901
+ Parse then verifies that the provided authData is valid and checks to see if a user is already associated with this data. If so, it returns a status code of 200 OK and the details (including a sessionToken for the user).
902
+
903
+ With a response body like:
904
+
905
+ ```ruby
906
+ {
907
+ "username" => "Parse",
908
+ "createdAt" => "2012-02-28T23:49:36.353Z",
909
+ "updatedAt" => "2012-02-28T23:49:36.353Z",
910
+ "objectId" => "uMz0YZeAqc",
911
+ "sessionToken" => "samplei3l83eerhnln0ecxgy5",
912
+ "authData" => {
913
+ "twitter" => {
914
+ "id" => "12345678",
915
+ "screen_name" => "ParseIt",
916
+ "consumer_key" => "SaMpLeId3X7eLjjLgWEw",
917
+ "consumer_secret" => "SaMpLew55QbMR0vTdtOACfPXa5UdO2THX1JrxZ9s3c",
918
+ "auth_token" => "12345678-SaMpLeTuo3m2avZxh5cjJmIrAfx4ZYyamdofM7IjU",
919
+ "auth_token_secret" => "SaMpLeEb13SpRzQ4DAIzutEkCE2LBIm2ZQDsP3WUU"
920
+ }
921
+ }
922
+ }
923
+ ```
924
+
925
+ If the user has never been linked with this account, you will instead receive a status code of 201 Created, indicating that a new user was created.
926
+
927
+ The body of the response will contain the objectId, createdAt, sessionToken, and an automatically-generated unique username. For example:
928
+
929
+ ```ruby
930
+ {
931
+ "username" => "iwz8sna7sug28v4eyu7t89fij",
932
+ "createdAt" => "2012-02-28T23:49:36.353Z",
933
+ "objectId" => "uMz0YZeAqc",
934
+ "sessionToken" => "samplei3l83eerhnln0ecxgy5"
935
+ }
936
+ ```
937
+
938
+ #### Linking
939
+
940
+ TODO: Implement this!
941
+
942
+ Linking an existing user with a service like Facebook or Twitter uses a PUT request to associate authData with the user. For example, linking a user with a Facebook account would use a request like this:
943
+
944
+ ```ruby
945
+ # should look something like this:
946
+
947
+ user = Parse::Query.new("_User").eq("objectId", "2bMfWZQ9Ob").get.first
948
+ user.link_to_facebook!({
949
+ "id" => "123456789",
950
+ "access_token" => "SaMpLeAAibS7Q55FSzcERWIEmzn6rosftAr7pmDME10008bWgyZAmv7mziwfacNOhWkgxDaBf8a2a2FCc9Hbk9wAsqLYZBLR995wxBvSGNoTrEaL",
951
+ "expiration_date" => "2012-02-28T23:49:36.353Z"
952
+ })
953
+
954
+ # or
955
+
956
+ user.link_to_twitter!({...})
957
+ ```
958
+
959
+ After linking your user to a service, you can authenticate them using matching authData.
960
+
961
+
962
+ #### Unlinking
963
+
964
+ TODO: Implement this!
965
+
966
+ Unlinking an existing user with a service also uses a PUT request to clear authData from the user by setting the authData for the service to null. For example, unlinking a user with a Facebook account would use a request like this:
967
+
968
+ ```ruby
969
+ # should look something like this:
970
+
971
+ user = Parse::Query.new("_User").eq("objectId", "2bMfWZQ9Ob").get.first
972
+ user.unlink_from_facebook!
973
+ ```
974
+
975
+ ### Security
976
+
977
+ TODO: Implement this!
978
+
979
+ When you access Parse via the REST API key, access can be restricted by ACL just like in the iOS and Android SDKs. You can still read and modify acls via the REST API, just be accessing the "ACL" key of an object.
980
+
981
+ The ACL is formatted as a JSON object where the keys are either object ids or the special key "*" to indicate public access permissions. The values of the ACL are "permission objects", JSON objects whose keys are the permission name and the value is always true.
982
+
983
+ For example, if you want the user with id "3KmCvT7Zsb" to have read and write access to an object, plus the object should be publicly readable, that corresponds to an ACL of:
984
+
985
+ ```json
986
+ {
987
+ "3KmCvT7Zsb": {
988
+ "read": true,
989
+ "write": true
990
+ },
991
+ "*": {
992
+ "read": true
993
+ }
994
+ }
995
+ ```
996
+
997
+ If you want to access your data ignoring all ACLs, you can use the master key provided on the Dashboard. Instead of the X-Parse-REST-API-Key header, set the X-Parse-Master-Key header. For backward compatibility, you can also do master-level authentication using HTTP Basic Auth, passing the application id as the username and the master key as the password. For security, the master key should not be distributed to end users, but if you are running code in a trusted environment, feel free to use the master key for authentication.
998
+
127
999
  ## Roles
128
1000
 
1001
+ TODO: Implement this!
1002
+
1003
+ See https://parse.com/docs/rest#roles
1004
+
129
1005
  ## Files
130
1006
 
1007
+ ### Uploading Files
1008
+
1009
+ To upload a file to Parse, use `Parse::File`. You must include the `"Content-Type"` parameter when instantiating. Keep in mind that files are limited to 10 megabytes. Here's a simple example that'll create a file named `hello.txt` containing a string:
1010
+
1011
+ ```ruby
1012
+ file = Parse::File.new({
1013
+ :body => "Hello World!",
1014
+ :local_filename => "hello.txt",
1015
+ :content_type => "text/plain"
1016
+ })
1017
+ file.save
1018
+ ```
1019
+
1020
+ The response body is a `Hash` object containing the name of the file, which is the original file name prefixed with a unique identifier in order to prevent name collisions. This means, you can save files by the same name, and the files will not overwrite one another.
1021
+
1022
+ ```ruby
1023
+ {"url"=>
1024
+ "http://files.parse.com/372fcbb9-7eae-4b9a-abc8-6da97fcac50d/98f06e15-d6e6-42a9-a9cd-7d28ec98052c-hello.txt",
1025
+ "name"=>"98f06e15-d6e6-42a9-a9cd-7d28ec98052c-hello.txt"}
1026
+ ```
1027
+
1028
+ To upload an image, the syntax is a little bit different. Here's an example that will upload the image parsers.jpg from the current directory:
1029
+
1030
+ ```ruby
1031
+ photo = Parse::File.new({
1032
+ :body => IO.read("test/parsers.jpg"),
1033
+ :local_filename => "parsers.jpg",
1034
+ :content_type => "image/jpeg"
1035
+ })
1036
+ photo.save
1037
+ ```
1038
+
1039
+ ### Associating with Objects
1040
+
1041
+ After files are uploaded, you can associate them with Parse objects:
1042
+
1043
+ ```ruby
1044
+ photo = Parse::File.new({
1045
+ :body => IO.read("test/parsers.jpg"),
1046
+ :local_filename => "parsers.jpg",
1047
+ :content_type => "image/jpeg"
1048
+ })
1049
+ photo.save
1050
+ player_profile = Parse::Object.new("PlayerProfile").tap do |p|
1051
+ p["name"] = "All the Parsers"
1052
+ p["picture"] = photo
1053
+ end.save
1054
+ ```
1055
+
1056
+ ### Deleting Files
1057
+
1058
+ TODO: Implement this!
1059
+
131
1060
  ## Push Notifications
132
1061
 
1062
+ For now, see https://github.com/adelevie/parse-ruby-client/blob/master/test/test_push.rb for examples.
1063
+
1064
+ Also, for config/installation: https://parse.com/docs/rest#push and https://parse.com/docs/push_guide#top/REST
1065
+
133
1066
  ## Installations
134
1067
 
135
- ## Geopoints
1068
+ TODO: Implement this!
1069
+
1070
+ ## GeoPoints
1071
+
1072
+ Parse allows you to associate real-world latitude and longitude coordinates with an object. Adding a GeoPoint data type to a class allows queries to take into account the proximity of an object to a reference point. This allows you to easily do things like find out what user is closest to another user or which places are closest to a user.
1073
+
1074
+ ### GeoPoint
1075
+
1076
+ To associate a point with an object you will need to embed a GeoPoint data type into your object. This is done by using a JSON object with __type set to the string GeoPoint and numeric values being set for the latitude and longitude keys. For example, to create an object containing a point under the "location" key with a latitude of 40.0 degrees and -30.0 degrees longitude:
1077
+
1078
+ ```ruby
1079
+ place = Parse::Object.new("PlaceObject").tap do |p|
1080
+ p["location"] = Parse::GeoPoint.new({
1081
+ "latitude" => 40.0,
1082
+ "longitude" => -30.0
1083
+ })
1084
+ end.save
1085
+ ```
1086
+
1087
+ ### GeoQueries
1088
+
1089
+ TODO: Implement this!
1090
+
1091
+ Now that you have a bunch of objects with spatial coordinates, it would be nice to find out which objects are closest to a point. This can be done by using a GeoPoint data type with query on the field using $nearSphere. Getting a list of ten places that are closest to a user may look something like:
1092
+
1093
+ ```ruby
1094
+ # should look something like this:
1095
+ places = Parse::Query.new("PlaceObject").tap do |q|
1096
+ q.near("location", {
1097
+ "latitude" => 30.0,
1098
+ "longitude" => -20.0
1099
+ })
1100
+ end.get
1101
+ ```
1102
+
1103
+ See https://parse.com/docs/rest#geo-query for the rest of the geo query types to implement.
1104
+
1105
+ ### Caveats
1106
+
1107
+ At the moment there are a couple of things to watch out for:
1108
+
1109
+ 1. Each PFObject class may only have one key with a PFGeoPoint object.
1110
+
1111
+ 2. Points should not equal or exceed the extreme ends of the ranges. Latitude should not be -90.0 or 90.0. Longitude should not be -180.0 or 180.0. Attempting to use GeoPoint's with latitude and/or longitude outside these ranges will cause an error.
data/lib/parse/client.rb CHANGED
@@ -2,6 +2,8 @@ require 'parse/protocol'
2
2
  require 'parse/error'
3
3
  require 'parse/util'
4
4
 
5
+ require 'iron_mq'
6
+
5
7
  module Parse
6
8
 
7
9
  # A class which encapsulates the HTTPS communication with the Parse
@@ -27,6 +29,21 @@ module Parse
27
29
  @session.timeout = 30
28
30
  @session.connect_timeout = 30
29
31
 
32
+ if data[:ironio_project_id] && data[:ironio_token]
33
+
34
+ if data[:max_concurrent_requests]
35
+ @max_concurrent_requests = data[:max_concurrent_requests]
36
+ else
37
+ @max_concurrent_requests = 50
38
+ end
39
+
40
+ @queue = IronMQ::Client.new({
41
+ :project_id => data[:ironio_project_id],
42
+ :token => data[:ironio_token]
43
+ }).queue("concurrent_parse_requests")
44
+
45
+ end
46
+
30
47
  @session.base_url = "https://#{host}"
31
48
  @session.headers["Content-Type"] = "application/json"
32
49
  @session.headers["Accept"] = "application/json"
@@ -58,7 +75,24 @@ module Parse
58
75
  num_tries = 0
59
76
  begin
60
77
  num_tries += 1
61
- response = @session.request(method, uri, {}, options)
78
+
79
+ if @queue
80
+ while true
81
+ if @queue.reload.size >= @max_concurrent_requests
82
+ sleep 1
83
+ else
84
+ # add to queue before request
85
+ @queue.post("1")
86
+ response = @session.request(method, uri, {}, options)
87
+ # delete from queue after request
88
+ msg = @queue.get()
89
+ msg.delete
90
+ end
91
+ end
92
+ else
93
+ response = @session.request(method, uri, {}, options)
94
+ end
95
+
62
96
  parsed = JSON.parse(response.body)
63
97
 
64
98
  if response.status >= 400
@@ -116,6 +150,7 @@ module Parse
116
150
  # use less permissive key if both are specified
117
151
  defaulted[:master_key] = ENV["PARSE_MASTER_API_KEY"] unless data[:master_key] || defaulted[:api_key]
118
152
 
153
+
119
154
  @@client = Client.new(defaulted)
120
155
  end
121
156
 
data/lib/parse/push.rb CHANGED
@@ -31,7 +31,7 @@ module Parse
31
31
  body.delete :channel
32
32
  end
33
33
 
34
- body.merge!({ :expiration_time_interval => @expiration_time_interval }) if @expiration_time_interval
34
+ body.merge!({ :expiration_interval => @expiration_time_interval }) if @expiration_time_interval
35
35
  body.merge!({ :expiration_time => @expiration_time }) if @expiration_time
36
36
  body.merge!({ :type => @type }) if @type
37
37
 
@@ -40,4 +40,4 @@ module Parse
40
40
 
41
41
  end
42
42
 
43
- end
43
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "parse-ruby-client"
8
- s.version = "0.1.12"
8
+ s.version = "0.1.13"
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"]
12
- s.date = "2013-01-29"
12
+ s.date = "2013-02-27"
13
13
  s.description = "A simple Ruby client for the parse.com REST API"
14
14
  s.email = "adelevie@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -96,6 +96,7 @@ Gem::Specification.new do |s|
96
96
 
97
97
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
98
98
  s.add_runtime_dependency(%q<patron>, [">= 0"])
99
+ s.add_runtime_dependency(%q<iron_mq>, [">= 0"])
99
100
  s.add_development_dependency(%q<bundler>, ["~> 1.1.5"])
100
101
  s.add_development_dependency(%q<shoulda>, [">= 0"])
101
102
  s.add_development_dependency(%q<test-unit>, ["= 2.5.0"])
@@ -106,6 +107,7 @@ Gem::Specification.new do |s|
106
107
  s.add_development_dependency(%q<vcr>, [">= 0"])
107
108
  else
108
109
  s.add_dependency(%q<patron>, [">= 0"])
110
+ s.add_dependency(%q<iron_mq>, [">= 0"])
109
111
  s.add_dependency(%q<bundler>, ["~> 1.1.5"])
110
112
  s.add_dependency(%q<shoulda>, [">= 0"])
111
113
  s.add_dependency(%q<test-unit>, ["= 2.5.0"])
@@ -117,6 +119,7 @@ Gem::Specification.new do |s|
117
119
  end
118
120
  else
119
121
  s.add_dependency(%q<patron>, [">= 0"])
122
+ s.add_dependency(%q<iron_mq>, [">= 0"])
120
123
  s.add_dependency(%q<bundler>, ["~> 1.1.5"])
121
124
  s.add_dependency(%q<shoulda>, [">= 0"])
122
125
  s.add_dependency(%q<test-unit>, ["= 2.5.0"])
data/test/test_user.rb CHANGED
@@ -46,19 +46,19 @@ class TestUser < Test::Unit::TestCase
46
46
  end
47
47
 
48
48
  def test_reset_password
49
- u = "alan" + rand(10000000000000).to_s + "@gmail.com"
50
- data = {
51
- :username => u,
52
- :password => "secret"
53
- }
49
+ u = "alan" + rand(10000000000000).to_s + "@gmail.com"
50
+ data = {
51
+ :username => u,
52
+ :password => "secret"
53
+ }
54
54
 
55
- user = Parse::User.new(data)
55
+ user = Parse::User.new(data)
56
56
 
57
- user.save
57
+ user.save
58
58
 
59
- reset_password = Parse::User.reset_password(u)
59
+ reset_password = Parse::User.reset_password(u)
60
60
 
61
- assert true
61
+ assert_equal Hash.new, reset_password
62
62
  end
63
63
 
64
64
  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.12
4
+ version: 0.1.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-29 00:00:00.000000000 Z
13
+ date: 2013-02-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: patron
@@ -28,6 +28,22 @@ dependencies:
28
28
  - - ! '>='
29
29
  - !ruby/object:Gem::Version
30
30
  version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: iron_mq
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
31
47
  - !ruby/object:Gem::Dependency
32
48
  name: bundler
33
49
  requirement: !ruby/object:Gem::Requirement
@@ -246,7 +262,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
246
262
  version: '0'
247
263
  segments:
248
264
  - 0
249
- hash: 555133796256997664
265
+ hash: 202729299205714675
250
266
  required_rubygems_version: !ruby/object:Gem::Requirement
251
267
  none: false
252
268
  requirements: