opium 1.5.3 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +103 -0
- data/lib/opium/installation.rb +6 -1
- data/lib/opium/model/connectable.rb +4 -0
- data/lib/opium/version.rb +1 -1
- data/spec/opium/installation_spec.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e532f3a073fd1b08d3b659faf9a2012b75de256
|
4
|
+
data.tar.gz: c4df755ca1dd1d8f3af4822740e8bb086197679b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1caaf649218ecbc0ac3e69ae32bc5d8f087b2189ff9280f3b335010ae4173ee5dc7d74b7c9df987607205a1a6d667dde62df44e11d51c115d71e8f4c2ca7e3f9
|
7
|
+
data.tar.gz: fa9d3fdf08b4c3c635fd579529540aade5b3c7bcb5ceea1cc4fb56ad8e27edf5825aa37cfa767313625c31646baa7ae91f6414bba93711c92c0a97bdeaf5ed96
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 1.5.4
|
2
|
+
### Resolved Issues
|
3
|
+
- #55: Opium::Installation was not properly using the master key for performing queries. Parse requires the presence of the master key to perform any sort of non-id query on installations.
|
4
|
+
|
1
5
|
## 1.5.3
|
2
6
|
### New Features
|
3
7
|
- #54: Installation queries are now supported by Opium::Push to perform a more finely targeted push.
|
data/README.md
CHANGED
@@ -285,6 +285,80 @@ JSON serialization is built around an object's `attributes` hash, which is publi
|
|
285
285
|
|
286
286
|
Be aware that all Opium models use `ActiveModel::ForbiddenAttributesProtection` for mass assignment sanitization.
|
287
287
|
|
288
|
+
### Special Models: User and Installation
|
289
|
+
|
290
|
+
Parse defines a couple of utility classes for each app, which require special access privileges. Amongst these are two models for dealing with users of the app and the devices the app are installed on.
|
291
|
+
|
292
|
+
Opium provides wrappers around these constructs, in the form of `Opium::User` and `Opium::Installation`. For the most part, these two classes behave exactly like other models. Both classes are inheritable, so you can extend either of them with more information as necessary. Please be aware that the new subclasses will still be wrapping the core parse model, rather than being new models within the app; this means that you can still access their data via their superclasses, but would lose the convenient access to custom data.
|
293
|
+
|
294
|
+
#### Opium::User
|
295
|
+
|
296
|
+
The user model comes with the following data defined upon it:
|
297
|
+
|
298
|
+
| Field | Data type |
|
299
|
+
|----------------|----------------|
|
300
|
+
| id | String |
|
301
|
+
| created_at | DateTime |
|
302
|
+
| updated_at | DateTime |
|
303
|
+
| username | String |
|
304
|
+
| password | String |
|
305
|
+
| email | String |
|
306
|
+
| email_verified | Opium::Boolean |
|
307
|
+
| session_token | String |
|
308
|
+
|
309
|
+
To further customize the User model with other fields, associations, or scopes, you can subclass `Opium::User`, as in the following example:
|
310
|
+
|
311
|
+
```ruby
|
312
|
+
class CustomUser < Opium::User
|
313
|
+
field :gamer_score, type: Integer
|
314
|
+
has_many :high_scores
|
315
|
+
end
|
316
|
+
```
|
317
|
+
|
318
|
+
Note that as `Opium::User` is already an `Opium::Model`, you do not need to include that module into the custom user.
|
319
|
+
|
320
|
+
`Opium::User` provides a set of utility methods at the class level for handling user authentication and session handling.
|
321
|
+
|
322
|
+
- `authenticate[!]`: takes two parameters, being the `username` and `password` combo to test. Passwords are assumed to be in cleartext, so plan accordingly. The bang version of this method will raise an exception on failure, while the regular method will silently fail with nil. Otherwise, returns the instance of `Opium::User` associated with the provided credentials.
|
323
|
+
- `find_by_session_token`: takes a single parameter, the token to search for. Should the token be found, the associated user object is returned. If the token is not found, raises an exception.
|
324
|
+
|
325
|
+
At the instance level, `Opium::User` also provides a set of methods for reseting the users password:
|
326
|
+
|
327
|
+
- `reset_password[!]`: requires the user have a set email address. The bang variant will raise an exception on failure, while the regular method sets an error in the instance's `errors` object. Requests that parse reset the password for this current user, who will then get information sent to them via their email address.
|
328
|
+
|
329
|
+
#### Opium::Installation
|
330
|
+
|
331
|
+
The `Opium::Installation` class comes with a number of different fields predefined upon it:
|
332
|
+
|
333
|
+
| Field | Data Type |
|
334
|
+
|-----------------|-----------|
|
335
|
+
| id | String |
|
336
|
+
| created_at | DateTime |
|
337
|
+
| updated_at | DateTime |
|
338
|
+
| badge | Integer |
|
339
|
+
| channels | Array |
|
340
|
+
| time_zone | String |
|
341
|
+
| device_type | Symbol |
|
342
|
+
| push_type | Symbol |
|
343
|
+
| gcm_sender_id | Integer |
|
344
|
+
| installation_id | String |
|
345
|
+
| device_token | String |
|
346
|
+
| channel_uris | Array |
|
347
|
+
| app_name | String |
|
348
|
+
| app_version | String |
|
349
|
+
| parse_version | String |
|
350
|
+
| app_identifier | String |
|
351
|
+
|
352
|
+
Like `Opium::User`, the `Installation` class may be extended to provide access to more information stored within the parse database:
|
353
|
+
|
354
|
+
```ruby
|
355
|
+
class CustomInstallation < Opium::Installation
|
356
|
+
field :notify_on_score_change, type: Opium::Boolean
|
357
|
+
end
|
358
|
+
```
|
359
|
+
|
360
|
+
Installations provide a convenient method to perform advanced targeting when sending [push notifications](#push-notifications).
|
361
|
+
|
288
362
|
### Creating and updating models
|
289
363
|
|
290
364
|
After defining a model with Opium, you might want to create new instances of it, or update the data of an existing instance. Opium has been designed to be familiar to anyone who has used other Rails-centric ORMs, such as ActiveRecord. In this regard, object creation follows two patterns: delayed persistence, and immediate persistence.
|
@@ -406,6 +480,35 @@ gem 'opium'
|
|
406
480
|
|
407
481
|
Models and Criteria will gain the methods defined by Kaminari, and should be compatible with Kaminari's pagination partials.
|
408
482
|
|
483
|
+
## Push Notifications
|
484
|
+
|
485
|
+
Opium provides support for Parse's push endpoint via the `Opium::Push` class. The following attributes may be configured on a push before it is created:
|
486
|
+
|
487
|
+
- `channels`: an array of strings, indicating the channels to send the push to.
|
488
|
+
- `where`: used to perform an installation query. See [advanced targeting](#advanced-targeting) for more details.
|
489
|
+
- `data`: a payload hash to be delivered as part of the push.
|
490
|
+
- `expires_at`: the DateTime when the push expires; Parse will no longer attempt to send the notification after this time.
|
491
|
+
- `push_at`: used to schedule the notification for some point in the future.
|
492
|
+
- `exiration_interval`: used with `push_at`; specifies an interval, expressed in seconds relative to `push_at`, to attempt to send the notification for.
|
493
|
+
|
494
|
+
Note that `expires_at` and `push_at` are mutually exclusive; Opium prioritizes `push_at`. `push_at` can only be a value within a two week window of Time.now.
|
495
|
+
|
496
|
+
Furthermore, the `data` payload has some common fields which are accessible from the push object itself:
|
497
|
+
|
498
|
+
- `alert`: A message payload to send. Assumed to be a string.
|
499
|
+
- `badge`: (iOS only) can be either a string value of "Increment" to increase the badge count by 1 on the receiving device, or a number indicating the new badge count.
|
500
|
+
- `sound`: (iOS only) a string indicating the file within the app bundle to play upon receiving the notification.
|
501
|
+
- `content_available`: (iOS only) will cause the app to trigger a background download if set to a value of 1.
|
502
|
+
- `category`: (iOS only) the identifier of the UIUserNotificationCategory of this notification.
|
503
|
+
- `uri`: (android only) specifies an Activity to be activated associated with the provided value.
|
504
|
+
- `title`: (android only) the value displayed in for the push in the system tray.
|
505
|
+
|
506
|
+
Note that note all of these data are supported on all platforms.
|
507
|
+
|
508
|
+
Once the push has be configured as desired, it can be sent out by triggering the `create` method, which will either raise an error on failure or return true on success. Note that a truthy return value does not necessarily indicate that Parse has successfully sent any notifications; rather it merely indicates that Parse has successfully received the push request and did not find anything egregious in it.
|
509
|
+
|
510
|
+
### Advanced Targeting
|
511
|
+
|
409
512
|
## Contributing
|
410
513
|
|
411
514
|
1. Fork it ( https://github.com/[my-github-username]/opium/fork )
|
data/lib/opium/installation.rb
CHANGED
@@ -3,7 +3,12 @@ module Opium
|
|
3
3
|
include Opium::Model
|
4
4
|
|
5
5
|
no_object_prefix!
|
6
|
-
|
6
|
+
no_really_i_need_master!
|
7
|
+
|
8
|
+
def self.inherited( subclass )
|
9
|
+
subclass.no_really_i_need_master!
|
10
|
+
super
|
11
|
+
end
|
7
12
|
|
8
13
|
field :badge, type: Integer
|
9
14
|
field :channels, type: Array
|
data/lib/opium/version.rb
CHANGED
@@ -6,7 +6,7 @@ describe Opium::Installation do
|
|
6
6
|
|
7
7
|
it { should be_an( Opium::Model ) }
|
8
8
|
|
9
|
-
it { expect( described_class ).to
|
9
|
+
it { expect( described_class ).to have_a_master_complex }
|
10
10
|
|
11
11
|
describe '#object_prefix' do
|
12
12
|
it { expect( described_class.object_prefix ).to be_empty }
|
@@ -41,7 +41,8 @@ describe Opium::Installation do
|
|
41
41
|
it { is_expected.to respond_to( :field, :fields ) }
|
42
42
|
it { expect( subject.fields.keys ).to include( 'badge', 'device_token', 'has_web_access' ) }
|
43
43
|
|
44
|
-
it { expect( subject ).to have_heightened_privileges }
|
44
|
+
# it { expect( subject ).to have_heightened_privileges }
|
45
|
+
it { expect( subject ).to have_a_master_complex }
|
45
46
|
|
46
47
|
describe '#object_prefix' do
|
47
48
|
it { expect( subject.object_prefix ).to be_empty }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Bowers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|