device_cloud 0.0.5 → 0.0.6
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.
- data/lib/device_cloud/configuration.rb +12 -6
- data/lib/device_cloud/push_notification/alert_notification.rb +7 -0
- data/lib/device_cloud/push_notification/{base.rb → base_notification.rb} +1 -1
- data/lib/device_cloud/push_notification/data_notification.rb +7 -0
- data/lib/device_cloud/push_notification/event_notification.rb +7 -0
- data/lib/device_cloud/push_notification/message.rb +1 -1
- data/lib/device_cloud/push_notification.rb +1 -1
- data/lib/device_cloud/version.rb +1 -1
- data/lib/device_cloud.rb +4 -3
- data/spec/device_cloud/push_notification/{alert_spec.rb → alert_notification_spec.rb} +4 -4
- data/spec/device_cloud/push_notification/{base_spec.rb → base_notification_spec.rb} +2 -2
- data/spec/device_cloud/push_notification/data_notification_spec.rb +26 -0
- data/spec/device_cloud/push_notification/{event_spec.rb → event_notification_spec.rb} +4 -4
- data/spec/device_cloud/push_notification_spec.rb +18 -7
- data/spec/version_spec.rb +1 -1
- metadata +14 -11
- data/lib/device_cloud/push_notification/alert.rb +0 -7
- data/lib/device_cloud/push_notification/event.rb +0 -7
@@ -16,14 +16,20 @@ module DeviceCloud
|
|
16
16
|
attr_writer :logger
|
17
17
|
|
18
18
|
# Proc that will be called for handling
|
19
|
-
# DeviceCloud::PushNotification::
|
20
|
-
# Proc will be called with the event object
|
21
|
-
attr_accessor :
|
19
|
+
# DeviceCloud::PushNotification::EventNotification objects
|
20
|
+
# Proc will be called with the event notification object
|
21
|
+
attr_accessor :event_notification_handler
|
22
22
|
|
23
23
|
# Proc that will be called for handling
|
24
|
-
# DeviceCloud::PushNotification::
|
25
|
-
# Proc will be called with the alert object
|
26
|
-
attr_accessor :
|
24
|
+
# DeviceCloud::PushNotification::AlertNotification objects
|
25
|
+
# Proc will be called with the alert notification object
|
26
|
+
attr_accessor :alert_notification_handler
|
27
|
+
|
28
|
+
# Proc that will be called for handling
|
29
|
+
# DeviceCloud::PushNotification::DataNotification objects
|
30
|
+
# Proc will be called with the data notification object
|
31
|
+
attr_accessor :data_notification_handler
|
32
|
+
|
27
33
|
|
28
34
|
# Yield self to be able to configure ActivityFeed with
|
29
35
|
# block-style configuration.
|
@@ -2,7 +2,7 @@ module DeviceCloud
|
|
2
2
|
class PushNotification::Message
|
3
3
|
attr_accessor :timestamp, :topic, :file_data, :operation, :group, :replay
|
4
4
|
|
5
|
-
ALLOWED_TOPICS = %w{alert event}
|
5
|
+
ALLOWED_TOPICS = %w{alert event data}
|
6
6
|
|
7
7
|
def self.parse_raw_messages(raw_message_data)
|
8
8
|
if raw_message_data.is_a? Array
|
@@ -17,7 +17,7 @@ module DeviceCloud
|
|
17
17
|
end
|
18
18
|
private
|
19
19
|
def class_type(class_name)
|
20
|
-
DeviceCloud.constantize "DeviceCloud::PushNotification::#{class_name.capitalize}"
|
20
|
+
DeviceCloud.constantize "DeviceCloud::PushNotification::#{class_name.capitalize}Notification"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/device_cloud/version.rb
CHANGED
data/lib/device_cloud.rb
CHANGED
@@ -2,9 +2,10 @@ require 'device_cloud/configuration'
|
|
2
2
|
require 'device_cloud/utils'
|
3
3
|
require 'device_cloud/version'
|
4
4
|
require 'device_cloud/push_notification'
|
5
|
-
require 'device_cloud/push_notification/
|
6
|
-
require 'device_cloud/push_notification/
|
7
|
-
require 'device_cloud/push_notification/
|
5
|
+
require 'device_cloud/push_notification/base_notification'
|
6
|
+
require 'device_cloud/push_notification/alert_notification'
|
7
|
+
require 'device_cloud/push_notification/event_notification'
|
8
|
+
require 'device_cloud/push_notification/data_notification'
|
8
9
|
require 'device_cloud/push_notification/message'
|
9
10
|
require 'device_cloud/push_notification/message/file_data'
|
10
11
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe DeviceCloud::PushNotification::
|
3
|
+
describe DeviceCloud::PushNotification::AlertNotification do
|
4
4
|
describe "#handle!" do
|
5
5
|
let(:data) do
|
6
6
|
{
|
@@ -13,11 +13,11 @@ describe DeviceCloud::PushNotification::Alert do
|
|
13
13
|
end
|
14
14
|
let(:file_data) { OpenStruct.new(data: data, full_path: '/foo/bar/baz.json') }
|
15
15
|
|
16
|
-
subject { DeviceCloud::PushNotification::
|
16
|
+
subject { DeviceCloud::PushNotification::AlertNotification.new file_data }
|
17
17
|
|
18
|
-
it "should call the DeviceCloud.
|
18
|
+
it "should call the DeviceCloud.alert_notification_handler with self" do
|
19
19
|
handled_alert = nil
|
20
|
-
DeviceCloud.
|
20
|
+
DeviceCloud.alert_notification_handler = ->(alert) { handled_alert = alert }
|
21
21
|
|
22
22
|
subject.handle!
|
23
23
|
expect(handled_alert).to eq subject
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe DeviceCloud::PushNotification::
|
3
|
+
describe DeviceCloud::PushNotification::BaseNotification do
|
4
4
|
let(:data) do
|
5
5
|
{
|
6
6
|
'id' => '1234',
|
@@ -18,7 +18,7 @@ describe DeviceCloud::PushNotification::Base do
|
|
18
18
|
)
|
19
19
|
end
|
20
20
|
|
21
|
-
subject { DeviceCloud::PushNotification::
|
21
|
+
subject { DeviceCloud::PushNotification::BaseNotification.new file_data }
|
22
22
|
|
23
23
|
describe "attributes" do
|
24
24
|
its(:id) { should eq data['id'] }
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DeviceCloud::PushNotification::DataNotification do
|
4
|
+
describe "#handle!" do
|
5
|
+
let(:data) do
|
6
|
+
{
|
7
|
+
'id' => 1234,
|
8
|
+
'device_id' => 'm:1392301029',
|
9
|
+
'type' => 'some type',
|
10
|
+
'queued_dt' => '2013-06-24T14:52:55.421Z',
|
11
|
+
'value' => {'this' => 'is a value'}
|
12
|
+
}
|
13
|
+
end
|
14
|
+
let(:file_data) { OpenStruct.new(data: data, full_path: '/foo/bar/baz.json') }
|
15
|
+
|
16
|
+
subject { DeviceCloud::PushNotification::DataNotification.new file_data }
|
17
|
+
|
18
|
+
it "should call the DeviceCloud.data_notification_handler with self" do
|
19
|
+
handled_data = nil
|
20
|
+
DeviceCloud.data_notification_handler = ->(data) { handled_data = data }
|
21
|
+
|
22
|
+
subject.handle!
|
23
|
+
expect(handled_data).to eq subject
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe DeviceCloud::PushNotification::
|
3
|
+
describe DeviceCloud::PushNotification::EventNotification do
|
4
4
|
describe "#handle!" do
|
5
5
|
let(:data) do
|
6
6
|
{
|
@@ -13,11 +13,11 @@ describe DeviceCloud::PushNotification::Event do
|
|
13
13
|
end
|
14
14
|
let(:file_data) { OpenStruct.new(data: data, full_path: '/foo/bar/baz.json') }
|
15
15
|
|
16
|
-
subject { DeviceCloud::PushNotification::
|
16
|
+
subject { DeviceCloud::PushNotification::EventNotification.new file_data }
|
17
17
|
|
18
|
-
it "should call the DeviceCloud.
|
18
|
+
it "should call the DeviceCloud.event_notification_handler with self" do
|
19
19
|
handled_event = nil
|
20
|
-
DeviceCloud.
|
20
|
+
DeviceCloud.event_notification_handler = ->(event) { handled_event = event }
|
21
21
|
|
22
22
|
subject.handle!
|
23
23
|
expect(handled_event).to eq subject
|
@@ -4,7 +4,8 @@ describe DeviceCloud::PushNotification do
|
|
4
4
|
let(:raw_messages) do
|
5
5
|
[
|
6
6
|
{ 'topic_type' => 'an alert' },
|
7
|
-
{ 'topic_type' => 'an event' }
|
7
|
+
{ 'topic_type' => 'an event' },
|
8
|
+
{ 'topic_type' => 'a piece of data' }
|
8
9
|
]
|
9
10
|
end
|
10
11
|
let(:valid_parsed_messages) do
|
@@ -20,6 +21,12 @@ describe DeviceCloud::PushNotification do
|
|
20
21
|
valid_parsed_file_data?: true,
|
21
22
|
topic_type: 'event',
|
22
23
|
parsed_file_data: 'the event data'
|
24
|
+
),
|
25
|
+
OpenStruct.new(
|
26
|
+
valid?: true,
|
27
|
+
valid_parsed_file_data?: true,
|
28
|
+
topic_type: 'data',
|
29
|
+
parsed_file_data: 'the data data'
|
23
30
|
)
|
24
31
|
]
|
25
32
|
end
|
@@ -41,9 +48,11 @@ describe DeviceCloud::PushNotification do
|
|
41
48
|
context "all valid" do
|
42
49
|
|
43
50
|
it "should call handle! on each of the message's topic_type classes" do
|
44
|
-
DeviceCloud::PushNotification::
|
51
|
+
DeviceCloud::PushNotification::AlertNotification.should_receive(:handle!).with(valid_parsed_messages[0].parsed_file_data)
|
52
|
+
|
53
|
+
DeviceCloud::PushNotification::EventNotification.should_receive(:handle!).with(valid_parsed_messages[1].parsed_file_data)
|
45
54
|
|
46
|
-
DeviceCloud::PushNotification::
|
55
|
+
DeviceCloud::PushNotification::DataNotification.should_receive(:handle!).with(valid_parsed_messages[2].parsed_file_data)
|
47
56
|
|
48
57
|
subject.handle_each!
|
49
58
|
|
@@ -59,9 +68,10 @@ describe DeviceCloud::PushNotification do
|
|
59
68
|
parsed_file_data: 'the alert data'
|
60
69
|
)
|
61
70
|
|
62
|
-
DeviceCloud::PushNotification::
|
71
|
+
DeviceCloud::PushNotification::AlertNotification.should_not_receive(:handle!)
|
63
72
|
|
64
|
-
DeviceCloud::PushNotification::
|
73
|
+
DeviceCloud::PushNotification::EventNotification.should_receive(:handle!)
|
74
|
+
DeviceCloud::PushNotification::DataNotification.should_receive(:handle!)
|
65
75
|
|
66
76
|
subject.handle_each!
|
67
77
|
end
|
@@ -76,9 +86,10 @@ describe DeviceCloud::PushNotification do
|
|
76
86
|
parsed_file_data: 'the alert data'
|
77
87
|
)
|
78
88
|
|
79
|
-
DeviceCloud::PushNotification::
|
89
|
+
DeviceCloud::PushNotification::AlertNotification.should_not_receive(:handle!)
|
80
90
|
|
81
|
-
DeviceCloud::PushNotification::
|
91
|
+
DeviceCloud::PushNotification::EventNotification.should_receive(:handle!)
|
92
|
+
DeviceCloud::PushNotification::DataNotification.should_receive(:handle!)
|
82
93
|
|
83
94
|
subject.handle_each!
|
84
95
|
end
|
data/spec/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: device_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -77,16 +77,18 @@ files:
|
|
77
77
|
- lib/device_cloud.rb
|
78
78
|
- lib/device_cloud/configuration.rb
|
79
79
|
- lib/device_cloud/push_notification.rb
|
80
|
-
- lib/device_cloud/push_notification/
|
81
|
-
- lib/device_cloud/push_notification/
|
82
|
-
- lib/device_cloud/push_notification/
|
80
|
+
- lib/device_cloud/push_notification/alert_notification.rb
|
81
|
+
- lib/device_cloud/push_notification/base_notification.rb
|
82
|
+
- lib/device_cloud/push_notification/data_notification.rb
|
83
|
+
- lib/device_cloud/push_notification/event_notification.rb
|
83
84
|
- lib/device_cloud/push_notification/message.rb
|
84
85
|
- lib/device_cloud/push_notification/message/file_data.rb
|
85
86
|
- lib/device_cloud/utils.rb
|
86
87
|
- lib/device_cloud/version.rb
|
87
|
-
- spec/device_cloud/push_notification/
|
88
|
-
- spec/device_cloud/push_notification/
|
89
|
-
- spec/device_cloud/push_notification/
|
88
|
+
- spec/device_cloud/push_notification/alert_notification_spec.rb
|
89
|
+
- spec/device_cloud/push_notification/base_notification_spec.rb
|
90
|
+
- spec/device_cloud/push_notification/data_notification_spec.rb
|
91
|
+
- spec/device_cloud/push_notification/event_notification_spec.rb
|
90
92
|
- spec/device_cloud/push_notification/message/file_data_spec.rb
|
91
93
|
- spec/device_cloud/push_notification/message_spec.rb
|
92
94
|
- spec/device_cloud/push_notification_spec.rb
|
@@ -118,9 +120,10 @@ signing_key:
|
|
118
120
|
specification_version: 3
|
119
121
|
summary: A Ruby wrapper for the Etherios Device Cloud
|
120
122
|
test_files:
|
121
|
-
- spec/device_cloud/push_notification/
|
122
|
-
- spec/device_cloud/push_notification/
|
123
|
-
- spec/device_cloud/push_notification/
|
123
|
+
- spec/device_cloud/push_notification/alert_notification_spec.rb
|
124
|
+
- spec/device_cloud/push_notification/base_notification_spec.rb
|
125
|
+
- spec/device_cloud/push_notification/data_notification_spec.rb
|
126
|
+
- spec/device_cloud/push_notification/event_notification_spec.rb
|
124
127
|
- spec/device_cloud/push_notification/message/file_data_spec.rb
|
125
128
|
- spec/device_cloud/push_notification/message_spec.rb
|
126
129
|
- spec/device_cloud/push_notification_spec.rb
|