pushr-core 1.0.0 → 1.0.1

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: 9ffb7fb3c92d6c74cd952b1e2db925518a24b75b
4
- data.tar.gz: b167c999e085a9017a5ba924aa6b2769ced36e70
3
+ metadata.gz: d6e254858fcb2c4dc190b0fa1a6a296e57e91b59
4
+ data.tar.gz: aa3314e0f9fb385870eeb764ec2bbf87a4133a30
5
5
  SHA512:
6
- metadata.gz: 8da5f1a457ff6bdf6926318df3b3d8757d27651d7ca11a1e472d4d2587452b6e543e28d42d2bc524d0055f6e13f265b34bf546df6360a78b76a0d81d5822550c
7
- data.tar.gz: 6f2a17440d22d992863a6cd4f3ac0f5a7dd5c61b32a3764f025db1d559902a04231d24dad422c1fa7ff885561b5da443d67e762711638394196dd75f440fe0e9
6
+ metadata.gz: c97e2a1940e91880215a3d55d489260df0e5e04e1e61f818b4468d876c857229a2c3ed60f07f41d72707c3fae7f25c033297c13fd9f0421f3a214af99226fe34
7
+ data.tar.gz: 2fa7792d71e250b1e63c2389f2533459f13651b153997a9a99ba4b89c6e3bef7c5c0b193cfa75215e453d77531807b3d09a372b3be96a69b4f6bc0acb31bc1bd
data/README.md CHANGED
@@ -1,15 +1,12 @@
1
1
  # Pushr
2
2
 
