parse-stack 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +5 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +40 -80
  5. data/lib/parse/api/all.rb +7 -0
  6. data/lib/parse/api/analytics.rb +8 -3
  7. data/lib/parse/api/apps.rb +29 -1
  8. data/lib/parse/api/batch.rb +14 -129
  9. data/lib/parse/api/cloud_functions.rb +9 -0
  10. data/lib/parse/api/config.rb +10 -1
  11. data/lib/parse/api/files.rb +7 -2
  12. data/lib/parse/api/hooks.rb +45 -2
  13. data/lib/parse/api/objects.rb +43 -6
  14. data/lib/parse/api/push.rb +6 -1
  15. data/lib/parse/api/schemas.rb +15 -1
  16. data/lib/parse/api/sessions.rb +5 -0
  17. data/lib/parse/api/users.rb +64 -5
  18. data/lib/parse/client/authentication.rb +25 -8
  19. data/lib/parse/client/batch.rb +206 -0
  20. data/lib/parse/client/body_builder.rb +12 -6
  21. data/lib/parse/client/caching.rb +42 -10
  22. data/lib/parse/client/protocol.rb +51 -46
  23. data/lib/parse/client/response.rb +1 -47
  24. data/lib/parse/client.rb +171 -42
  25. data/lib/parse/model/acl.rb +184 -39
  26. data/lib/parse/model/associations/belongs_to.rb +1 -0
  27. data/lib/parse/model/classes/role.rb +7 -1
  28. data/lib/parse/model/classes/session.rb +7 -3
  29. data/lib/parse/model/classes/user.rb +107 -0
  30. data/lib/parse/model/core/actions.rb +166 -115
  31. data/lib/parse/model/core/fetching.rb +105 -0
  32. data/lib/parse/model/core/properties.rb +40 -13
  33. data/lib/parse/model/core/querying.rb +123 -39
  34. data/lib/parse/model/core/schema.rb +22 -32
  35. data/lib/parse/model/object.rb +26 -20
  36. data/lib/parse/model/pointer.rb +1 -0
  37. data/lib/parse/query/constraint.rb +65 -27
  38. data/lib/parse/query/constraints.rb +0 -3
  39. data/lib/parse/query/operation.rb +33 -22
  40. data/lib/parse/query/ordering.rb +10 -5
  41. data/lib/parse/stack/generators/rails.rb +5 -1
  42. data/lib/parse/stack/generators/templates/model_installation.rb +1 -1
  43. data/lib/parse/stack/generators/templates/model_role.rb +1 -1
  44. data/lib/parse/stack/generators/templates/model_session.rb +2 -2
  45. data/lib/parse/stack/generators/templates/model_user.rb +1 -1
  46. data/lib/parse/stack/generators/templates/parse.rb +0 -1
  47. data/lib/parse/stack/railtie.rb +1 -0
  48. data/lib/parse/stack/tasks.rb +3 -1
  49. data/lib/parse/stack/version.rb +3 -1
  50. data/lib/parse/webhooks/registration.rb +3 -3
  51. data/lib/parse/webhooks.rb +88 -7
  52. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4da68d2d9e3ed4e2607a9fadaae3cd833755492d
4
- data.tar.gz: a0ebd3622b1daedde1396993ad5f777522c3ecb1
3
+ metadata.gz: 54b0162fed5af5493439188b14b21db3eb1c7ff9
4
+ data.tar.gz: 17f07ddd2e7a79157f54769c46cee32b4aa03b97
5
5
  SHA512:
6
- metadata.gz: ecf353df19d8b5c24acf57d472d9e1a166e055e1f8648f596b2d9b78e8755855fc623e4347ff656891a6ba64ad137a3e61bdb1be9435e9719ac4f833eb53d689
7
- data.tar.gz: 06ba25aaa84702d56dc87a030aec5c99ea4858686b38ff9bfe261bc2128ca50dc6969652632033e5153e8eb6c906d8ccd9dc3023282fc4972af7206eaac86a92
6
+ metadata.gz: 93ae12440065bd3aeb3563457048bda7b60b07b08d2169381676d1638ea7acf364f3c9c1d033a741883bc21537f3decd8508bc83968a8ce326fae8004c60c5bd
7
+ data.tar.gz: cd29ad6665369388220d1599aa375323bbf872e6054541a34a660ebd71b206ddb87a3b8252391b6564c7fe2a0d4481d776ee910efef2509e772c30170469e867
data/Changes.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## Parse-Stack Changelog
2
2
 
3
+ ### 1.5.3
4
+ - Several fixes and performance improvements.
5
+ - Major revisions to documentation.
6
+ - Support for increment! and decrement! for Integer and Float properties.
7
+
3
8
  ### 1.5.2
4
9
  - FIXES #16: Constraints to `count` were not properly handled.
5
10
  - FIXES #15: Incorrect call to `request_password_reset`.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parse-stack (1.5.2)
