device_cloud 0.1.0 → 0.2.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.
- data/README.md +55 -1
- data/lib/device_cloud/configuration.rb +17 -0
- data/lib/device_cloud/push_notification/alert_notification.rb +4 -0
- data/lib/device_cloud/push_notification/base_notification.rb +9 -0
- data/lib/device_cloud/push_notification/data_notification.rb +4 -0
- data/lib/device_cloud/push_notification/event_notification.rb +4 -0
- data/lib/device_cloud/push_notification/message/file_data.rb +14 -17
- data/lib/device_cloud/push_notification/message.rb +5 -21
- data/lib/device_cloud/push_notification.rb +3 -3
- data/lib/device_cloud/version.rb +1 -1
- data/spec/device_cloud/push_notification/base_notification_spec.rb +17 -1
- data/spec/device_cloud/push_notification/message/file_data_spec.rb +55 -17
- data/spec/device_cloud/push_notification/message_spec.rb +22 -8
- data/spec/device_cloud/push_notification_spec.rb +28 -20
- data/spec/version_spec.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# DeviceCloud
|
2
2
|
|
3
|
-
TODO:
|
3
|
+
TODO:
|
4
|
+
- remove any assumptions about Device Cloud FileData contents .. probably should only parse them if asked
|
5
|
+
- add code for maintaining monitors
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -20,6 +22,58 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
TODO: Write usage instructions here
|
22
24
|
|
25
|
+
## Example Push Notification
|
26
|
+
|
27
|
+
```json
|
28
|
+
{
|
29
|
+
"Document": {
|
30
|
+
"Msg": {
|
31
|
+
"timestamp": "2013-10-21T19:34:56Z",
|
32
|
+
"topic": "4044/FileData/db/4044_MadGlory_Interactive/00000000-00000000-001395FF-FF0E6017/event/parking_lot_event_exit-0966595cdcdd11e2abf50013950e6017.json",
|
33
|
+
"FileData": {
|
34
|
+
"id": {
|
35
|
+
"fdPath": " /db/4044_MadGlory_Interactive/00000000-00000000-001395FF-FF0E6017/event/",
|
36
|
+
"fdName": "parking_lot_event_exit-0966595cdcdd11e2abf50013950e6017.json"
|
37
|
+
},
|
38
|
+
"fdLastModifiedDate": "2013-10-21T19:34:56Z",
|
39
|
+
"fdSize": 545,
|
40
|
+
"fdContentType": "application/json",
|
41
|
+
"fdData": "eyJ2YWx1ZSI6eyJwbGF0ZSI6Ijk0MUdWVCIsImNvbmZpZGVuY2UiOiI5OSIsImNvdW50cnkiOiJVUyIsInRvd2FyZHNfY2FtZXJhIjoiZmFsc2UiLCJ0aW1lc3RhbXAiOiIyMDEzLTEwLTIxVDE0OjM0OjQwWiIsIm92ZXJ2aWV3X2ltYWdlX2lkIjoibG90X292ZXJ2aWV3X2NhcF8xMF8yMV8yMDEzXzE0MzQ0MC5qcGciLCJzdGF0ZSI6Ik1OIiwicGF0Y2hfaW1hZ2VfaWQiOiJsb3RfcGF0Y2hfY2FwXzEwXzIxXzIwMTNfMTQzNDQwLmpwZyJ9LCJjbGFzcyI6ImV2ZW50IiwicXVldWVkX2R0IjoiMjAxMy0xMC0yMVQxOTozNDo1NloiLCJ0eXBlIjoicGFya2luZ19sb3RfZXZlbnRfZXhpdCIsImlkIjoiZGQ5ZDU3MzYzYTg3MTFlM2E5YmQwMDEzOTUwZTYwMTciLCJkZXZpY2VfaWQiOiJtOjAwMTM5NTBFNjAxNyJ9",
|
42
|
+
"fdArchive": false,
|
43
|
+
"cstId": 4044,
|
44
|
+
"fdType": "event",
|
45
|
+
"fdCreatedDate": "2013-06-24T14:52:55.421Z"
|
46
|
+
},
|
47
|
+
"operation": "INSERTION",
|
48
|
+
"replay": true,
|
49
|
+
"group": "*"
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
```
|
54
|
+
|
55
|
+
That notification's unencoded fdData:
|
56
|
+
|
57
|
+
```json
|
58
|
+
{
|
59
|
+
"value": {
|
60
|
+
"plate": "941GVT",
|
61
|
+
"confidence": "99",
|
62
|
+
"country": "US",
|
63
|
+
"towards_camera": "false",
|
64
|
+
"timestamp": "2013-10-21T14:34:40Z",
|
65
|
+
"overview_image_id": "lot_overview_cap_10_21_2013_143440.jpg",
|
66
|
+
"state": "MN",
|
67
|
+
"patch_image_id": "lot_patch_cap_10_21_2013_143440.jpg"
|
68
|
+
},
|
69
|
+
"class": "event",
|
70
|
+
"queued_dt": "2013-10-21T19:34:56Z",
|
71
|
+
"type": "parking_lot_event_exit",
|
72
|
+
"id": "dd9d57363a8711e3a9bd0013950e6017",
|
73
|
+
"device_id": "m:0013950E6017"
|
74
|
+
}
|
75
|
+
```
|
76
|
+
|
23
77
|
## Contributing
|
24
78
|
|
25
79
|
1. Fork it
|
@@ -20,16 +20,33 @@ module DeviceCloud
|
|
20
20
|
# Proc will be called with the event notification object
|
21
21
|
attr_accessor :event_notification_handler
|
22
22
|
|
23
|
+
# Proc that will be called for handling
|
24
|
+
# DeviceCloud::PushNotification::EventNotification objects that
|
25
|
+
# do not contain file data (data too large - over 120KB)
|
26
|
+
# Proc will be called with the event notification object
|
27
|
+
attr_accessor :empty_event_notification_handler
|
28
|
+
|
23
29
|
# Proc that will be called for handling
|
24
30
|
# DeviceCloud::PushNotification::AlertNotification objects
|
25
31
|
# Proc will be called with the alert notification object
|
26
32
|
attr_accessor :alert_notification_handler
|
27
33
|
|
34
|
+
# Proc that will be called for handling
|
35
|
+
# DeviceCloud::PushNotification::AlertNotification objects that
|
36
|
+
# do not contain file data (data too large - over 120KB)
|
37
|
+
# Proc will be called with the alert notification object
|
38
|
+
attr_accessor :empty_alert_notification_handler
|
39
|
+
|
28
40
|
# Proc that will be called for handling
|
29
41
|
# DeviceCloud::PushNotification::DataNotification objects
|
30
42
|
# Proc will be called with the data notification object
|
31
43
|
attr_accessor :data_notification_handler
|
32
44
|
|
45
|
+
# Proc that will be called for handling
|
46
|
+
# DeviceCloud::PushNotification::DataNotification objects that
|
47
|
+
# do not contain file data (data too large - over 120KB)
|
48
|
+
# Proc will be called with the data notification object
|
49
|
+
attr_accessor :empty_data_notification_handler
|
33
50
|
|
34
51
|
# Yield self to be able to configure ActivityFeed with
|
35
52
|
# block-style configuration.
|
@@ -7,6 +7,11 @@ module DeviceCloud
|
|
7
7
|
event.handle!
|
8
8
|
end
|
9
9
|
|
10
|
+
def self.handle_no_content!(file_data)
|
11
|
+
event = new(file_data)
|
12
|
+
event.hanlde_no_content!
|
13
|
+
end
|
14
|
+
|
10
15
|
def initialize(file_data)
|
11
16
|
@file_data = file_data
|
12
17
|
@id = data["id"]
|
@@ -21,6 +26,10 @@ module DeviceCloud
|
|
21
26
|
raise NotImplementedError
|
22
27
|
end
|
23
28
|
|
29
|
+
def handle_no_content!
|
30
|
+
DeviceCloud.logger.info "DeviceCloud::PushNotification::BaseNotification - No FileData content - NotImplemented #{@full_path}"
|
31
|
+
end
|
32
|
+
|
24
33
|
def file_name
|
25
34
|
@file_data.file_name
|
26
35
|
end
|
@@ -4,14 +4,14 @@ require 'base64'
|
|
4
4
|
module DeviceCloud
|
5
5
|
class PushNotification::Message::FileData
|
6
6
|
attr_accessor :id, :fdLastModifiedDate, :fdSize, :fdContentType, :fdData, :fdArchive, :cstId, :fdType, :fdCreatedDate
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :no_content
|
8
8
|
|
9
9
|
def initialize(attributes = {})
|
10
|
-
@
|
10
|
+
@no_content = false
|
11
11
|
attributes.each do |name, value|
|
12
12
|
send("#{name}=", value)
|
13
13
|
end
|
14
|
-
|
14
|
+
validate_content!
|
15
15
|
end
|
16
16
|
|
17
17
|
def full_path
|
@@ -23,8 +23,7 @@ module DeviceCloud
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def data
|
26
|
-
|
27
|
-
@data ||= if json_data?
|
26
|
+
@data ||= if json_data? && content?
|
28
27
|
JSON.parse unencoded_data
|
29
28
|
else
|
30
29
|
unencoded_data
|
@@ -32,18 +31,21 @@ module DeviceCloud
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def file_name
|
35
|
-
return '' unless id
|
34
|
+
return '' unless id && id['fdName']
|
36
35
|
id['fdName']
|
37
36
|
end
|
38
37
|
|
39
38
|
def file_path
|
40
|
-
return '' unless id
|
39
|
+
return '' unless id && id['fdPath']
|
41
40
|
id['fdPath']
|
42
41
|
end
|
43
42
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
43
|
+
def no_content?
|
44
|
+
@no_content
|
45
|
+
end
|
46
|
+
|
47
|
+
def content?
|
48
|
+
!no_content?
|
47
49
|
end
|
48
50
|
private
|
49
51
|
def json_data?
|
@@ -51,16 +53,11 @@ module DeviceCloud
|
|
51
53
|
end
|
52
54
|
|
53
55
|
def unencoded_data
|
54
|
-
@unencoded_data ||= Base64.decode64(fdData)
|
56
|
+
@unencoded_data ||= no_content? ? '' : Base64.decode64(fdData)
|
55
57
|
end
|
56
58
|
|
57
59
|
def validate_content!
|
58
|
-
|
59
|
-
@errors << 'no content'
|
60
|
-
false
|
61
|
-
else
|
62
|
-
true
|
63
|
-
end
|
60
|
+
@no_content = !fdData || fdData.size == 0 || fdSize.to_i < 1
|
64
61
|
end
|
65
62
|
end
|
66
63
|
end
|
@@ -2,8 +2,6 @@ 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 data}
|
6
|
-
|
7
5
|
def self.parse_raw_messages(raw_message_data)
|
8
6
|
if raw_message_data.is_a? Array
|
9
7
|
messages = raw_message_data.map {|message| new(message) }
|
@@ -21,7 +19,7 @@ module DeviceCloud
|
|
21
19
|
send("#{name}=", value)
|
22
20
|
end
|
23
21
|
end
|
24
|
-
DeviceCloud.logger.
|
22
|
+
DeviceCloud.logger.info "DeviceCloud::PushNotification::Message Invalid (no FileData) - #{topic}" unless valid?
|
25
23
|
end
|
26
24
|
|
27
25
|
def parsed_file_data
|
@@ -29,26 +27,12 @@ module DeviceCloud
|
|
29
27
|
@parsed_file_data ||= FileData.new file_data
|
30
28
|
end
|
31
29
|
|
32
|
-
def
|
33
|
-
|
30
|
+
def no_content?
|
31
|
+
parsed_file_data.no_content?
|
34
32
|
end
|
35
33
|
|
36
|
-
def
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
def topic_type
|
41
|
-
topic_matches.first
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
def topic_allowed?
|
46
|
-
return false if !topic
|
47
|
-
topic_matches.any?
|
48
|
-
end
|
49
|
-
|
50
|
-
def topic_matches
|
51
|
-
topic.split('/') & ALLOWED_TOPICS
|
34
|
+
def valid?
|
35
|
+
!!file_data
|
52
36
|
end
|
53
37
|
end
|
54
38
|
end
|
@@ -8,11 +8,11 @@ module DeviceCloud
|
|
8
8
|
|
9
9
|
def handle_each!
|
10
10
|
messages.each do |message|
|
11
|
-
next unless message.valid?
|
11
|
+
next unless message.valid?
|
12
12
|
|
13
13
|
klass = class_type(message.topic_type)
|
14
|
-
|
15
|
-
klass.handle!(message.parsed_file_data)
|
14
|
+
|
15
|
+
message.no_content? ? klass.handle_no_content!(message.parsed_file_data) : klass.handle!(message.parsed_file_data)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
private
|
data/lib/device_cloud/version.rb
CHANGED
@@ -5,7 +5,7 @@ describe DeviceCloud::PushNotification::BaseNotification do
|
|
5
5
|
let(:raw_file_data) do
|
6
6
|
{
|
7
7
|
"id" => {
|
8
|
-
"fdPath" => "
|
8
|
+
"fdPath" => "/db/4044_MadGlory_Interactive/00000000-00000000-001395FF-FF0E6012/alert/",
|
9
9
|
"fdName" => "foo-0966595cdcdd11e2abf50013950e6012.json"
|
10
10
|
},
|
11
11
|
"fdLastModifiedDate" => "2013-06-24T14:52:55.421Z",
|
@@ -42,6 +42,22 @@ describe DeviceCloud::PushNotification::BaseNotification do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
describe "#handle_no_content!" do
|
46
|
+
let(:logger) { double('logger') }
|
47
|
+
before(:each) do
|
48
|
+
DeviceCloud.logger = logger
|
49
|
+
end
|
50
|
+
|
51
|
+
after(:each) do
|
52
|
+
DeviceCloud.logger = Logger.new(STDOUT)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should raise NotImplementedError" do
|
56
|
+
logger.should_receive(:info).with("DeviceCloud::PushNotification::BaseNotification - No FileData content - NotImplemented #{raw_file_data['id']['fdPath']}#{raw_file_data['id']['fdName']}")
|
57
|
+
subject.handle_no_content!
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
45
61
|
describe "#mac_address" do
|
46
62
|
context "when device_id present" do
|
47
63
|
its(:mac_address) { should eq('00:13:95:0E:60:12') }
|
@@ -31,31 +31,59 @@ describe DeviceCloud::PushNotification::Message::FileData do
|
|
31
31
|
its(:fdData) { should eq(raw_file_data["fdData"]) }
|
32
32
|
end
|
33
33
|
|
34
|
-
describe '#
|
35
|
-
|
36
|
-
|
34
|
+
describe '#no_content?' do
|
35
|
+
let(:raw_file_data) do
|
36
|
+
{
|
37
|
+
"id" => {
|
38
|
+
"fdPath" => " /db/4044_MadGlory_Interactive/00000000-00000000-001395FF-FF0E6012/alert/",
|
39
|
+
"fdName" => "foo-0966595cdcdd11e2abf50013950e6012.json"
|
40
|
+
},
|
41
|
+
"fdLastModifiedDate" => "2013-06-24T14:52:55.421Z",
|
42
|
+
"fdSize" => 156,
|
43
|
+
"fdContentType" => "application/octet-stream",
|
44
|
+
"fdData" => fd_data_content,
|
45
|
+
"fdArchive" => false,
|
46
|
+
"cstId" => 4044,
|
47
|
+
"fdType" => "file",
|
48
|
+
"fdCreatedDate" => "2013-06-24T14:52:55.421Z"
|
49
|
+
}
|
50
|
+
end
|
51
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data }
|
52
|
+
|
53
|
+
context 'when fdData blank' do
|
54
|
+
let(:fd_data_content) { '' }
|
55
|
+
its(:no_content?) { should be_true }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when fdData null' do
|
59
|
+
let(:fd_data_content) { nil }
|
60
|
+
its(:no_content?) { should be_true }
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when fdData missing' do
|
64
|
+
let(:missing_fd_data) do
|
37
65
|
{
|
38
66
|
"id" => {
|
39
67
|
"fdPath" => " /db/4044_MadGlory_Interactive/00000000-00000000-001395FF-FF0E6012/alert/",
|
40
68
|
"fdName" => "foo-0966595cdcdd11e2abf50013950e6012.json"
|
41
69
|
},
|
42
70
|
"fdLastModifiedDate" => "2013-06-24T14:52:55.421Z",
|
43
|
-
"fdSize" =>
|
71
|
+
"fdSize" => 0,
|
44
72
|
"fdContentType" => "application/octet-stream",
|
45
|
-
"fdData" => "",
|
46
73
|
"fdArchive" => false,
|
47
74
|
"cstId" => 4044,
|
48
75
|
"fdType" => "file",
|
49
76
|
"fdCreatedDate" => "2013-06-24T14:52:55.421Z"
|
50
77
|
}
|
51
78
|
end
|
79
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new missing_fd_data }
|
80
|
+
its(:no_content?) { should be_true }
|
81
|
+
end
|
52
82
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
expect(subject.errors.include?('no content')).to be_true
|
58
|
-
end
|
83
|
+
context 'when fdData present' do
|
84
|
+
let(:fd_data_content) { 'jibberish' }
|
85
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data }
|
86
|
+
its(:no_content) { should be_false }
|
59
87
|
end
|
60
88
|
end
|
61
89
|
|
@@ -66,10 +94,15 @@ describe DeviceCloud::PushNotification::Message::FileData do
|
|
66
94
|
its(:file_path) { should eq raw_file_data['id']['fdPath'] }
|
67
95
|
end
|
68
96
|
|
69
|
-
context "when id
|
97
|
+
context "when id not present" do
|
70
98
|
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data.merge( 'id' => nil ) }
|
71
99
|
its(:file_path) { should eq '' }
|
72
100
|
end
|
101
|
+
|
102
|
+
context "when id blank" do
|
103
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data.merge( 'id' => '' ) }
|
104
|
+
its(:file_path) { should eq '' }
|
105
|
+
end
|
73
106
|
end
|
74
107
|
|
75
108
|
describe "#file_name" do
|
@@ -79,14 +112,19 @@ describe DeviceCloud::PushNotification::Message::FileData do
|
|
79
112
|
its(:file_name) { should eq raw_file_data['id']['fdName'] }
|
80
113
|
end
|
81
114
|
|
82
|
-
context "when id
|
115
|
+
context "when id not present" do
|
83
116
|
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data.merge( 'id' => nil ) }
|
84
117
|
its(:file_name) { should eq '' }
|
85
118
|
end
|
119
|
+
|
120
|
+
context "when id blank" do
|
121
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data.merge( 'id' => '' ) }
|
122
|
+
its(:file_name) { should eq '' }
|
123
|
+
end
|
86
124
|
end
|
87
125
|
|
88
126
|
describe "#data" do
|
89
|
-
context 'when
|
127
|
+
context 'when content present' do
|
90
128
|
context "json content-type" do
|
91
129
|
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data }
|
92
130
|
its(:data) { should eq(JSON.parse(Base64.decode64(raw_file_data['fdData']))) }
|
@@ -103,12 +141,12 @@ describe DeviceCloud::PushNotification::Message::FileData do
|
|
103
141
|
end
|
104
142
|
end
|
105
143
|
|
106
|
-
context 'when
|
144
|
+
context 'when content not present' do
|
107
145
|
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data.merge('fdData' => '') }
|
108
|
-
its(:data) { should
|
146
|
+
its(:data) { should eq '' }
|
109
147
|
|
110
148
|
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data.merge('fdData' => nil) }
|
111
|
-
its(:data) { should
|
149
|
+
its(:data) { should eq '' }
|
112
150
|
end
|
113
151
|
end
|
114
152
|
|
@@ -104,31 +104,45 @@ describe DeviceCloud::PushNotification::Message do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
describe "#valid?" do
|
107
|
-
context "with file_data
|
108
|
-
subject { DeviceCloud::PushNotification::Message.new 'FileData' => 'present'
|
107
|
+
context "with file_data" do
|
108
|
+
subject { DeviceCloud::PushNotification::Message.new 'FileData' => 'present' }
|
109
109
|
its(:valid?) { should be_true }
|
110
110
|
end
|
111
111
|
|
112
112
|
context "without file_data" do
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
let(:logger) { double('logger') }
|
114
|
+
before(:each) do
|
115
|
+
DeviceCloud.logger = logger
|
116
|
+
logger.should_receive(:info)
|
117
|
+
end
|
116
118
|
|
117
|
-
|
118
|
-
|
119
|
+
after(:each) do
|
120
|
+
DeviceCloud.logger = Logger.new(STDOUT)
|
121
|
+
end
|
122
|
+
|
123
|
+
subject { DeviceCloud::PushNotification::Message.new }
|
119
124
|
its(:valid?) { should_not be_true }
|
120
125
|
end
|
121
126
|
end
|
122
127
|
|
123
128
|
describe "#parsed_file_data" do
|
124
129
|
context "when invalid" do
|
130
|
+
let(:logger) { double('logger') }
|
131
|
+
before(:each) do
|
132
|
+
DeviceCloud.logger = logger
|
133
|
+
logger.should_receive(:info)
|
134
|
+
end
|
135
|
+
|
136
|
+
after(:each) do
|
137
|
+
DeviceCloud.logger = Logger.new(STDOUT)
|
138
|
+
end
|
125
139
|
it "should be false" do
|
126
140
|
expect(subject.parsed_file_data).to be_false
|
127
141
|
end
|
128
142
|
end
|
129
143
|
|
130
144
|
context "when valid" do
|
131
|
-
subject { DeviceCloud::PushNotification::Message.new 'FileData' => single_raw_message["FileData"]
|
145
|
+
subject { DeviceCloud::PushNotification::Message.new 'FileData' => single_raw_message["FileData"] }
|
132
146
|
|
133
147
|
it "should return a DeviceCloud::PushNotification::Message::FileData object" do
|
134
148
|
expect(subject.parsed_file_data.class).to eq(DeviceCloud::PushNotification::Message::FileData)
|
@@ -12,19 +12,34 @@ describe DeviceCloud::PushNotification do
|
|
12
12
|
[
|
13
13
|
OpenStruct.new(
|
14
14
|
valid?: true,
|
15
|
-
valid_parsed_file_data?: true,
|
16
15
|
topic_type: 'alert',
|
17
16
|
parsed_file_data: 'the alert data'
|
18
17
|
),
|
19
18
|
OpenStruct.new(
|
20
19
|
valid?: true,
|
21
|
-
valid_parsed_file_data?: true,
|
22
20
|
topic_type: 'event',
|
23
21
|
parsed_file_data: 'the event data'
|
24
22
|
),
|
25
23
|
OpenStruct.new(
|
26
24
|
valid?: true,
|
27
|
-
|
25
|
+
topic_type: 'data',
|
26
|
+
parsed_file_data: 'the data data'
|
27
|
+
),
|
28
|
+
OpenStruct.new(
|
29
|
+
valid?: true,
|
30
|
+
no_content?: true,
|
31
|
+
topic_type: 'alert',
|
32
|
+
parsed_file_data: 'the alert data'
|
33
|
+
),
|
34
|
+
OpenStruct.new(
|
35
|
+
valid?: true,
|
36
|
+
no_content?: true,
|
37
|
+
topic_type: 'event',
|
38
|
+
parsed_file_data: 'the event data'
|
39
|
+
),
|
40
|
+
OpenStruct.new(
|
41
|
+
valid?: true,
|
42
|
+
no_content?: true,
|
28
43
|
topic_type: 'data',
|
29
44
|
parsed_file_data: 'the data data'
|
30
45
|
)
|
@@ -54,6 +69,12 @@ describe DeviceCloud::PushNotification do
|
|
54
69
|
|
55
70
|
DeviceCloud::PushNotification::DataNotification.should_receive(:handle!).with(valid_parsed_messages[2].parsed_file_data)
|
56
71
|
|
72
|
+
DeviceCloud::PushNotification::AlertNotification.should_receive(:handle_no_content!).with(valid_parsed_messages[3].parsed_file_data)
|
73
|
+
|
74
|
+
DeviceCloud::PushNotification::EventNotification.should_receive(:handle_no_content!).with(valid_parsed_messages[4].parsed_file_data)
|
75
|
+
|
76
|
+
DeviceCloud::PushNotification::DataNotification.should_receive(:handle_no_content!).with(valid_parsed_messages[5].parsed_file_data)
|
77
|
+
|
57
78
|
subject.handle_each!
|
58
79
|
|
59
80
|
end
|
@@ -63,7 +84,6 @@ describe DeviceCloud::PushNotification do
|
|
63
84
|
it "should not be handled" do
|
64
85
|
valid_parsed_messages[0] = OpenStruct.new(
|
65
86
|
valid?: false, # test condition
|
66
|
-
valid_parsed_file_data?: true,
|
67
87
|
topic_type: 'alert',
|
68
88
|
parsed_file_data: 'the alert data'
|
69
89
|
)
|
@@ -73,23 +93,11 @@ describe DeviceCloud::PushNotification do
|
|
73
93
|
DeviceCloud::PushNotification::EventNotification.should_receive(:handle!)
|
74
94
|
DeviceCloud::PushNotification::DataNotification.should_receive(:handle!)
|
75
95
|
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
96
|
+
DeviceCloud::PushNotification::AlertNotification.should_receive(:handle_no_content!)
|
79
97
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
valid?: true,
|
84
|
-
valid_parsed_file_data?: false, # test condition
|
85
|
-
topic_type: 'alert',
|
86
|
-
parsed_file_data: 'the alert data'
|
87
|
-
)
|
88
|
-
|
89
|
-
DeviceCloud::PushNotification::AlertNotification.should_not_receive(:handle!)
|
90
|
-
|
91
|
-
DeviceCloud::PushNotification::EventNotification.should_receive(:handle!)
|
92
|
-
DeviceCloud::PushNotification::DataNotification.should_receive(:handle!)
|
98
|
+
DeviceCloud::PushNotification::EventNotification.should_receive(:handle_no_content!)
|
99
|
+
|
100
|
+
DeviceCloud::PushNotification::DataNotification.should_receive(:handle_no_content!)
|
93
101
|
|
94
102
|
subject.handle_each!
|
95
103
|
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.
|
4
|
+
version: 0.2.0
|
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-
|
12
|
+
date: 2013-10-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|