3
- Please note: We're in the process of updating this gem. The current code is not yet stable. Please contact us if you
4
- want to test or contribute to this project.
5
-
6
3
  [![Build Status](https://travis-ci.org/9to5/pushr-core.svg?branch=master)](https://travis-ci.org/9to5/pushr-core)
7
4
  [![Code Climate](https://codeclimate.com/github/9to5/pushr-core.png)](https://codeclimate.com/github/9to5/pushr-core)
8
5
  [![Coverage Status](https://coveralls.io/repos/9to5/pushr-core/badge.png)](https://coveralls.io/r/9to5/pushr-core)
9
6
 
10
7
  ## Features
11
8
 
12
- * Lightening fast push notification delivery
9
+ * Lightning fast push notification delivery
13
10
  * Redis for queueing
14
11
  * Redis or YAML for configuration
15
12
  * Multi-App
@@ -133,18 +130,21 @@ Where `<options>` can be:
133
130
 
134
131
  ## Sending notifications
135
132
 
133
+ Use the `new` and `save` methods to create a message or use the `create` and `create!` methods. These methods are
134
+ similar to the ActiveRecord model methods.
135
+
136
136
  APNS:
137
137
  ```ruby
138
138
  Pushr::MessageApns.create(
139
- app: 'app_name',
140
- device: '<APNS device_token here>',
141
- alert: 'Hello World',
142
- sound: '1.aiff',
143
- badge: 1,
144
- expiry: 1.day.from_now.to_i,
145
- attributes_for_device: {key: 'MSG'},
146
- priority: 10,
147
- content_available: 1)
139
+ app: 'app_name', # required: String, the name of the configuration
140
+ device: '<APNS device_token here>', # required: String, token of the device
141
+ expiry: 1.day.from_now.to_i, # required: Integer, A UNIX epoch date expressed in seconds
142
+ priority: 10, # required: Integer, 10 or 5 (should be 10 if message includes an alert, sound or badge)
143
+ alert: 'Hello World', # optional: String or Hash, read APNS documentation for more information
144
+ sound: '1.aiff', # optional: String, sound to play
145
+ badge: 1, # optional: Integer, display badge on homescreen
146
+ attributes_for_device: {key: 'MSG'}, # optional: Hash, send additional parameters
147
+ content_available: 1) # optional: Integer, 1 if device should be notified if new content is available
148
148
  ```
149
149
 
150
150
 
@@ -168,15 +168,15 @@ Use `content_available: 1` if the iOS device should start your app upon receivin
168
168
  GCM:
169
169
  ```ruby
170
170
  Pushr::MessageGcm.create(
171
- app: 'app_name',
172
- registration_ids: ['<GCM registration_id here>', '<GCM registration_id here>'],
173
- notification_key: 'notification_key_name',
174
- delay_while_idle: true,
175
- data: { message: 'Hello World' },
176
- time_to_live: 24 * 60 * 60,
177
- restricted_package_name: 'com.example.gcm',
178
- dry_run: false,
179
- collapse_key: 'MSG')
171
+ app: 'app_name', # required: String, the name of the configuration
172
+ registration_ids: ['<registration_id>', '...'], # required: Array of registration ids
173
+ notification_key: 'notification_key_name', # optional: String, Use with User Notifications
174
+ delay_while_idle: true, # optional: Boolean, message is received if device is active
175
+ data: { message: 'Hello World' }, # optional: Hash, contains information for the app
176
+ time_to_live: 24 * 60 * 60, # optional: Integer, in seconds how long the message will be stored
177
+ restricted_package_name: 'com.example.gcm', # optional: String, message will only be received with this package name
178
+ dry_run: false, # optional: Boolean, do not actually deliver the message to the app
179
+ collapse_key: 'MSG') # optional: String, messages with the same key can be collapsed into one
180
180
  ```
181
181
 
182
182
  ## Feedback processing
@@ -33,6 +33,14 @@ module Pushr
33
33
  m
34
34
  end
35
35
 
36
+ def self.create!(attributes = {})
37
+ m = new(attributes)
38
+ unless m.save
39
+ raise Pushr::Error::RecordInvalid
40
+ end
41
+ m
42
+ end
43
+
36
44
  def delete
37
45
  Pushr::Core.redis { |conn| conn.hdel('pushr:configurations', key) }
38
46
  end
@@ -2,6 +2,7 @@ require 'yaml'
2
2
  require 'active_model'
3
3
  require 'multi_json'
4
4
  require 'pushr/version'
5
+ require 'pushr/error'
5
6
  require 'pushr/configuration'
6
7
  require 'pushr/message'
7
8
  require 'pushr/feedback'
@@ -0,0 +1,10 @@
1
+ module Pushr
2
+
3
+ # Module containing Pushr::Error classes, all of which extend StandardError.
4
+ module Error
5
+
6
+ # Raised if the entered authentication details (API key or username and password) are incorrect. (Error code: 2)
7
+ class RecordInvalid < StandardError
8
+ end
9
+ end
10
+ end
@@ -29,6 +29,14 @@ module Pushr
29
29
  m
30
30
  end
31
31
 
32
+ def self.create!(attributes = {})
33
+ m = new(attributes)
34
+ unless m.save
35
+ raise Pushr::Error::RecordInvalid
36
+ end
37
+ m
38
+ end
39
+
32
40
  def to_json
33
41
  MultiJson.dump(to_hash)
34
42
  end
@@ -26,6 +26,14 @@ module Pushr
26
26
  m
27
27
  end
28
28
 
29
+ def self.create!(attributes = {})
30
+ m = new(attributes)
31
+ unless m.save
32
+ raise Pushr::Error::RecordInvalid
33
+ end
34
+ m
35
+ end
36
+
29
37
  def to_json
30
38
  MultiJson.dump(to_hash)
31
39
  end
@@ -1,3 +1,3 @@
1
1
  module Pushr
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -49,6 +49,28 @@ describe Pushr::Configuration do
49
49
  end
50
50
  end
51
51
 
52
+ describe 'create!' do
53
+ subject { Pushr::ConfigurationDummy.create!(app: app_name, connections: 2, enabled: true) }
54
+
55
+ context 'with app name' do
56
+ let(:app_name) { 'app_name' }
57
+ it 'should create a message' do
58
+ expect(subject.valid?).to eql true
59
+ end
60
+
61
+ it 'should create a ConfigurationDummy class' do
62
+ expect(subject.class).to eql Pushr::ConfigurationDummy
63
+ end
64
+ end
65
+
66
+ context 'without app name' do
67
+ let(:app_name) { nil }
68
+ it 'should raise error' do
69
+ expect { subject }.to raise_error Pushr::Error::RecordInvalid
70
+ end
71
+ end
72
+ end
73
+
52
74
  describe 'find' do
53
75
  let!(:config) { Pushr::ConfigurationDummy.new(app: 'app_name', connections: 2, enabled: true) }
54
76
  it 'should find a configuration' do
@@ -35,4 +35,26 @@ describe Pushr::Feedback do
35
35
  expect(subject.class).to eql Pushr::FeedbackDummy
36
36
  end
37
37
  end
38
+
39
+ describe 'create!' do
40
+ subject { Pushr::FeedbackDummy.create!(app: app_name, device: 'a' * 64, follow_up: 'delete', failed_at: Time.now) }
41
+
42
+ context 'with app name' do
43
+ let(:app_name) { 'app_name' }
44
+ it 'should create a message' do
45
+ expect(subject.valid?).to eql true
46
+ end
47
+
48
+ it 'should create a FeedbackDummy class' do
49
+ expect(subject.class).to eql Pushr::FeedbackDummy
50
+ end
51
+ end
52
+
53
+ context 'without app name' do
54
+ let(:app_name) { nil }
55
+ it 'should raise error' do
56
+ expect { subject }.to raise_error Pushr::Error::RecordInvalid
57
+ end
58
+ end
59
+ end
38
60
  end
@@ -41,4 +41,26 @@ describe Pushr::Message do
41
41
  expect(subject.class).to eql Pushr::MessageDummy
42
42
  end
43
43
  end
44
+
45
+ describe 'create!' do
46
+ subject { Pushr::MessageDummy.create!(app: app_name) }
47
+
48
+ context 'with app name' do
49
+ let(:app_name) { 'app_name' }
50
+ it 'should create a message' do
51
+ expect(subject.valid?).to eql true
52
+ end
53
+
54
+ it 'should create a MessageDummy class' do
55
+ expect(subject.class).to eql Pushr::MessageDummy
56
+ end
57
+ end
58
+
59
+ context 'without app name' do
60
+ let(:app_name) { nil }
61
+ it 'should raise error' do
62
+ expect { subject }.to raise_error Pushr::Error::RecordInvalid
63
+ end
64
+ end
65
+ end
44
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushr-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Pesman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-27 00:00:00.000000000 Z
11
+ date: 2015-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: redis-namespace
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.4.1
33
+ version: '1.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.4.1
40
+ version: '1.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: multi_json
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 3.0.0.beta2
89
+ version: '3.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 3.0.0.beta2
96
+ version: '3.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -201,6 +201,9 @@ executables:
201
201
  extensions: []
202
202
  extra_rdoc_files: []
203
203
  files:
204
+ - MIT-LICENSE
205
+ - README.md
206
+ - bin/pushr
204
207
  - lib/generators/templates/feedback_processor.rb
205
208
  - lib/generators/templates/pushr.yml
206
209
  - lib/pushr/configuration.rb
@@ -213,12 +216,11 @@ files:
213
216
  - lib/pushr/daemon/message_handler.rb
214
217
  - lib/pushr/daemon/pid_file.rb
215
218
  - lib/pushr/daemon/settings.rb
219
+ - lib/pushr/error.rb
216
220
  - lib/pushr/feedback.rb
217
221
  - lib/pushr/message.rb
218
222
  - lib/pushr/redis_connection.rb
219
223
  - lib/pushr/version.rb
220
- - README.md
221
- - MIT-LICENSE
222
224
  - spec/lib/pushr/configuration_spec.rb
223
225
  - spec/lib/pushr/daemon/app_spec.rb
224
226
  - spec/lib/pushr/daemon/delivery_error_spec.rb
@@ -238,7 +240,6 @@ files:
238
240
  - spec/support/pushr_feedback_processor_dummy.rb
239
241
  - spec/support/pushr_invalid_configuration_dummy.rb
240
242
  - spec/support/pushr_message_dummy.rb
241
- - bin/pushr
242
243
  homepage: https://github.com/9to5/pushr-core
243
244
  licenses:
244
245
  - MIT
@@ -259,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
260
  version: '0'
260
261
  requirements: []
261
262
  rubyforge_project:
262
- rubygems_version: 2.1.11
263
+ rubygems_version: 2.2.2
263
264
  signing_key:
264
265
  specification_version: 4
265
266
  summary: Core of the pushr daemon.