opium 1.2.4 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20938c9338f0dea54366b7ae20a74a5e416c1b3e
4
- data.tar.gz: 901e5c2f20e9db92da93f2e32fd0c64bc6323269
3
+ metadata.gz: 6654bbb09c0e23b6fb3c05a5cf1f2515029383db
4
+ data.tar.gz: e32e0bd58f3c71d69bf6ea6cfea1ed1a0d00f60e
5
5
  SHA512:
6
- metadata.gz: 812b467de4ac66ffedd6b3bf7be8965b09af23a3a9bd8253dfac3ecf4cc7dc1608458bb27e3f116142ef77d220f83c3b4b6d1d4d11230859c0fbef1d9021a89f
7
- data.tar.gz: f5f78274f8963237dee6db4dd81d27e383d3440a550f7a5105e0ae2ce3769ec5b71d13149d79d6ffe56839dac0c727061d872ec695ac289ae299539f773d0811
6
+ metadata.gz: a178267af93078ede88138342b5ff9438acfcc4f062b9938c0e7b76ceff69488230bbf2a121109d3a9400625174197d83274d9d4c8844fc617d73043b2b1bc83
7
+ data.tar.gz: ca37ddc7b04eb11ba164fb9d9a9877b47aaa9ed057ddb7a381d763476ea2f367aac978dd01c399a5e7e3b4f37e408779e953c2e918c43cc9f564b04c1954698b
data/.travis.yml CHANGED
@@ -6,7 +6,10 @@ rvm:
6
6
  - 2.0.0
7
7
  - 2.1.2
8
8
  - 2.2.0
9
-
9
+
10
+ before_install:
11
+ - gem update bundler
12
+
10
13
  script: 'bundle exec rake'
11
14
 
12
15
  notifications:
@@ -14,4 +17,4 @@ notifications:
14
17
  recipients:
15
18
  - joshua.bowers+code@gmail.com
16
19
  on_failure: change
17
- on_success: never
20
+ on_success: never
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.3.0
2
+ ### New Features
3
+ - Now have basic support for sending push notifications via the parse server.
4
+
1
5
  ## 1.2.4
2
6
  ### Resolved Issues
3
7
  - #49: Opium::File#to_ruby now correctly handles blank/empty strings.
@@ -60,9 +64,9 @@
60
64
  ## 1.1.0
61
65
 
62
66
  ### New Features
63
- - #29: `Opium::File` is now a supported field type, which wraps Parse's File objects.
67
+ - #29: `Opium::File` is now a supported field type, which wraps Parse's File objects.
64
68
  - #31: `Symbol` is now a supported field type, which is meant to be used on top of a Parse String column.
65
69
 
66
70
  ### Resolved Issues
67
71
  - #30: ActionController compatibility is increased: `.all` and `#update` should work without causing any issues.
68
- - #10: `#attributes=` delegates to a setter for an unknown field preferentially, if the setter is present.
72
+ - #10: `#attributes=` delegates to a setter for an unknown field preferentially, if the setter is present.
data/lib/opium/push.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'opium/model/connectable'
2
+
3
+ module Opium
4
+ class Push
5
+ include Opium::Model::Connectable
6
+
7
+ def initialize( attributes = {} )
8
+ self.channels = []
9
+ self.data = {}.with_indifferent_access
10
+ end
11
+
12
+ attr_accessor :channels, :data
13
+
14
+ def alert
15
+ data[:alert]
16
+ end
17
+
18
+ def alert=( value )
19
+ self.data[:alert] = value
20
+ end
21
+
22
+ def create
23
+ fail ArgumentError, 'No channels were specified!' if channels.empty?
24
+ self.class.as_resource(:push) do
25
+ result = self.class.http_post post_data
26
+ result[:result]
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def post_data
33
+ {
34
+ channels: self.channels,
35
+ data: self.data
36
+ }
37
+ end
38
+ end
39
+ end
data/lib/opium/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Opium
2
- VERSION = "1.2.4"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/opium.rb CHANGED
@@ -8,4 +8,5 @@ require 'opium/model'
8
8
  require 'opium/user'
9
9
  require 'opium/file'
10
10
  require 'opium/schema'
