hsquare 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hsquare.rb +1 -1
- data/lib/hsquare/notification.rb +9 -2
- data/lib/hsquare/version.rb +1 -1
- data/spec/lib/hsquare/notification_spec.rb +30 -4
- data/spec/lib/hsquare_spec.rb +1 -1
- 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: 0d1507f1c438d795d2e07722eade1b707f0406cb
|
4
|
+
data.tar.gz: 77f27aa6ceb593c0897dc4ad7c2f83afe51b8104
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7be65d1e64cc31120a655ee240103b523cdd7c74e4bd3a211cbd787e8b0481ab9e01fc5bd8f54b0cc996db47867b10eb4746f263915c933b42da5d6f9b8ca82
|
7
|
+
data.tar.gz: 52d7845f0f67a7aef317f971a77215567efd5bf9236131b6ad6a244b3a8a8c9488aa2d89d31fc97326f389fbeae597e4246656aee863e389fdce917fa9b9ba6e
|
data/lib/hsquare.rb
CHANGED
@@ -50,7 +50,7 @@ module Hsquare
|
|
50
50
|
# Returns registered Hsquare::Application object.
|
51
51
|
def self.application(label = nil)
|
52
52
|
if label
|
53
|
-
@configuration.applications.detect { |application| application.label == label.to_sym }
|
53
|
+
@configuration.applications.detect { |application| application.label == label.to_sym } || @configuration.default_application
|
54
54
|
else
|
55
55
|
@configuration.default_application
|
56
56
|
end
|
data/lib/hsquare/notification.rb
CHANGED
@@ -25,6 +25,9 @@ module Hsquare
|
|
25
25
|
# Public: Extra payload.
|
26
26
|
attr_accessor :extra
|
27
27
|
|
28
|
+
# Public: IDs of Hsquare applications to deliver.
|
29
|
+
attr_accessor :app_ids
|
30
|
+
|
28
31
|
# Public: Initializes new notification object.
|
29
32
|
#
|
30
33
|
# attributes - Attributes of the notification.
|
@@ -39,6 +42,7 @@ module Hsquare
|
|
39
42
|
# :idle_delay - Whether GCM message delivery is delayed
|
40
43
|
# while device is idle (default: false).
|
41
44
|
# :extra - Extra payload (optinoal).
|
45
|
+
# :app_ids - IDs of Hsquare applications to deliver.
|
42
46
|
#
|
43
47
|
# Returns newly initialized notification object.
|
44
48
|
def initialize(attributes = {})
|
@@ -50,6 +54,7 @@ module Hsquare
|
|
50
54
|
@collapse = attributes[:collapse]
|
51
55
|
@idle_delay = attributes.has_key?(:idle_delay) ? attributes[:idle_delay] : false
|
52
56
|
@extra = attributes[:extra]
|
57
|
+
@app_ids = attributes[:app_ids]
|
53
58
|
end
|
54
59
|
|
55
60
|
# Public: Helper method to set recipient_ids with single ID.
|
@@ -66,7 +71,9 @@ module Hsquare
|
|
66
71
|
# Returns nothing.
|
67
72
|
def deliver
|
68
73
|
Hsquare.config.applications.each do |application|
|
69
|
-
application.
|
74
|
+
if !app_ids || app_ids.include?(application.label)
|
75
|
+
application.admin_client.post('/v1/push/send', body: payload)
|
76
|
+
end
|
70
77
|
end
|
71
78
|
end
|
72
79
|
|
@@ -99,7 +106,7 @@ module Hsquare
|
|
99
106
|
{
|
100
107
|
collapse: collapse,
|
101
108
|
delay_while_idle: idle_delay,
|
102
|
-
custom_field: (extra || {}).merge(message: message)
|
109
|
+
custom_field: (extra || {}).merge(message: message, sound: sound)
|
103
110
|
}.keep_if { |_, v| !v.nil? }
|
104
111
|
end
|
105
112
|
end
|
data/lib/hsquare/version.rb
CHANGED
@@ -6,12 +6,38 @@ RSpec.describe Hsquare::Notification do
|
|
6
6
|
let(:message) { 'message' }
|
7
7
|
let(:notification) { Hsquare::Notification.new(recipient_id: recipient_id, message: message) }
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
context 'when no app ids is set' do
|
10
|
+
it do
|
11
|
+
Hsquare.config.applications.each do |application|
|
12
|
+
expect(application.admin_client).to receive(:post).with('/v1/push/send', body: { uuids: [recipient_id].to_json, push_message: { for_apns: { push_alert: true, message: message }, for_gcm: { delay_while_idle: false, custom_field: { message: message, sound: nil } } }.to_json })
|
13
|
+
end
|
14
|
+
|
15
|
+
notification.deliver
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when app ids is set' do
|
20
|
+
let(:notification) { Hsquare::Notification.new(recipient_id: recipient_id, message: message, app_ids: [nil]) }
|
21
|
+
|
22
|
+
it do
|
23
|
+
Hsquare.config.applications.each do |application|
|
24
|
+
expect(application.admin_client).to receive(:post).with('/v1/push/send', body: { uuids: [recipient_id].to_json, push_message: { for_apns: { push_alert: true, message: message }, for_gcm: { delay_while_idle: false, custom_field: { message: message, sound: nil } } }.to_json })
|
25
|
+
end
|
26
|
+
|
27
|
+
notification.deliver
|
12
28
|
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when app ids is set' do
|
32
|
+
let(:notification) { Hsquare::Notification.new(recipient_id: recipient_id, message: message, app_ids: [:not_exist]) }
|
13
33
|
|
14
|
-
|
34
|
+
it do
|
35
|
+
Hsquare.config.applications.each do |application|
|
36
|
+
expect(application.admin_client).not_to receive(:post).with('/v1/push/send', body: { uuids: [recipient_id].to_json, push_message: { for_apns: { push_alert: true, message: message }, for_gcm: { delay_while_idle: false, custom_field: { message: message } } }.to_json })
|
37
|
+
end
|
38
|
+
|
39
|
+
notification.deliver
|
40
|
+
end
|
15
41
|
end
|
16
42
|
end
|
17
43
|
|
data/spec/lib/hsquare_spec.rb
CHANGED
@@ -35,7 +35,7 @@ RSpec.describe Hsquare do
|
|
35
35
|
it { expect(Hsquare.application(:first).admin_key).to eq('firstkey') }
|
36
36
|
it { expect(Hsquare.application(:second)).not_to be_nil }
|
37
37
|
it { expect(Hsquare.application(:second).admin_key).to eq('secondkey') }
|
38
|
-
it { expect(Hsquare.application(:third)).to
|
38
|
+
it { expect(Hsquare.application(:third)).to eq(Hsquare.application(:first)) }
|
39
39
|
it { expect(Hsquare.application).not_to be_nil }
|
40
40
|
it { expect(Hsquare.application.label).to eq(:first) }
|
41
41
|
it { expect(Hsquare.application.admin_key).to eq('firstkey') }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hsquare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Inbeom Hwang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|