4
+ parse-stack (1.5.3)
5
5
  active_model_serializers (>= 0.9, < 1)
6
6
  activemodel (>= 4.2.1, < 6)
7
7
  activesupport (>= 4.2.1, < 6)
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # Parse-Stack - The Parse Server Ruby Client and ORM
2
- Parse-Stack is a [Parse Server](https://github.com/ParsePlatform/parse-server) REST API Client and ORM framework for ruby. It provides a client adapter, a query engine, an object relational mapper (ORM) and a Cloud Code Webhooks rack application.
1
+ # Parse-Stack - The Parse Server Ruby SDK
2
+ Parse-Stack is a [Parse Server](https://github.com/ParsePlatform/parse-server) SDK and ORM framework for Ruby. It provides a client adapter, a query engine, an object relational mapper (ORM) and a Cloud Code Webhooks rack application.
3
3
 
4
4
  ### Code Status
5
5
  [![Gem Version](https://badge.fury.io/rb/parse-stack.svg)](https://badge.fury.io/rb/parse-stack)
6
6
  [![Build Status](https://travis-ci.org/modernistik/parse-stack.svg?branch=master)](https://travis-ci.org/modernistik/parse-stack)
7
+ [![API Reference](http://img.shields.io/badge/api-docs-blue.svg)](http://www.rubydoc.info/github/modernistik/parse-stack)
8
+ [![Source Code](https://img.shields.io/badge/github-code-orange.svg)](https://github.com/modernistik/parse-stack)
7
9
 
8
10
  ## Installation
9
11
 
@@ -59,7 +61,7 @@ For a more details on the rails integration see [Parse-Stack Rails Example](http
59
61
  - [Signup](#signup)
60
62
  - [Third-Party Services](#third-party-services)
61
63
  - [Login and Sessions](#login-and-sessions)
62
- - [Linking and Unlinking Users](#linking-and-unlinking-users)
64
+ - [Linking and Unlinking](#linking-and-unlinking)
63
65
  - [Request Password Reset](#request-password-reset)
64
66
  - [Modeling and Subclassing](#modeling-and-subclassing)
65
67
  - [Defining Properties](#defining-properties)
@@ -85,12 +87,13 @@ For a more details on the rails integration see [Parse-Stack Rails Example](http
85
87
  - [Parse Relation](#parse-relation)
86
88
  - [Options](#options-1)
87
89
  - [`:through`](#through)
90
+ - [`:scope_only`](#scope_only)
88
91
  - [Creating, Saving and Deleting Records](#creating-saving-and-deleting-records)
89
92
  - [Create](#create)
90
93
  - [Saving](#saving)
91
94
  - [Raising an exception when save fails](#raising-an-exception-when-save-fails)
92
95
  - [Modifying Associations](#modifying-associations)
93
- - [Batch Save Requests](#batch-save-requests)
96
+ - [Batch Requests](#batch-requests)
94
97
  - [Magic `save_all`](#magic-save_all)
95
98
  - [Deleting](#deleting)
96
99
  - [Fetching, Finding and Counting Records](#fetching-finding-and-counting-records)
@@ -150,7 +153,7 @@ For a more details on the rails integration see [Parse-Stack Rails Example](http
150
153
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
151
154
 
152
155
  ## Overview
153
- Parse-Stack is a full stack framework that utilizes several ideas behind [DataMapper](http://datamapper.org/docs/find.html) and [ActiveModel](https://github.com/rails/rails/tree/master/activemodel) to manage and maintain larger scale ruby applications and tools that utilize the Parse Platform. If you are familiar with these technologies, the framework should feel familiar to you.
156
+ Parse-Stack is a full stack framework that utilizes several ideas behind [DataMapper](http://datamapper.org/docs/find.html) and [ActiveModel](https://github.com/rails/rails/tree/master/activemodel) to manage and maintain larger scale ruby applications and tools that utilize the [Parse Server Platform](https://github.com/ParsePlatform/parse-server). If you are familiar with these technologies, the framework should feel familiar to you.
154
157
 
155
158
  ```ruby
156
159
 
@@ -223,7 +226,7 @@ result = Parse.call_function :myFunctionName, {param: value}
223
226
  The architecture of `Parse::Stack` is broken into four main components.
224
227
 
225
228
  ### Parse::Client
226
- This class is the core and low level API for the Parse SDK REST interface that is used by the other components. It can manage multiple sessions, which means you can have multiple client instances pointing to different Parse Applications at the same time. It handles sending raw requests as well as providing Request/Response objects for all API handlers. The connection engine is Faraday, which means it is open to add any additional middleware for features you'd like to implement.
229
+ This class is the core and low level API for the Parse Server REST interface that is used by the other components. It can manage multiple sessions, which means you can have multiple client instances pointing to different Parse Server applications at the same time. It handles sending raw requests as well as providing Request/Response objects for all API handlers. The connection engine is Faraday, which means it is open to add any additional middleware for features you'd like to implement.
227
230
 
228
231
  ### Parse::Query
229
232
  This class implements the [Parse REST Querying](http://parseplatform.github.io/docs/rest/guide/#queries) interface in the [DataMapper finder syntax style](http://datamapper.org/docs/find.html). It compiles a set of query constraints and utilizes `Parse::Client` to send the request and provide the raw results. This class can be used without the need to define models.
@@ -261,6 +264,7 @@ To connect to a Parse server, you will need a minimum of an `application_id`, an
261
264
  ```ruby
262
265
  Parse.setup app_id: "YOUR_APP_ID",
263
266
  api_key: "YOUR_API_KEY",
267
+ master_key: "YOUR_MASTER_KEY", # optional
264
268
  server_url: 'https://api.parse.com/1/' #default
265
269
  ```
266
270
 
@@ -275,18 +279,18 @@ If you wish to add additional connection middleware to the stack, you may do so
275
279
  end
276
280
  ```
277
281
 
278
- Calling `setup` will create the default `Parse::Client` session object that will be used for all models and requests in the stack. You may retrive this client by calling the class `session()` method. It is possible to create different client connections and have different models point to different Parse applications and endpoints at the same time.
282
+ Calling `setup` will create the default `Parse::Client` session object that will be used for all models and requests in the stack. You may retrive this client by calling the class `client` method. It is possible to create different client connections and have different models point to different Parse applications and endpoints at the same time.
279
283
 
280
284
  ```ruby
281
- default_client = Parse::Client.client(:default)
282
- # alias Parse::Client.client
285
+ default_client = Parse.client
286
+ # alias Parse::Client.client(:default)
283
287
  ```
284
288
 
285
289
  ### Connection Options
286
290
  There are additional connection options that you may pass the setup method when creating a `Parse::Client`.
287
291
 
288
292
  #### `:server_url`
289
- The server url of your Parse Server if you are not using the hosted Parse.com service. By default it will use `PARSE_SERVER_URL` environment variable available or fall back to `https://api.parse.com/1/` if not specified.
293
+ The server url of your Parse Server if you are not using the hosted Parse service. By default it will use `PARSE_SERVER_URL` environment variable available or fall back to `https://api.parse.com/1/` if not specified.
290
294
 
291
295
  #### `:app_id`
292
296
  The Parse application id. By default it will use `PARSE_APP_ID` environment variable if not specified.
@@ -520,19 +524,7 @@ All `Parse::Object` subclasses have an `acl` property by default. With this prop
520
524
  For more information about Parse record ACLs, see the documentation at [Security](https://parseplatform.github.io/docs/rest/guide/#security)
521
525
 
522
526
  ### Parse::Session
523
- This class represents the data and columns contained in the standard Parse `_Session` collection. You may add additional properties and methods to this class. It is defined as follows:
524
-
525
- ```ruby
526
- class Parse::Session < Parse::Object
527
- property :created_with, :object
528
- property :expires_at, :date
529
- property :installation_id
530
- property :restricted, :boolean
531
- property :session_token
532
-
533
- belongs_to :user
534
- end
535
- ```
527
+ This class represents the data and columns contained in the standard Parse `_Session` collection. You may add additional properties and methods to this class. See [Session API Reference](http://www.rubydoc.info/github/modernistik/parse-stack/Parse/Session).
536
528
 
537
529
  You can get a specific `Parse::Session` given a session_token by using the `session` method. You can also find the user tied to a specific Parse session or session token with `Parse::User.session`.
538
530
 
@@ -547,52 +539,13 @@ user = Parse::User.session(token)
547
539
  ```
548
540
 
549
541
  ### Parse::Installation
550
- This class represents the data and columns contained in the standard Parse `_Installation` collection. You may add additional properties and methods to this class. It is defined as follows:
551
-
552
- ```ruby
553
- class Parse::Installation < Parse::Object
554
- property :gcm_sender_id, :string, field: :GCMSenderId
555
- property :app_identifier
556
- property :app_name
557
- property :app_version
558
- property :badge, :integer
559
- property :channels, :array
560
- property :device_token
561
- property :device_token_last_modified, :integer
562
- property :device_type
563
- property :installation_id
564
- property :locale_identifier
565
- property :parse_version
566
- property :push_type
567
- property :time_zone
568
- end
569
- ```
542
+ This class represents the data and columns contained in the standard Parse `_Installation` collection. You may add additional properties and methods to this class. See [Installation API Reference](http://www.rubydoc.info/github/modernistik/parse-stack/Parse/Installation).
570
543
 
571
544
  ### Parse::Role
572
- This class represents the data and columns contained in the standard Parse `_Role` collection. You may add additional properties and methods to this class. It is defined as follows:
573
-
574
- ```ruby
575
- class Parse::Role < Parse::Object
576
- property :name
577
-
578
- has_many :roles, through: :relation
579
- has_many :users, through: :relation
580
- end
581
- ```
545
+ This class represents the data and columns contained in the standard Parse `_Role` collection. You may add additional properties and methods to this class. See [Roles API Reference](http://www.rubydoc.info/github/modernistik/parse-stack/Parse/Role).
582
546
 
583
547
  ### Parse::User
584
- This class represents the data and columns contained in the standard Parse `_User` collection. You may add additional properties and methods to this class. It is defined as follows:
585
-
586
- ```ruby
587
- class Parse::User < Parse::Object
588
- property :auth_data, :object
589
- property :email
590
- property :username
591
-
592
- end
593
- ```
594
-
595
- While `:password` is a property on the User class, which will generally be empty whenever fetching User records.
548
+ This class represents the data and columns contained in the standard Parse `_User` collection. You may add additional properties and methods to this class. See [User API Reference](http://www.rubydoc.info/github/modernistik/parse-stack/Parse/User).
596
549
 
597
550
  #### Signup
598
551
  You can signup new users in two ways. You can either use a class method `Parse::User.signup` to create a new user with the minimum fields of username, password and email, or create a `Parse::User` object can call the `signup!` method. If signup fails, it will raise the corresponding exception.
@@ -661,8 +614,8 @@ user = Parse::User.session(session_token)
661
614
  user.logout # deletes the corresponding session
662
615
  ```
663
616
 
664
- #### Linking and Unlinking Users
665
- You can signup or login uses with third-party services like Facebook and Twitter as described in: [Linking and Unlinking Users](https://parseplatform.github.io/docs/rest/guide/#linking). To do this, you must first get the corresponding authentication data for the specific service, and then apply it to the user using the linking and unlinking methods. Each method returns true or false if the action was successful. For a listing of supported third-party authentication services, see [OAuth](https://github.com/ParsePlatform/parse-server/wiki/OAuth).
617
+ #### Linking and Unlinking
618
+ You can link or unlink user accounts with third-party services like Facebook and Twitter as described in: [Linking and Unlinking Users](https://parseplatform.github.io/docs/rest/guide/#linking). To do this, you must first get the corresponding authentication data for the specific service, and then apply it to the user using the linking and unlinking methods. Each method returns true or false if the action was successful. For a listing of supported third-party authentication services, see [OAuth](https://github.com/ParsePlatform/parse-server/wiki/OAuth).
666
619
 
667
620
  ```ruby
668
621
 
@@ -712,8 +665,8 @@ end
712
665
  Properties are considered a literal-type of association. This means that a defined local property maps directly to a column name for that remote Parse class which contain the value. **All properties are implicitly formatted to map to a lower-first camelcase version in Parse (remote).** Therefore a local property defined as `like_count`, would be mapped to the remote column of `likeCount` automatically. The only special behavior to this rule is the `:id` property which maps to `objectId` in Parse. This implicit conversion mapping is the default behavior, but can be changed on a per-property basis. All Parse data types are supported and all Parse::Object subclasses already provide definitions for `:id` (objectId), `:created_at` (createdAt), `:updated_at` (updatedAt) and `:acl` (ACL) properties.
713
666
 
714
667
  - **:string** (_default_) - a generic string. Can be used as an enum field, see [Enum](#enum).
715
- - **:integer** (alias **:int**) - basic number.
716
- - **:float** - a floating numeric value.
668
+ - **:integer** (alias **:int**) - basic number. Will also generate atomic `_increment!` helper method.
669
+ - **:float** - a floating numeric value. Will also generate atomic `_increment!` helper method.
717
670
  - **:boolean** (alias **:bool**) - true/false value. This will also generate a class scope helper. See [Query Scopes](#query-scopes).
718
671
  - **:date** - a Parse date type. See [Parse::Date](#parsedate).
719
672
  - **:array** - a heterogeneous list with dirty tracking. See [Parse::CollectionProxy](https://github.com/modernistik/parse-stack/blob/master/lib/parse/model/associations/collection_proxy.rb).
@@ -724,7 +677,11 @@ Properties are considered a literal-type of association. This means that a defin
724
677
 
725
678
  For completeness, the `:id` and `:acl` data types are also defined in order to handle the Parse `objectId` field and the `ACL` object. Those are special and should not be used in your class (unless you know what you are doing). New data types can be implemented through the internal `typecast` interface. **TODO: discuss `typecast` interface in the future**
726
679
 
727
- In addition, `:boolean` data types create a special method that uses the `?` convention. As an example, if you have a property named `approved`, the normal getter `obj.approved` can return true, false or nil based on the value in Parse. However with the `obj.approved?` method, it will return true if it set to true, false for any other value.
680
+ When declaring a `:boolean` data type, it will also create a special method that uses the `?` convention. As an example, if you have a property named `approved`, the normal getter `obj.approved` can return true, false or nil based on the value in Parse. However with the `obj.approved?` method, it will return true if it set to true, false for any other value.
681
+
682
+ When declaring an `:integer` or `:float` type, it will also create a special method that performs
683
+ an atomic increment of that field through the `_increment!` and `_decrement!` methods. If you have
684
+ defined a property named `like_count` for one of these numeric types, which would create the normal getter/setter `obj.like_count`; you can now also call `obj.like_count_increment!` or `obj.like_count_decrement!` to perform the atomic operations (done server side) on this field. You may also pass an amount as an argument to these helper methods such as `obj.like_count_increment!(3)`.
728
685
 
729
686
  Using the example above, we can add the base properties to our classes.
730
687
 
@@ -1341,12 +1298,12 @@ The save operation can handle both creating and updating existing objects. If yo
1341
1298
  By default, we return `true` or `false` for save and destroy operations. If you prefer to have `Parse::Object` raise an exception instead, you can tell to do so either globally or on a per-model basis. When a save fails, it will raise a `Parse::SaveFailureError`.
1342
1299
 
1343
1300
  ```ruby
1344
- Parse::Model.raise_on_save_failure = true # globally across all models
1345
- Song.raise_on_save_failure = true # per-model
1346
-
1347
- # or per-instance raise on failure
1348
- song.save!
1301
+ # globally across all models
1302
+ Parse::Model.raise_on_save_failure = true
1303
+ Song.raise_on_save_failure = true # per-model
1349
1304
 
1305
+ # or per-instance raise on failure
1306
+ song.save!
1350
1307
  ```
1351
1308
 
1352
1309
  When enabled, if an error is returned by Parse due to saving or destroying a record, due to your `before_save` or `before_delete` validation cloud code triggers, `Parse::Object` will return the a `Parse::SaveFailureError` exception type. This exception has an instance method of `#object` which contains the object that failed to save.
@@ -1412,8 +1369,8 @@ The `has_many` Parse Relation associations are handled similarly as in the array
1412
1369
 
1413
1370
  ```
1414
1371
 
1415
- ### Batch Save Requests
1416
- Batch requests are supported implicitly and intelligently through an extension of array. When an array of `Parse::Object` subclasses is saved, Parse-Stack will batch all possible save operations for the objects in the array that have changed. It will also batch save 50 at a time until all items in the array are saved. *Note: Parse does not allow batch saving Parse::User objects.*
1372
+ ### Batch Requests
1373
+ Batch requests are supported implicitly and intelligently through an extension of Array. When an array of `Parse::Object` subclasses is saved, Parse-Stack will batch all possible save operations for the objects in the array that have changed. It will also batch save 50 at a time until all items in the array are saved. The objects do not have to be of the same collection in order to be supported in the batch request. *Note: Parse does not allow batch saving Parse::User objects.*
1417
1374
 
1418
1375
  ```ruby
1419
1376
  songs = Songs.first 1000 #first 1000 songs
@@ -1423,6 +1380,9 @@ end
1423
1380
 
1424
1381
  # will batch save 50 items at a time until all are saved.
1425
1382
  songs.save
1383
+
1384
+ # you can also destroy a set of objects
1385
+ songs.destroy
1426
1386
  ```
1427
1387
 
1428
1388
  ### Magic `save_all`
@@ -2199,7 +2159,7 @@ You can register webhooks to handle the different object triggers: `:before_save
2199
2159
 
2200
2160
  For any `after_*` hook, return values are not needed since Parse does not utilize them. You may also register as many `after_save` or `after_delete` handlers as you prefer, all of them will be called.
2201
2161
 
2202
- `before_save` and `before_delete` hooks have special functionality. When the `error!` method is called by the provided block, the framework will return the correct error response to Parse with value provided. Returning an error will prevent Parse from saving the object in the case of `before_save` and will prevent Parse from deleting the object when in a `before_delete`. In addition, for a `before_save`, the last value returned by the block will be the value returned in the success response. If the block returns nil or an `empty?` value, it will return `true` as the default response. You can also return a JSON object in a hash format to override the values that will be saved. However, we recommend modifying the `parse_object` provided since it has dirty tracking, and then returning that same object. This will automatically call your model specific `before_save` callbacks and send the proper payload back to Parse. For more details, see [Cloud Code BeforeSave Webhooks](https://parse.com/docs/cloudcode/guide#cloud-code-advanced-beforesave-webhooks)
2162
+ `before_save` and `before_delete` hooks have special functionality. When the `error!` method is called by the provided block, the framework will return the correct error response to Parse with value provided. Returning an error will prevent Parse from saving the object in the case of `before_save` and will prevent Parse from deleting the object when in a `before_delete`. In addition, for a `before_save`, the last value returned by the block will be the value returned in the success response. If the block returns nil or an `empty?` value, it will return `true` as the default response. You can also return a JSON object in a hash format to override the values that will be saved. However, we recommend modifying the `parse_object` provided since it has dirty tracking, and then returning that same object. This will automatically call your model specific `before_save` callbacks and send the proper payload back to Parse. For more details, see [Cloud Code BeforeSave Webhooks](http://parseplatform.github.io/docs/cloudcode/guide/#cloud-code-advanced-beforesave-webhooks)
2203
2163
 
2204
2164
  ```ruby
2205
2165
  # recommended way
@@ -2290,7 +2250,7 @@ However, we have predefined a few rake tasks you can use in your application. Ju
2290
2250
  Then you can see the tasks available by typing `rake -T`.
2291
2251
 
2292
2252
  ## Parse REST API Client
2293
- While in most cases you do not have to work with `Parse::Client` directly, you can still utilize it for any raw requests that are not supported by the framework. We provide support for most of the [Parse REST API](https://parse.com/docs/rest/guide#quick-reference) endpoints as helper methods, however you can use the `request()` method to make your own API requests. Parse::Client will handle header authentication, request/response generation and caching.
2253
+ While in most cases you do not have to work with `Parse::Client` directly, you can still utilize it for any raw requests that are not supported by the framework. We provide support for most of the [Parse REST API](http://parseplatform.github.io/docs/rest/guide/#quick-reference) endpoints as helper methods, however you can use the `request()` method to make your own API requests. Parse::Client will handle header authentication, request/response generation and caching.
2294
2254
 
2295
2255
  ```ruby
2296
2256
  client = Parse::Client.new(application_id: <string>, api_key: <string>) do |conn|
@@ -2326,7 +2286,7 @@ If you are already have setup a client that is being used by your defined models
2326
2286
  - **master_key**: The master secret key for the application. If this is provided, `api_key` may be unnecessary.
2327
2287
  - **logging**: A boolean value to add additional logging messages.
2328
2288
  - **cache**: A [Moneta](https://github.com/minad/moneta) cache store that can be used to cache API requests. We recommend use a cache store that supports native expires like [Redis](http://redis.io). For more information see `Parse::Middleware::Caching`. Disabled by default.
2329
- - **expires**: When used with the `cache` option, sets the expiration time of cached API responses. The default is [3 seconds](https://parse.com/docs/cloudcode/guide#cloud-code-timeouts).
2289
+ - **expires**: When used with the `cache` option, sets the expiration time of cached API responses. The default is 3 seconds.
2330
2290
  - **adapter**: The connection adapter to use. Defaults to `Faraday.default_adapter`.
2331
2291
 
2332
2292
  ### Request Caching
data/lib/parse/api/all.rb CHANGED
@@ -14,3 +14,10 @@ require_relative "push"
14
14
  require_relative "schemas"
15
15
  require_relative "sessions"
16
16
  require_relative "users"
17
+
18
+ module Parse
19
+ # The module containing most of the REST API requests supported by Parse Server.
20
+ # Defines all the Parse REST API endpoints.
21
+ module API
22
+ end
23
+ end
@@ -4,10 +4,15 @@
4
4
  module Parse
5
5
 
6
6
  module API
7
+ # Defines the Analytics interface for the Parse REST API
7
8
  module Analytics
8
- # Sends analytics data
9
- def send_analytics(event_name, data = {})
10
- request :post, "events/#{event_name}", body: data
9
+
10
+ # Send analytics data.
11
+ # @param event_name [String] the name of the event.
12
+ # @param metrics [Hash] the metrics to attach to event.
13
+ # @see https://parseplatform.github.io/docs/rest/guide/#analytics-app-open-analytics Parse Analytics
14
+ def send_analytics(event_name, metrics = {})
15
+ request :post, "events/#{event_name}", body: metrics
11
16
  end
12
17
 
13
18
  end
@@ -4,25 +4,53 @@
4
4
  module Parse
5
5
 
6
6
  module API
7
-
7
+ # Defines the Apps interface for the Parse REST API
8
8
  module Apps
9
9
 
10
10
  APPS_PATH = "apps"
11
+
12
+ # Fetch the application keys.
13
+ # @param appid [String] the application id.
14
+ # @param email [String] your hosted Parse account email.
15
+ # @param password [String] your hosted Parse account password.
16
+ # @param headers [Hash] additional HTTP headers to send with the request.
17
+ # @note Only supported by the hosted Parse platform and not the open source Parse-Server.
18
+ # @return [Parse::Response]
11
19
  def fetch_app_keys(appid, email, password, headers: {})
12
20
  headers.merge!( { Parse::Protocol::EMAIL => email, Parse::Protocol::PASSWORD => password } )
13
21
  request :get, "#{APPS_PATH}/#{appid}", headers: headers
14
22
  end
15
23
 
24
+ # Fetch the applications.
25
+ # @param email [String] your hosted Parse account email.
26
+ # @param password [String] your hosted Parse account password.
27
+ # @param headers [Hash] additional HTTP headers to send with the request.
28
+ # @note Only supported by the hosted Parse platform and not the open source Parse-Server.
29
+ # @return [Parse::Response]
16
30
  def fetch_apps(email, password, headers: {})
17
31
  headers.merge!( { Parse::Protocol::EMAIL => email, Parse::Protocol::PASSWORD => password } )
18
32
  request :get, APPS_PATH, headers: headers
19
33
  end
20
34
 
35
+ # Create a new application in the hosted Parse Platform.
36
+ # @param body [Hash] parameters for creating the app.
37
+ # @param email [String] your hosted Parse account email.
38
+ # @param password [String] your hosted Parse account password.
39
+ # @param headers [Hash] additional HTTP headers to send with the request.
40
+ # @note Only supported by the hosted Parse platform and not the open source Parse-Server.
41
+ # @return [Parse::Response]
21
42
  def create_app(body, email, password, headers: {})
22
43
  headers.merge!( { Parse::Protocol::EMAIL => email, Parse::Protocol::PASSWORD => password } )
23
44
  request :post, APPS_PATH, body: body, headers: headers
24
45
  end
25
46
 
47
+ # @param appid [String] the application id.
48
+ # @param body [Hash] parameters to update the app.
49
+ # @param email [String] your hosted Parse account email.
50
+ # @param password [String] your hosted Parse account password.
51
+ # @param headers [Hash] additional HTTP headers to send with the request.
52
+ # @note Only supported by the hosted Parse platform and not the open source Parse-Server.
53
+ # @return [Parse::Response]
26
54
  def update_app(appid, body, email, password, headers: {})
27
55
  headers.merge!( { Parse::Protocol::EMAIL => email, Parse::Protocol::PASSWORD => password } )
28
56
  request :put, "#{APPS_PATH}/#{appid}", body: body, headers: headers
@@ -4,140 +4,25 @@
4
4
  require 'parallel'
5
5
  require 'active_support'
6
6
  require 'active_support/core_ext'
7
- class Array
8
-
9
- def destroy
10
- batch = Parse::BatchOperation.new
11
- each do |o|
12
- next unless o.respond_to?(:destroy_request)
13
- r = o.destroy_request
14
- batch.add(r) unless r.nil?
15
- end
16
- batch.submit
17
- batch
18
- end
19
-
20
- def save(merge: true, force: false)
21
- batch = Parse::BatchOperation.new
22
- objects = {}
23
- each do |o|
24
- next unless o.is_a?(Parse::Object)
25
- objects[o.object_id] = o
26
- batch.add o.change_requests(force)
27
- end
28
- if merge == false
29
- batch.submit
30
- return batch
31
- end
32
- #rebind updates
33
- batch.submit do |request, response|
34
- next unless request.tag.present? && response.present? && response.success?
35
- o = objects[request.tag]
36
- next unless o.is_a?(Parse::Object)
37
- result = response.result
38
- o.id = result['objectId'] if o.id.blank?
39
- o.set_attributes!(result)
40
- o.clear_changes!
41
- end
42
- batch
43
- end #save!
44
-
45
- end
46
7
 
47
8
  module Parse
48
9
 
49
- def self.batch(reqs = nil)
50
- BatchOperation.new(reqs)
51
- end
52
-
53
- class BatchOperation
54
-
55
- attr_accessor :requests, :responses
56
- include Enumerable
57
-
58
- def client
59
- @client ||= Parse::Client.client
60
- end
61
-
62
- def initialize(reqs = nil)
63
- @requests = []
64
- @responses = []
65
- reqs = [reqs] unless reqs.is_a?(Enumerable)
66
- reqs.each { |r| add(r) } if reqs.is_a?(Enumerable)
67
- end
68
-
69
- def add(req)
70
- if req.respond_to?(:change_requests)
71
- requests = req.change_requests.select { |r| r.is_a?(Parse::Request) }
72
- @requests += requests
73
- elsif req.is_a?(Array)
74
- requests = req.select { |r| r.is_a?(Parse::Request) }
75
- @requests += requests
76
- elsif req.is_a?(BatchOperation)
77
- @requests += req.requests if req.is_a?(BatchOperation)
78
- else
79
- @requests.push(req) if req.is_a?(Parse::Request)
80
- end
81
- @requests
82
- end
83
-
84
- # make Batching interoperable with object methods. This allows adding a batch
85
- # to another batch.
86
- def change_requests
87
- @requests
88
- end
89
-
90
- def each
91
- return enum_for(:each) unless block_given?
92
- @requests.each(&Proc.new)
93
- self
94
- end
95
-
96
- def as_json(*args)
97
- { requests: requests }.as_json
98
- end
99
-
100
- def count
101
- @requests.count
102
- end
103
-
104
- def clear!
105
- @requests.clear
106
- end
107
-
108
- def success?
109
- return false if @responses.empty?
110
- @responses.compact.all?(&:success?)
111
- end
112
-
113
- def error?
114
- return false if @responses.empty?
115
- ! success?
116
- end
117
- # Note that N requests sent in a batch will still count toward
118
- # your request limit as N requests.
119
- def submit(segment = 50)
120
- @responses = []
121
- @requests.uniq!(&:signature)
122
- @requests.each_slice(segment) do |slice|
123
- @responses << client.batch_request( BatchOperation.new(slice) )
124
- #throttle
125
- # sleep (slice.count.to_f / MAX_REQ_SEC.to_f )
126
- end
127
- @responses.flatten!
128
- #puts "Requests: #{@requests.count} == Response: #{@responses.count}"
129
- @requests.zip(@responses).each(&Proc.new) if block_given?
130
- @responses
131
- end
132
- alias_method :save, :submit
133
-
134
-
135
- end
136
-
137
10
  module API
138
- #object fetch methods
139
-
11
+ # Defines the Batch interface for the Parse REST API
12
+ # @see Parse::BatchOperation
13
+ # @see Array.destroy
14
+ # @see Array.save
140
15
  module Batch
16
+ # @note You cannot use batch_requests with {Parse::User} instances that need to
17
+ # be created.
18
+ # @overload batch_request(requests)
19
+ # Perform a set of {Parse::Request} instances as a batch operation.
20
+ # @param requests [Array<Parse::Request>] the set of requests to batch.
21
+ # @overload batch_request(operation)
22
+ # Submit a batch operation.
23
+ # @param operation [Parse::BatchOperation] the batch operation.
24
+ # @return [Array<Parse::Response>] if successful, a set of responses for each operation in the batch.
25
+ # @return [Parse::Response] if an error occurred, the error response.
141
26
  def batch_request(batch_operations)
142
27
  unless batch_operations.is_a?(Parse::BatchOperation)
143
28
  batch_operations = Parse::BatchOperation.new batch_operations
@@ -4,12 +4,21 @@
4
4
  module Parse
5
5
 
6
6
  module API
7
+ # Defines the CloudCode interface for the Parse REST API
7
8
  module CloudFunctions
8
9
 
10
+ # Call a cloud function.
11
+ # @param name [String] the name of the cloud function.
12
+ # @param body [Hash] the parameters to forward to the function.
13
+ # @return [Parse::Response]
9
14
  def call_function(name, body = {})
10
15
  request :post, "functions/#{name}", body: body
11
16
  end
12
17
 
18
+ # Trigger a job.
19
+ # @param name [String] the name of the job to trigger.
20
+ # @param body [Hash] the parameters to forward to the job.
21
+ # @return [Parse::Response]
13
22
  def trigger_job(name, body = {})
14
23
  request :post, "jobs/#{name}", body: body
15
24
  end
@@ -4,15 +4,21 @@
4
4
  module Parse
5
5
 
6
6
  module API
7
- #object fetch methods
7
+ # Defines the Config interface for the Parse REST API
8
8
  module Config
9
+ # @return [Hash] the cached config hash for the client.
9
10
  attr_accessor :config
10
11
  CONFIG_PATH = "config"
12
+
13
+ # @return [Hash] force fetch the application configuration hash.
11
14
  def config!
12
15
  @config = nil
13
16
  self.config
14
17
  end
15
18
 
19
+ # Return the configuration hash for the configured application for this client.
20
+ # This method caches the configuration after the first time it is fetched.
21
+ # @return [Hash] force fetch the application configuration hash.
16
22
  def config
17
23
  if @config.nil?
18
24
  response = request :get, CONFIG_PATH
@@ -23,6 +29,9 @@ module Parse
23
29
  @config
24
30
  end
25
31
 
32
+ # Update the application configuration
33
+ # @param params [Hash] the hash of key value pairs.
34
+ # @return [Boolean] true if the configuration was successfully updated.
26
35
  def update_config(params)
27
36
  body = { params: params }
28
37
  response = request :put, CONFIG_PATH, body: body
@@ -7,10 +7,15 @@ require 'active_support/core_ext'
7
7
  module Parse
8
8
 
9
9
  module API
10
- #object fetch methods
10
+ # Defines the Parse Files interface for the Parse REST API
11
11
  module Files
12
12
  FILES_PATH = "files"
13
- # /1/classes/<className> POST Creating Objects
13
+
14
+ # Upload and create a Parse file.
15
+ # @param fileName [String] the basename of the file.
16
+ # @param data [Hash] the data related to this file.
17
+ # @param content_type [String] the mime-type of the file.
18
+ # @return [Parse::Response]
14
19
  def create_file(fileName, data = {}, content_type = nil)
15
20
  headers = {}
16
21
  headers.merge!( { Parse::Protocol::CONTENT_TYPE => content_type.to_s } ) if content_type.present?