11
+ require 'opium/push'
11
12
  require 'opium/railtie' if defined?( Rails )
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe Opium::Push do
4
+ it { expect( described_class ).to be <= Opium::Model::Connectable }
5
+
6
+ it { expect( described_class ).to respond_to(:to_ruby, :to_parse).with(1).argument }
7
+
8
+ it { is_expected.to respond_to( :create, :channels, :data, :alert ) }
9
+
10
+ describe '#alert' do
11
+ let(:result) do
12
+ subject.data = data
13
+ subject.alert
14
+ end
15
+
16
+ context 'with no data' do
17
+ let(:data) { { } }
18
+
19
+ it 'equals data[:alert]' do
20
+ expect( result ).to be_nil
21
+ end
22
+ end
23
+
24
+ context 'with alert data' do
25
+ let(:data) { { alert: 'The sky is blue.' } }
26
+
27
+ it 'equals data[:alert]' do
28
+ expect( result ).to eq data[:alert]
29
+ end
30
+ end
31
+ end
32
+
33
+ describe '#alert=' do
34
+ let(:result) do
35
+ subject.alert = alert
36
+ subject.data[:alert]
37
+ end
38
+
39
+ context 'with nothing' do
40
+ let(:alert) { nil }
41
+
42
+ it 'equals data[:alert]' do
43
+ expect( result ).to be_nil
44
+ end
45
+ end
46
+
47
+ context 'with text' do
48
+ let(:alert) { 'The sky is blue.' }
49
+
50
+ it 'equals data[:alert]' do
51
+ expect( result ).to eq alert
52
+ end
53
+ end
54
+ end
55
+
56
+ describe '#create' do
57
+ let(:result) do
58
+ subject.tap do |push|
59
+ push.channels = channels
60
+ push.alert = alert
61
+ end.create
62
+ end
63
+
64
+ let(:alert) { 'Zoo animals are fighting!' }
65
+
66
+ before do
67
+ stub_request(:post, "https://api.parse.com/1/push").
68
+ with(body: "{\"channels\":[\"Penguins\",\"PolarBears\"],\"data\":{\"alert\":\"Zoo animals are fighting!\"}}",
69
+ headers: {'Content-Type'=>'application/json', 'X-Parse-Application-Id'=>'PARSE_APP_ID', 'X-Parse-Rest-Api-Key'=>'PARSE_API_KEY'}).
70
+ to_return(:status => 200, :body => { result: true }.to_json, :headers => {content_type: 'application/json'})
71
+ end
72
+
73
+ context 'with no channels' do
74
+ let(:channels) { [] }
75
+
76
+ it { expect { result }.to raise_exception( ArgumentError ) }
77
+ end
78
+
79
+ context 'with channels' do
80
+ let(:channels) { %w{ Penguins PolarBears } }
81
+
82
+ it { expect { result }.to_not raise_exception }
83
+ it { expect( result ).to eq true }
84
+ end
85
+ end
86
+ end
data/spec/opium_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Opium do
4
- it { expect( described_class.constants ).to include( :Model, :User, :File, :Config, :Schema ) }
4
+ it { expect( described_class.constants ).to include( :Model, :User, :File, :Config, :Schema, :Push ) }
5
5
  end
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.2.4
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Bowers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-30 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -301,6 +301,7 @@ files:
301
301
  - lib/opium/model/relation.rb
302
302
  - lib/opium/model/scopable.rb
303
303
  - lib/opium/model/serialization.rb
304
+ - lib/opium/push.rb
304
305
  - lib/opium/railtie.rb
305
306
  - lib/opium/schema.rb
306
307
  - lib/opium/user.rb
@@ -346,6 +347,7 @@ files:
346
347
  - spec/opium/model/scopable_spec.rb
347
348
  - spec/opium/model/serialization_spec.rb
348
349
  - spec/opium/model_spec.rb
350
+ - spec/opium/push_spec.rb
349
351
  - spec/opium/schema_spec.rb
350
352
  - spec/opium/user_spec.rb
351
353
  - spec/opium_spec.rb
@@ -415,6 +417,7 @@ test_files:
415
417
  - spec/opium/model/scopable_spec.rb
416
418
  - spec/opium/model/serialization_spec.rb
417
419
  - spec/opium/model_spec.rb
420
+ - spec/opium/push_spec.rb
418
421
  - spec/opium/schema_spec.rb
419
422
  - spec/opium/user_spec.rb
420
423
  - spec/opium_spec.rb