device_cloud 0.0.6 → 0.0.7
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.
@@ -18,9 +18,17 @@ module DeviceCloud
|
|
18
18
|
file_path + file_name
|
19
19
|
end
|
20
20
|
|
21
|
+
def content_type
|
22
|
+
fdContentType
|
23
|
+
end
|
24
|
+
|
21
25
|
def data
|
22
26
|
return false unless valid?
|
23
|
-
@data ||=
|
27
|
+
@data ||= if json_data?
|
28
|
+
JSON.parse unencoded_data
|
29
|
+
else
|
30
|
+
unencoded_data
|
31
|
+
end
|
24
32
|
end
|
25
33
|
|
26
34
|
def file_name
|
@@ -35,25 +43,19 @@ module DeviceCloud
|
|
35
43
|
|
36
44
|
def valid?
|
37
45
|
return false if @errors.any?
|
38
|
-
|
46
|
+
validate_content!
|
39
47
|
end
|
40
48
|
private
|
49
|
+
def json_data?
|
50
|
+
fdContentType =~ /json/ || file_name =~ /\.json\z/
|
51
|
+
end
|
41
52
|
|
42
53
|
def unencoded_data
|
43
54
|
@unencode_data ||= Base64.decode64(fdData)
|
44
55
|
end
|
45
56
|
|
46
|
-
def validate_content_type!
|
47
|
-
if file_name =~ /\.json/
|
48
|
-
true
|
49
|
-
else
|
50
|
-
@errors << 'wrong file type'
|
51
|
-
false
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
57
|
def validate_content!
|
56
|
-
if fdData.size == 0 || fdSize.to_i < 1
|
58
|
+
if !fdData || fdData.size == 0 || fdSize.to_i < 1
|
57
59
|
@errors << 'no content'
|
58
60
|
false
|
59
61
|
else
|
data/lib/device_cloud/version.rb
CHANGED
@@ -18,9 +18,9 @@ describe DeviceCloud::PushNotification::Message::FileData do
|
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data }
|
21
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data }
|
23
22
|
|
23
|
+
describe "attributes" do
|
24
24
|
its(:id) { should eq(raw_file_data['id']) }
|
25
25
|
its(:fdLastModifiedDate) { should eq(raw_file_data['fdLastModifiedDate']) }
|
26
26
|
its(:fdSize) { should eq(raw_file_data['fdSize']) }
|
@@ -32,32 +32,6 @@ describe DeviceCloud::PushNotification::Message::FileData do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
describe '#valid?' do
|
35
|
-
subject { DeviceCloud::PushNotification::Message::FileData.new }
|
36
|
-
context 'wrong file type' do
|
37
|
-
let(:raw_file_data) do
|
38
|
-
{
|
39
|
-
"id" => {
|
40
|
-
"fdPath" => "/db/4044_MadGlory_Interactive/00000000-00000000-001395FF-FF0E6014/",
|
41
|
-
"fdName" => "event"
|
42
|
-
},
|
43
|
-
"fdLastModifiedDate" => "2013-06-26T16:18:39.675Z",
|
44
|
-
"fdSize" => 0,
|
45
|
-
"fdContentType" => "application/octet-stream",
|
46
|
-
"fdArchive" => false,
|
47
|
-
"cstId" => 4044,
|
48
|
-
"fdType" => "directory",
|
49
|
-
"fdCreatedDate" => "2013-06-26T16:18:39.675Z"
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data}
|
54
|
-
its(:valid?) { should be_false }
|
55
|
-
it "should set a 'wrong file type' error" do
|
56
|
-
subject.valid?
|
57
|
-
expect(subject.errors.include?('wrong file type')).to be_true
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
35
|
context 'without content' do
|
62
36
|
let(:raw_file_data) do
|
63
37
|
{
|
@@ -78,7 +52,7 @@ describe DeviceCloud::PushNotification::Message::FileData do
|
|
78
52
|
|
79
53
|
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data}
|
80
54
|
its(:valid?) { should be_false }
|
81
|
-
it "should set a '
|
55
|
+
it "should set a 'no content' error" do
|
82
56
|
subject.valid?
|
83
57
|
expect(subject.errors.include?('no content')).to be_true
|
84
58
|
end
|
@@ -93,6 +67,7 @@ describe DeviceCloud::PushNotification::Message::FileData do
|
|
93
67
|
end
|
94
68
|
|
95
69
|
context "when id blank" do
|
70
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data.merge( 'id' => nil ) }
|
96
71
|
its(:file_path) { should eq '' }
|
97
72
|
end
|
98
73
|
end
|
@@ -105,18 +80,34 @@ describe DeviceCloud::PushNotification::Message::FileData do
|
|
105
80
|
end
|
106
81
|
|
107
82
|
context "when id blank" do
|
83
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data.merge( 'id' => nil ) }
|
108
84
|
its(:file_name) { should eq '' }
|
109
85
|
end
|
110
86
|
end
|
111
87
|
|
112
88
|
describe "#data" do
|
113
89
|
context 'when valid' do
|
114
|
-
|
90
|
+
context "json content-type" do
|
91
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data }
|
92
|
+
its(:data) { should eq(JSON.parse(Base64.decode64(raw_file_data['fdData']))) }
|
93
|
+
end
|
94
|
+
|
95
|
+
context "non-json content-type" do
|
96
|
+
before(:each) do
|
97
|
+
raw_file_data['fdContentType'] = 'foobar'
|
98
|
+
raw_file_data['id']['fdName'] = 'not_json.jpg'
|
99
|
+
end
|
100
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data }
|
115
101
|
|
116
|
-
|
102
|
+
its(:data) { should eq(Base64.decode64(raw_file_data['fdData'])) }
|
103
|
+
end
|
117
104
|
end
|
118
105
|
|
119
106
|
context 'when invalid' do
|
107
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data.merge('fdData' => '') }
|
108
|
+
its(:data) { should be_false }
|
109
|
+
|
110
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data.merge('fdData' => nil) }
|
120
111
|
its(:data) { should be_false }
|
121
112
|
end
|
122
113
|
end
|
@@ -126,4 +117,10 @@ describe DeviceCloud::PushNotification::Message::FileData do
|
|
126
117
|
|
127
118
|
its(:full_path) { should eq(raw_file_data['id']['fdPath'] + raw_file_data['id']['fdName']) }
|
128
119
|
end
|
120
|
+
|
121
|
+
describe "#content_type" do
|
122
|
+
subject { DeviceCloud::PushNotification::Message::FileData.new raw_file_data }
|
123
|
+
|
124
|
+
its(:content_type) { should eq raw_file_data['fdContentType'] }
|
125
|
+
end
|
129
126
|
end
|
data/spec/version_spec.rb
CHANGED