mercurius 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fff5a024bedc9602172b080681a4ed8b28f8d45
4
- data.tar.gz: 06d8f0cd9206fc23c70cf66e48c2c1912bd3458e
3
+ metadata.gz: e9a83b6fe0b488197398d7f81294ff118c63509c
4
+ data.tar.gz: d641b9ab3f5b2651b7454f72d3399f932b2e9ef8
5
5
  SHA512:
6
- metadata.gz: 66e282ada6fef6296cf21380105f067aae9a54c27e0f0058f28b1fe467fc6595531c1aa7eef4d16017fb675ed4ef276522752436d557ef2fae0a206c40b6abb7
7
- data.tar.gz: 8caff3a87dd456736a0777607998f75a5e8b3a3dd1ef7cc2b280b776b05ac2c3bf05b4de8496050d42aefa7ebe8a2165e6ca3f8070ae4bc673ffc3228de54ede
6
+ metadata.gz: 54ef3d103e7d6a1f18bf198c7369f0a3a901eeec99bd045199f49336d5a93ad39d9992d4c5058363454f290bd17a6c25b96d59aa90a986bf602ccc5afc8c5ad8
7
+ data.tar.gz: cf40a5d26640d9de5cfc936a8fc9b7060693553d36110d828d3a2084db5787a595daf84ae3d1c4d1f18e16fd99b26bb876ddc14a1949e18f4ae141582e59549e
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ### Send push messages to Android, iOS devices.
4
4
 
5
+ This gem is designed to be easy to configure for simple operation when your needs are simple, but also allow more complicated cases such as when you need to send to multiple applications with different configurations. The interface is designed to be as similar as possible for GCM and APNS.
6
+
5
7
  ## Installation
6
8
 
7
9
  $ gem install mercurius
@@ -14,15 +16,64 @@ and install it with
14
16
 
15
17
  $ bundle install
16
18
 
17
- ## Contributing
19
+ ## GCM
18
20
 
19
- Please fork, modify, and send a pull request if you want to help improve this gem.
21
+ Set up the default GCM configuration. (All GCM::Services will be created with this configuration, but the configuration can be overridden per-service if you need to.)
22
+
23
+ GCM.key = 'your_gcm_key'
24
+
25
+ Create the service with:
26
+
27
+ gcm_service = GCM::Service.new
28
+
29
+ Now create the notification that you wish to send:
30
+
31
+ gcm_notification = GCM::Notification.new(alert: 'Hey')
32
+
33
+ You can deliver the gcm_notification in the following manners:
34
+
35
+ gcm_service.deliver gcm_notification, 'token123' # single recipient
36
+ gcm_service.deliver gcm_notification, 'token123', 'token456' # multiple recipients
37
+ token_array = ['token123', 'token456']
38
+ gcm_service.deliver gcm_notification, token_array # multiple recipients
39
+
40
+ ## APNS
41
+
42
+ The typical APNS configuration is set automatically, but you need to set the host with with either:
43
+
44
+ APNS.set_mode(:develop) # gateway.sandbox.push.apple.com
20
45
 
21
- ## Thanks
46
+ or
22
47
 
23
- This gem is based off of the 'pushmeup' gem by Nicos Karalis
48
+ APNS.set_mode(:production) # gateway.push.apple.com
24
49
 
25
- https://github.com/NicosKaralis/pushmeup
50
+ Next, you'll need to set your PEM information. This can either be with a file or with a text buffer:
51
+
52
+ pem = APNS::Pem.new(path: 'sandbox.pem', password: 'test123')
53
+ pem = APNS::Pem.new(data: pem_data_buffer, password: 'test123')
54
+
55
+ Set the default configuration:
56
+
57
+ APNS.pem = pem
58
+
59
+ Now you are ready to create the APNS::Service, which will allow you to send notifications:
60
+
61
+ apns_service = APNS::Service.new
62
+
63
+ The APNS::Service object is created with the settings from earlier, but any of them can be overridden if you need more control (for instance if you need to send with multiple PEMs)
64
+
65
+ apns_notification = APNS::Notification.new(alert: 'Hey')
66
+
67
+ The deliver method can be called in the following ways:
68
+
69
+ apns_service.deliver apns_notification, 'token123' # single recipient
70
+ apns_service.deliver apns_notification, 'token123', 'token456' # multiple recipients
71
+ token_array = ['token123', 'token456']
72
+ apns_service.deliver apns_notification, token_array # multiple recipients
73
+
74
+ ## Contributing
75
+
76
+ Please fork, modify, and send a pull request if you want to help improve this gem.
26
77
 
27
78
  ## License
28
79
 
@@ -1,10 +1,22 @@
1
1
  module APNS
2
+ HOSTS = {
3
+ develop: 'gateway.sandbox.push.apple.com',
4
+ production: 'gateway.push.apple.com',
5
+ }
6
+
2
7
  @host = ''
3
8
  @port = 2195
4
9
  @pem = nil
5
10
 
6
11
  class << self
7
12
  attr_accessor :host, :port, :pem
13
+
14
+ def set_mode(mode)
15
+ host = HOSTS.fetch(mode, nil)
16
+ raise InvalidApnsModeError.new if host.nil?
17
+ @host = host
18
+ end
19
+
8
20
  end
9
21
 
10
- end
22
+ end
@@ -0,0 +1,7 @@
1
+ class InvalidApnsModeError < StandardError
2
+
3
+ def initialize
4
+ super 'Tried to set invalid APNS mode.'
5
+ end
6
+
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Mercurius
2
- VERSION = '0.0.9'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/mercurius.rb CHANGED
@@ -7,6 +7,7 @@ require 'json'
7
7
 
8
8
  require 'mercurius/version'
9
9
 
10
+ require 'mercurius/errors/invalid_apns_mode_error'
10
11
  require 'mercurius/errors/pem_not_configured_error'
11
12
  require 'mercurius/errors/pem_not_found_error'
12
13
  require 'mercurius/errors/too_many_retries_error'
@@ -10,9 +10,9 @@ describe APNS::Service do
10
10
  end
11
11
 
12
12
  it 'should default to the APNS module configs' do
13
- expect(service.host).to eq 'gateway.sandbox.push.apple.com'
14
- expect(service.port).to eq 2195
15
- expect(service.pem.password).to eq 'test123'
13
+ expect(service.host).to eq APNS.host
14
+ expect(service.port).to eq APNS.port
15
+ expect(service.pem.password).to eq APNS.pem.password
16
16
  end
17
17
 
18
18
  describe '#send' do
@@ -0,0 +1,19 @@
1
+ describe APNS do
2
+
3
+ it 'sets up the develop mode' do
4
+ APNS.set_mode(:develop)
5
+ expect(APNS.host).to eq APNS::HOSTS[:develop]
6
+ end
7
+
8
+ it 'sets up the production mode' do
9
+ APNS.set_mode(:production)
10
+ expect(APNS.host).to eq APNS::HOSTS[:production]
11
+ end
12
+
13
+ it 'will not change the host if an invalid mode is specified' do
14
+ APNS.host = 'host'
15
+ expect { APNS.set_mode(:overdrive) }.to raise_error
16
+ expect(APNS.host).to eq 'host'
17
+ end
18
+
19
+ end
@@ -3,8 +3,8 @@ describe GCM::Service do
3
3
  let(:message) { GCM::Notification.new(alert: 'Hey') }
4
4
 
5
5
  it 'should default to the GCM module configs' do
6
- expect(service.host).to eq 'https://android.googleapis.com/'
7
- expect(service.key).to be_nil
6
+ expect(service.host).to eq GCM.host
7
+ expect(service.key).to GCM.key
8
8
  end
9
9
 
10
10
  describe '#send' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercurius
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Beck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -145,6 +145,7 @@ files:
145
145
  - lib/mercurius/apns/notification.rb
146
146
  - lib/mercurius/apns/pem.rb
147
147
  - lib/mercurius/apns/service.rb
148
+ - lib/mercurius/errors/invalid_apns_mode_error.rb
148
149
  - lib/mercurius/errors/pem_not_configured_error.rb
149
150
  - lib/mercurius/errors/pem_not_found_error.rb
150
151
  - lib/mercurius/errors/too_many_retries_error.rb
@@ -161,9 +162,10 @@ files:
161
162
  - lib/mercurius/testing/service.rb
162
163
  - lib/mercurius/version.rb
163
164
  - mercurius.gemspec
165
+ - spec/lib/apns_notification_spec.rb
164
166
  - spec/lib/apns_service_spec.rb
167
+ - spec/lib/apns_spec.rb
165
168
  - spec/lib/gcm_service_spec.rb
166
- - spec/lib/notification_spec.rb
167
169
  - spec/lib/testing_spec.rb
168
170
  - spec/spec_helper.rb
169
171
  - spec/support/apns.pem
@@ -192,9 +194,10 @@ signing_key:
192
194
  specification_version: 4
193
195
  summary: Send push notifications to mobile devices through native services
194
196
  test_files:
197
+ - spec/lib/apns_notification_spec.rb
195
198
  - spec/lib/apns_service_spec.rb
199
+ - spec/lib/apns_spec.rb
196
200
  - spec/lib/gcm_service_spec.rb
197
- - spec/lib/notification_spec.rb
198
201
  - spec/lib/testing_spec.rb
199
202
  - spec/spec_helper.rb
200
203
  - spec/support/apns.pem