cosm-rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.rbenv-version +1 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +91 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +195 -0
- data/Rakefile +35 -0
- data/ci/build_hudson.sh +24 -0
- data/cosm-rb.gemspec +40 -0
- data/init.rb +2 -0
- data/lib/cosm-rb/array_extensions.rb +6 -0
- data/lib/cosm-rb/base/instance_methods.rb +28 -0
- data/lib/cosm-rb/base.rb +52 -0
- data/lib/cosm-rb/client.rb +7 -0
- data/lib/cosm-rb/datapoint.rb +71 -0
- data/lib/cosm-rb/datastream.rb +136 -0
- data/lib/cosm-rb/feed.rb +108 -0
- data/lib/cosm-rb/hash_extensions.rb +16 -0
- data/lib/cosm-rb/helpers.rb +42 -0
- data/lib/cosm-rb/key.rb +98 -0
- data/lib/cosm-rb/nil_content.rb +15 -0
- data/lib/cosm-rb/object_extensions.rb +6 -0
- data/lib/cosm-rb/parsers/csv/datastream_defaults.rb +12 -0
- data/lib/cosm-rb/parsers/csv/feed_defaults.rb +38 -0
- data/lib/cosm-rb/parsers/defaults.rb +13 -0
- data/lib/cosm-rb/parsers/json/datapoint_defaults.rb +12 -0
- data/lib/cosm-rb/parsers/json/datastream_defaults.rb +53 -0
- data/lib/cosm-rb/parsers/json/feed_defaults.rb +103 -0
- data/lib/cosm-rb/parsers/json/key_defaults.rb +15 -0
- data/lib/cosm-rb/parsers/json/search_result_defaults.rb +18 -0
- data/lib/cosm-rb/parsers/json/trigger_defaults.rb +12 -0
- data/lib/cosm-rb/parsers/xml/datapoint_defaults.rb +20 -0
- data/lib/cosm-rb/parsers/xml/datastream_defaults.rb +77 -0
- data/lib/cosm-rb/parsers/xml/feed_defaults.rb +127 -0
- data/lib/cosm-rb/parsers/xml/key_defaults.rb +40 -0
- data/lib/cosm-rb/parsers/xml/trigger_defaults.rb +22 -0
- data/lib/cosm-rb/permission.rb +67 -0
- data/lib/cosm-rb/resource.rb +43 -0
- data/lib/cosm-rb/search_result.rb +63 -0
- data/lib/cosm-rb/string_extensions.rb +6 -0
- data/lib/cosm-rb/template.rb +32 -0
- data/lib/cosm-rb/templates/csv/datapoint_defaults.rb +22 -0
- data/lib/cosm-rb/templates/csv/datastream_defaults.rb +43 -0
- data/lib/cosm-rb/templates/csv/feed_defaults.rb +47 -0
- data/lib/cosm-rb/templates/defaults.rb +14 -0
- data/lib/cosm-rb/templates/json/datapoint_defaults.rb +15 -0
- data/lib/cosm-rb/templates/json/datastream_defaults.rb +66 -0
- data/lib/cosm-rb/templates/json/feed_defaults.rb +134 -0
- data/lib/cosm-rb/templates/json/key_defaults.rb +41 -0
- data/lib/cosm-rb/templates/json/search_result_defaults.rb +47 -0
- data/lib/cosm-rb/templates/json/trigger_defaults.rb +21 -0
- data/lib/cosm-rb/templates/xml/datapoint_defaults.rb +25 -0
- data/lib/cosm-rb/templates/xml/datastream_defaults.rb +66 -0
- data/lib/cosm-rb/templates/xml/feed_defaults.rb +110 -0
- data/lib/cosm-rb/templates/xml/search_result_defaults.rb +116 -0
- data/lib/cosm-rb/templates/xml_headers.rb +17 -0
- data/lib/cosm-rb/trigger.rb +65 -0
- data/lib/cosm-rb/validations.rb +9 -0
- data/lib/cosm-rb/version.rb +3 -0
- data/lib/cosm-rb.rb +29 -0
- data/spec/cosm-rb/array_extensions_spec.rb +9 -0
- data/spec/cosm-rb/base/instance_methods_spec.rb +109 -0
- data/spec/cosm-rb/base_spec.rb +56 -0
- data/spec/cosm-rb/client_spec.rb +7 -0
- data/spec/cosm-rb/datapoint_spec.rb +169 -0
- data/spec/cosm-rb/datastream_spec.rb +301 -0
- data/spec/cosm-rb/feed_spec.rb +298 -0
- data/spec/cosm-rb/hash_extensions_spec.rb +20 -0
- data/spec/cosm-rb/helpers_spec.rb +56 -0
- data/spec/cosm-rb/key_spec.rb +178 -0
- data/spec/cosm-rb/parsers/csv/datastream_defaults_spec.rb +12 -0
- data/spec/cosm-rb/parsers/csv/feed_defaults_spec.rb +35 -0
- data/spec/cosm-rb/parsers/json/datapoint_defaults_spec.rb +15 -0
- data/spec/cosm-rb/parsers/json/datastream_defaults_spec.rb +82 -0
- data/spec/cosm-rb/parsers/json/feed_defaults_spec.rb +18 -0
- data/spec/cosm-rb/parsers/json/key_defaults_spec.rb +8 -0
- data/spec/cosm-rb/parsers/json/search_result_defaults_spec.rb +12 -0
- data/spec/cosm-rb/parsers/json/trigger_defaults_spec.rb +16 -0
- data/spec/cosm-rb/parsers/xml/datapoint_defaults_spec.rb +19 -0
- data/spec/cosm-rb/parsers/xml/datastream_defaults_spec.rb +63 -0
- data/spec/cosm-rb/parsers/xml/feed_defaults_spec.rb +65 -0
- data/spec/cosm-rb/parsers/xml/key_defaults_spec.rb +16 -0
- data/spec/cosm-rb/parsers/xml/trigger_defaults_spec.rb +16 -0
- data/spec/cosm-rb/search_result_spec.rb +258 -0
- data/spec/cosm-rb/string_extensions_spec.rb +12 -0
- data/spec/cosm-rb/template_spec.rb +74 -0
- data/spec/cosm-rb/templates/csv/datapoint_defaults_spec.rb +41 -0
- data/spec/cosm-rb/templates/csv/datastream_defaults_spec.rb +131 -0
- data/spec/cosm-rb/templates/csv/feed_defaults_spec.rb +78 -0
- data/spec/cosm-rb/templates/json/datapoint_defaults_spec.rb +14 -0
- data/spec/cosm-rb/templates/json/datastream_defaults_spec.rb +170 -0
- data/spec/cosm-rb/templates/json/feed_defaults_spec.rb +397 -0
- data/spec/cosm-rb/templates/json/key_defaults_spec.rb +29 -0
- data/spec/cosm-rb/templates/json/search_result_defaults_spec.rb +37 -0
- data/spec/cosm-rb/templates/json/trigger_defaults_spec.rb +19 -0
- data/spec/cosm-rb/templates/xml/datapoint_defaults_spec.rb +14 -0
- data/spec/cosm-rb/templates/xml/datastream_defaults_spec.rb +113 -0
- data/spec/cosm-rb/templates/xml/feed_defaults_spec.rb +131 -0
- data/spec/cosm-rb/templates/xml/search_result_defaults_spec.rb +44 -0
- data/spec/cosm-rb/trigger_spec.rb +117 -0
- data/spec/fixtures/models.rb +81 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/contain_datapoint_eeml_matcher.rb +16 -0
- data/spec/support/contain_datastream_eeml_matcher.rb +60 -0
- data/spec/support/contain_feed_eeml_matcher.rb +96 -0
- data/spec/support/datapoint_helper.rb +53 -0
- data/spec/support/datastream_helper.rb +300 -0
- data/spec/support/describe_eeml_matcher.rb +23 -0
- data/spec/support/feed_helper.rb +771 -0
- data/spec/support/fully_represent_datapoint_matcher.rb +30 -0
- data/spec/support/fully_represent_datastream_matcher.rb +92 -0
- data/spec/support/fully_represent_feed_matcher.rb +226 -0
- data/spec/support/fully_represent_key_matcher.rb +74 -0
- data/spec/support/fully_represent_search_result_matcher.rb +67 -0
- data/spec/support/fully_represent_trigger_matcher.rb +29 -0
- data/spec/support/key_helper.rb +74 -0
- data/spec/support/search_result_helper.rb +252 -0
- data/spec/support/trigger_helper.rb +51 -0
- metadata +363 -0
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "default datastream json templates" do
|
4
|
+
before(:each) do
|
5
|
+
@datastream = Cosm::Datastream.new(datastream_as_(:hash))
|
6
|
+
end
|
7
|
+
|
8
|
+
context "1.0.0 (used by Pachube API V2)" do
|
9
|
+
it "should be the default" do
|
10
|
+
@datastream.generate_json("1.0.0").should == @datastream.as_json
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should represent Pachube JSON 1.0.0 (used by API v2)" do
|
14
|
+
json = @datastream.generate_json("1.0.0")
|
15
|
+
json[:id].should == @datastream.id
|
16
|
+
json[:version].should == "1.0.0"
|
17
|
+
json[:at].should == @datastream.updated.iso8601(6)
|
18
|
+
json[:current_value].should == @datastream.current_value
|
19
|
+
json[:max_value].should == @datastream.max_value.to_s
|
20
|
+
json[:min_value].should == @datastream.min_value.to_s
|
21
|
+
json[:tags].should == @datastream.tags.split(',').map(&:strip).sort{|a,b| a.downcase <=> b.downcase}
|
22
|
+
json[:unit].should == {
|
23
|
+
:type => @datastream.unit_type,
|
24
|
+
:symbol => @datastream.unit_symbol,
|
25
|
+
:label => @datastream.unit_label
|
26
|
+
}
|
27
|
+
json[:datapoints].should_not be_nil
|
28
|
+
json[:datapoints].each do |datapoint|
|
29
|
+
@datastream.datapoints.detect {|dp| dp.at == datapoint["at"]}.value.should == datapoint["value"]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should ignore tags if blank" do
|
34
|
+
@datastream.tags = []
|
35
|
+
json = @datastream.generate_json("1.0.0")
|
36
|
+
json[:tags].should be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should ignore nil unit elements" do
|
40
|
+
@datastream.unit_symbol = nil
|
41
|
+
json = @datastream.generate_json("1.0.0")
|
42
|
+
json[:unit][:symbol].should be_nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should ignore unit if none of the elements are set" do
|
46
|
+
@datastream.unit_label = nil
|
47
|
+
@datastream.unit_symbol = nil
|
48
|
+
@datastream.unit_type = nil
|
49
|
+
json = @datastream.generate_json("1.0.0")
|
50
|
+
json[:unit].should be_nil
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should ignore unit if all the elements are blank" do
|
54
|
+
@datastream.unit_label = ''
|
55
|
+
@datastream.unit_symbol = ''
|
56
|
+
@datastream.unit_type = ''
|
57
|
+
json = @datastream.generate_json("1.0.0")
|
58
|
+
json[:unit].should be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should ignore datapoints_function if it is not set" do
|
62
|
+
@datastream.datapoints_function = nil
|
63
|
+
json = @datastream.generate_json("1.0.0")
|
64
|
+
json[:datapoints_function].should be_nil
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should use datapoints_function if it is set" do
|
68
|
+
@datastream.datapoints_function = 'average'
|
69
|
+
json = @datastream.generate_json("1.0.0")
|
70
|
+
json[:datapoints_function].should == 'average'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should ignore tags if nil" do
|
74
|
+
@datastream.tags = nil
|
75
|
+
json = @datastream.generate_json("1.0.0")
|
76
|
+
json[:tags].should be_nil
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should ignore datapoints if empty" do
|
80
|
+
@datastream.datapoints = []
|
81
|
+
json = @datastream.generate_json("1.0.0")
|
82
|
+
json[:datapoints].should be_nil
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should ignore unit if none of the elements are set" do
|
86
|
+
@datastream.unit_label = nil
|
87
|
+
@datastream.unit_symbol = nil
|
88
|
+
@datastream.unit_type = nil
|
89
|
+
json = @datastream.generate_json("1.0.0")
|
90
|
+
json[:unit].should be_nil
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should include empty elements if we pass :include_blank" do
|
94
|
+
@datastream.unit_label = ''
|
95
|
+
@datastream.unit_symbol = ''
|
96
|
+
json = @datastream.generate_json("1.0.0", :include_blank => true)
|
97
|
+
json[:unit][:label].should == ''
|
98
|
+
json[:unit][:symbol].should == ''
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "0.6-alpha (used by API V1)" do
|
103
|
+
it "should represent Pachube JSON 0.6-alpha (used by API v1)" do
|
104
|
+
json = @datastream.generate_json("0.6-alpha")
|
105
|
+
json[:id].should == @datastream.id
|
106
|
+
json[:version].should == "0.6-alpha"
|
107
|
+
json[:values].first[:recorded_at].should == @datastream.updated.iso8601
|
108
|
+
json[:values].first[:value].should == @datastream.current_value
|
109
|
+
json[:values].first[:max_value].should == @datastream.max_value.to_s
|
110
|
+
json[:values].first[:min_value].should == @datastream.min_value.to_s
|
111
|
+
json[:tags].should == @datastream.tags.split(',').map(&:strip).sort{|a,b| a.downcase <=> b.downcase}
|
112
|
+
json[:unit].should == {
|
113
|
+
:type => @datastream.unit_type,
|
114
|
+
:symbol => @datastream.unit_symbol,
|
115
|
+
:label => @datastream.unit_label
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should ignore unit if none of the elements are set" do
|
120
|
+
@datastream.unit_label = nil
|
121
|
+
@datastream.unit_symbol = nil
|
122
|
+
@datastream.unit_type = nil
|
123
|
+
json = @datastream.generate_json("0.6-alpha")
|
124
|
+
json[:unit].should be_nil
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should ignore tags if nil" do
|
128
|
+
@datastream.tags = nil
|
129
|
+
json = @datastream.generate_json("0.6-alpha")
|
130
|
+
json[:tags].should be_nil
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should ignore unit if all the elements are blank" do
|
134
|
+
@datastream.unit_label = ''
|
135
|
+
@datastream.unit_symbol = ''
|
136
|
+
@datastream.unit_type = ''
|
137
|
+
json = @datastream.generate_json("0.6-alpha")
|
138
|
+
json[:unit].should be_nil
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should ignore unit if none of the elements are set" do
|
142
|
+
@datastream.unit_label = nil
|
143
|
+
@datastream.unit_symbol = nil
|
144
|
+
@datastream.unit_type = nil
|
145
|
+
json = @datastream.generate_json("0.6-alpha")
|
146
|
+
json[:unit].should be_nil
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should ignore nil unit elements" do
|
150
|
+
@datastream.unit_symbol = nil
|
151
|
+
json = @datastream.generate_json("0.6-alpha")
|
152
|
+
json[:unit][:symbol].should be_nil
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should ignore tags if blank" do
|
156
|
+
@datastream.tags = []
|
157
|
+
json = @datastream.generate_json("0.6-alpha")
|
158
|
+
json[:tags].should be_nil
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should include empty elements if we pass :include_blank" do
|
162
|
+
@datastream.unit_label = ''
|
163
|
+
@datastream.unit_symbol = ''
|
164
|
+
json = @datastream.generate_json("0.6-alpha", :include_blank => true)
|
165
|
+
json[:unit][:label].should == ''
|
166
|
+
json[:unit][:symbol].should == ''
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
@@ -0,0 +1,397 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "default feed json templates" do
|
4
|
+
before(:each) do
|
5
|
+
@feed = Cosm::Feed.new(feed_as_(:hash))
|
6
|
+
end
|
7
|
+
|
8
|
+
context "1.0.0" do
|
9
|
+
it "should be the default" do
|
10
|
+
@feed.generate_json("1.0.0").should == @feed.as_json
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should represent Cosm JSON (used by API v2)" do
|
14
|
+
json = @feed.generate_json("1.0.0")
|
15
|
+
json[:id].should == @feed.id
|
16
|
+
json[:version].should == "1.0.0"
|
17
|
+
json[:title].should == "Cosm Office Environment"
|
18
|
+
json[:private].should == "false"
|
19
|
+
json[:icon].should == "http://cosm.com/logo.png"
|
20
|
+
json[:website].should == "http://cosm.com"
|
21
|
+
json[:tags].should == ["aardvark", "kittens", "sofa"]
|
22
|
+
json[:description].should == "Sensors in cosm.com's headquarters."
|
23
|
+
json[:feed].should == "http://test.host/testfeed.html?random=890299&rand2=91.json"
|
24
|
+
json[:auto_feed_url].should == "http://test.host2/testfeed.xml?q=something"
|
25
|
+
json[:user][:login].should == "skeletor"
|
26
|
+
json[:status].should == "live"
|
27
|
+
json[:updated].should == "2011-01-02T00:00:00.000000+00:00"
|
28
|
+
json[:created].should == "2011-01-01T00:00:00.000000+00:00"
|
29
|
+
json[:email].should == "abc@example.com"
|
30
|
+
json[:creator].should == "http://cosm.com/users/skeletor"
|
31
|
+
json[:location][:disposition].should == "fixed"
|
32
|
+
json[:location][:name].should == "office"
|
33
|
+
json[:location][:exposure].should == "indoor"
|
34
|
+
json[:location][:domain].should == "physical"
|
35
|
+
json[:location][:ele].should == "23.0"
|
36
|
+
json[:location][:lat].should == 51.5235375648154
|
37
|
+
json[:location][:lon].should == -0.0807666778564453
|
38
|
+
json[:datastreams].should have(7).things
|
39
|
+
json[:datastreams].each do |ds|
|
40
|
+
datastream = @feed.datastreams.detect{|stream| stream.id == ds[:id]}
|
41
|
+
ds[:at].should == datastream.updated.iso8601(6)
|
42
|
+
ds[:max_value].should == datastream.max_value.to_s
|
43
|
+
ds[:min_value].should == datastream.min_value.to_s
|
44
|
+
ds[:current_value].should == datastream.current_value
|
45
|
+
ds[:tags].should == datastream.tags.split(',').map(&:strip).sort{|a,b| a.downcase <=> b.downcase} if datastream.tags
|
46
|
+
ds[:unit].should == {
|
47
|
+
:label => datastream.unit_label,
|
48
|
+
:type => datastream.unit_type,
|
49
|
+
:symbol => datastream.unit_symbol
|
50
|
+
}.delete_if{ |k,v|v.nil? || v.blank? } if ds[:unit]
|
51
|
+
ds[:datapoints].each do |dp|
|
52
|
+
datapoint = datastream.datapoints.detect {|point| point.at.iso8601(6) == dp[:at]}
|
53
|
+
dp[:value].should == datapoint.value
|
54
|
+
end if ds[:datapoints]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should ignore datastream datapoints if empty" do
|
59
|
+
@feed.datastreams.each do |ds|
|
60
|
+
ds.datapoints = []
|
61
|
+
end
|
62
|
+
json = @feed.generate_json("1.0.0")
|
63
|
+
json[:datastreams].each do |ds|
|
64
|
+
ds[:datapoints].should be_nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should ignore datastream tags if nil" do
|
69
|
+
@feed.datastreams.each do |ds|
|
70
|
+
ds.tags = nil
|
71
|
+
end
|
72
|
+
json = @feed.generate_json("1.0.0")
|
73
|
+
json[:datastreams].each do |ds|
|
74
|
+
datastream = @feed.datastreams.detect{|stream| stream.id == ds[:id]}
|
75
|
+
datastream.tags.should be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should blank feed if blank" do
|
80
|
+
@feed.feed = ''
|
81
|
+
json = @feed.generate_json("1.0.0")
|
82
|
+
json[:feed].should be_blank
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should blank feed if nil" do
|
86
|
+
@feed.feed = nil
|
87
|
+
json = @feed.generate_json("1.0.0")
|
88
|
+
json[:feed].should be_blank
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should ignore updated if nil" do
|
92
|
+
@feed.updated = nil
|
93
|
+
json = @feed.generate_json("1.0.0")
|
94
|
+
json[:updated].should be_nil
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should ignore updated if nil" do
|
98
|
+
@feed.created = nil
|
99
|
+
json = @feed.generate_json("1.0.0")
|
100
|
+
json[:created].should be_nil
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should ignore tags if nil" do
|
104
|
+
@feed.tags = nil
|
105
|
+
json = @feed.generate_json("1.0.0")
|
106
|
+
json[:tags].should be_nil
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should handle tags if an array" do
|
110
|
+
@feed.tags = %w(b a c)
|
111
|
+
json = @feed.generate_json("1.0.0")
|
112
|
+
json[:tags].should == %w(a b c)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should ignore location if all elements are nil" do
|
116
|
+
@feed.location_name = nil
|
117
|
+
@feed.location_disposition = nil
|
118
|
+
@feed.location_lat = nil
|
119
|
+
@feed.location_lon = nil
|
120
|
+
@feed.location_exposure = nil
|
121
|
+
@feed.location_ele = nil
|
122
|
+
@feed.location_domain = nil
|
123
|
+
json = @feed.generate_json("1.0.0")
|
124
|
+
json[:location].should be_nil
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should ignore datastream units if blank" do
|
128
|
+
@feed.datastreams.each do |ds|
|
129
|
+
ds.unit_label = ''
|
130
|
+
ds.unit_symbol = ''
|
131
|
+
ds.unit_type = ''
|
132
|
+
end
|
133
|
+
json = @feed.generate_json("1.0.0")
|
134
|
+
json[:datastreams].each do |ds|
|
135
|
+
ds[:unit].should be_nil
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should ignore datastream units if nil" do
|
140
|
+
@feed.datastreams.each do |ds|
|
141
|
+
ds.unit_label = nil
|
142
|
+
ds.unit_symbol = nil
|
143
|
+
ds.unit_type = nil
|
144
|
+
end
|
145
|
+
json = @feed.generate_json("1.0.0")
|
146
|
+
json[:datastreams].each do |ds|
|
147
|
+
ds[:unit].should be_nil
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should ignore location if all elements are nil" do
|
152
|
+
@feed.location_name = nil
|
153
|
+
@feed.location_disposition = nil
|
154
|
+
@feed.location_lat = nil
|
155
|
+
@feed.location_lon = nil
|
156
|
+
@feed.location_exposure = nil
|
157
|
+
@feed.location_ele = nil
|
158
|
+
@feed.location_domain = nil
|
159
|
+
json = @feed.generate_json("1.0.0")
|
160
|
+
json[:location].should be_nil
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should ignore blank location elements" do
|
164
|
+
@feed.location_disposition = ""
|
165
|
+
@feed.location_ele = ""
|
166
|
+
json = @feed.generate_json("1.0.0")
|
167
|
+
json[:location][:disposition].should be_nil
|
168
|
+
json[:location][:ele].should be_nil
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should ignore nil location elements" do
|
172
|
+
@feed.location_disposition = nil
|
173
|
+
@feed.location_ele = nil
|
174
|
+
json = @feed.generate_json("1.0.0")
|
175
|
+
json[:location][:disposition].should be_nil
|
176
|
+
json[:location][:ele].should be_nil
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should ignore location_waypoints if it is nil" do
|
180
|
+
@feed.location_disposition = 'mobile'
|
181
|
+
@feed.location_waypoints = nil
|
182
|
+
json = @feed.generate_json("1.0.0")
|
183
|
+
json[:location][:disposition].should == 'mobile'
|
184
|
+
json[:location][:waypoints].should be_nil
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should use location_waypoints if it is set" do
|
188
|
+
@feed.location_disposition = 'mobile'
|
189
|
+
@feed.location_waypoints = [
|
190
|
+
{:at => Time.parse('2012-01-01 12:00:00'), :lat => 1.0, :lon => 1.1, :ele => "1.2"},
|
191
|
+
{:at => Time.parse('2012-01-01 13:00:00'), :lat => 2.0, :lon => 2.1, :ele => "2.2"}
|
192
|
+
]
|
193
|
+
json = @feed.generate_json("1.0.0")
|
194
|
+
json[:location][:disposition].should == 'mobile'
|
195
|
+
json[:location][:waypoints].should == [
|
196
|
+
{:at => Time.parse('2012-01-01 12:00:00').iso8601(6), :lat => 1.0, :lon => 1.1, :ele => "1.2"},
|
197
|
+
{:at => Time.parse('2012-01-01 13:00:00').iso8601(6), :lat => 2.0, :lon => 2.1, :ele => "2.2"}
|
198
|
+
]
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should ignore datastream tags if blank" do
|
202
|
+
@feed.datastreams.each do |ds|
|
203
|
+
ds.tags = ""
|
204
|
+
end
|
205
|
+
json = @feed.generate_json("1.0.0")
|
206
|
+
json[:datastreams].each do |ds|
|
207
|
+
ds[:tags].should be_nil
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should ignore datastream tags if nil" do
|
212
|
+
@feed.datastreams.each do |ds|
|
213
|
+
ds.tags = nil
|
214
|
+
end
|
215
|
+
json = @feed.generate_json("1.0.0")
|
216
|
+
json[:datastreams].each do |ds|
|
217
|
+
ds[:tags].should be_nil
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should ignore tags if blank" do
|
222
|
+
@feed.tags = ""
|
223
|
+
json = @feed.generate_json("1.0.0")
|
224
|
+
json[:tags].should be_nil
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should ignore tags if nil" do
|
228
|
+
@feed.tags = nil
|
229
|
+
json = @feed.generate_json("1.0.0")
|
230
|
+
json[:tags].should be_nil
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should include empty stuff if we pass :include_blank" do
|
234
|
+
@feed.description = ''
|
235
|
+
@feed.location_ele = ''
|
236
|
+
json = @feed.generate_json("1.0.0", :include_blank => true)
|
237
|
+
json[:description].should == ''
|
238
|
+
json[:location][:ele].should == ''
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
context "0.6-alpha" do
|
243
|
+
|
244
|
+
it "should represent Cosm JSON (used by API v1)" do
|
245
|
+
json = @feed.generate_json("0.6-alpha")
|
246
|
+
json[:id].should == @feed.id
|
247
|
+
json[:version].should == "0.6-alpha"
|
248
|
+
json[:title].should == "Cosm Office Environment"
|
249
|
+
json[:private].should be_nil
|
250
|
+
json[:icon].should == "http://cosm.com/logo.png"
|
251
|
+
json[:website].should == "http://cosm.com"
|
252
|
+
json[:tags].should be_nil
|
253
|
+
json[:description].should == "Sensors in cosm.com's headquarters."
|
254
|
+
json[:feed].should == "http://test.host/testfeed.html?random=890299&rand2=91.json"
|
255
|
+
json[:status].should == "live"
|
256
|
+
json[:updated].should == "2011-01-02T00:00:00.000000+00:00"
|
257
|
+
json[:email].should == "abc@example.com"
|
258
|
+
json[:location][:disposition].should == "fixed"
|
259
|
+
json[:location][:name].should == "office"
|
260
|
+
json[:location][:exposure].should == "indoor"
|
261
|
+
json[:location][:domain].should == "physical"
|
262
|
+
json[:location][:ele].should == "23.0"
|
263
|
+
json[:location][:lat].should == 51.5235375648154
|
264
|
+
json[:location][:lon].should == -0.0807666778564453
|
265
|
+
json[:datastreams].should have(7).things
|
266
|
+
json[:datastreams].each do |ds|
|
267
|
+
datastream = @feed.datastreams.detect{|stream| stream.id == ds[:id]}
|
268
|
+
ds[:values].first[:max_value].should == datastream.max_value.to_s
|
269
|
+
ds[:values].first[:min_value].should == datastream.min_value.to_s
|
270
|
+
ds[:values].first[:value].should == datastream.current_value
|
271
|
+
ds[:values].first[:recorded_at].should == datastream.updated.iso8601
|
272
|
+
ds[:tags].should == datastream.tags.split(',').map(&:strip).sort{|a,b| a.downcase <=> b.downcase} if datastream.tags
|
273
|
+
ds[:unit].should == {
|
274
|
+
:label => datastream.unit_label,
|
275
|
+
:type => datastream.unit_type,
|
276
|
+
:symbol => datastream.unit_symbol
|
277
|
+
}.delete_if{ |k,v|v.nil? || v.blank? } if ds[:unit]
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should ignore datastream units if blank" do
|
282
|
+
@feed.datastreams.each do |ds|
|
283
|
+
ds.unit_label = ''
|
284
|
+
ds.unit_symbol = ''
|
285
|
+
ds.unit_type = ''
|
286
|
+
end
|
287
|
+
json = @feed.generate_json("0.6-alpha")
|
288
|
+
json[:datastreams].each do |ds|
|
289
|
+
ds[:unit].should be_nil
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should ignore datastream units if nil" do
|
294
|
+
@feed.datastreams.each do |ds|
|
295
|
+
ds.unit_label = nil
|
296
|
+
ds.unit_symbol = nil
|
297
|
+
ds.unit_type = nil
|
298
|
+
end
|
299
|
+
json = @feed.generate_json("0.6-alpha")
|
300
|
+
json[:datastreams].each do |ds|
|
301
|
+
ds[:unit].should be_nil
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should ignore datastream tags if blank" do
|
306
|
+
@feed.datastreams.each do |ds|
|
307
|
+
ds.tags = ""
|
308
|
+
end
|
309
|
+
json = @feed.generate_json("0.6-alpha")
|
310
|
+
json[:datastreams].each do |ds|
|
311
|
+
ds[:tags].should be_nil
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
|
316
|
+
it "should ignore datastream tags if nil" do
|
317
|
+
@feed.datastreams.each do |ds|
|
318
|
+
ds.tags = nil
|
319
|
+
end
|
320
|
+
json = @feed.generate_json("0.6-alpha")
|
321
|
+
json[:datastreams].each do |ds|
|
322
|
+
ds[:tags].should be_nil
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should ignore datastream value fields if nil" do
|
327
|
+
@feed.datastreams.each do |ds|
|
328
|
+
ds.min_value = nil
|
329
|
+
end
|
330
|
+
json = @feed.generate_json("0.6-alpha")
|
331
|
+
json[:datastreams].each do |ds|
|
332
|
+
ds[:values].first[:min_value].should be_nil
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should ignore datastream value fields if blank" do
|
337
|
+
@feed.datastreams.each do |ds|
|
338
|
+
ds.min_value = ""
|
339
|
+
end
|
340
|
+
json = @feed.generate_json("0.6-alpha")
|
341
|
+
json[:datastreams].each do |ds|
|
342
|
+
ds[:values].first[:min_value].should be_nil
|
343
|
+
end
|
344
|
+
end
|
345
|
+
it "should ignore tags if blank" do
|
346
|
+
@feed.tags = ""
|
347
|
+
json = @feed.generate_json("0.6-alpha")
|
348
|
+
json[:tags].should be_nil
|
349
|
+
end
|
350
|
+
|
351
|
+
|
352
|
+
it "should ignore tags if nil" do
|
353
|
+
@feed.tags = nil
|
354
|
+
json = @feed.generate_json("0.6-alpha")
|
355
|
+
json[:tags].should be_nil
|
356
|
+
end
|
357
|
+
|
358
|
+
it "should ignore nil location elements" do
|
359
|
+
@feed.location_disposition = nil
|
360
|
+
@feed.location_ele = nil
|
361
|
+
json = @feed.generate_json("0.6-alpha")
|
362
|
+
json[:location][:disposition].should be_nil
|
363
|
+
json[:location][:ele].should be_nil
|
364
|
+
end
|
365
|
+
|
366
|
+
|
367
|
+
it "should ignore blank location elements" do
|
368
|
+
@feed.location_disposition = ""
|
369
|
+
@feed.location_ele = ""
|
370
|
+
json = @feed.generate_json("0.6-alpha")
|
371
|
+
json[:location][:disposition].should be_nil
|
372
|
+
json[:location][:ele].should be_nil
|
373
|
+
end
|
374
|
+
|
375
|
+
|
376
|
+
it "should ignore location if all elements are nil" do
|
377
|
+
@feed.location_name = nil
|
378
|
+
@feed.location_disposition = nil
|
379
|
+
@feed.location_lat = nil
|
380
|
+
@feed.location_lon = nil
|
381
|
+
@feed.location_exposure = nil
|
382
|
+
@feed.location_ele = nil
|
383
|
+
@feed.location_domain = nil
|
384
|
+
json = @feed.generate_json("0.6-alpha")
|
385
|
+
json[:location].should be_nil
|
386
|
+
end
|
387
|
+
|
388
|
+
it "should include empty stuff if we pass :include_blank" do
|
389
|
+
@feed.description = ''
|
390
|
+
@feed.location_ele = ''
|
391
|
+
json = @feed.generate_json("0.6-alpha", :include_blank => true)
|
392
|
+
json[:description].should == ''
|
393
|
+
json[:location][:ele].should == ''
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "default key json templates" do
|
4
|
+
before(:each) do
|
5
|
+
@key = Cosm::Key.new(key_as_(:hash))
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should represent Pachube JSON (used by API v2)" do
|
9
|
+
json = @key.generate_json
|
10
|
+
json[:key][:id].should == @key.id
|
11
|
+
json[:key][:expires_at].should == @key.expires_at
|
12
|
+
json[:key][:api_key].should == @key.key
|
13
|
+
json[:key][:user].should == @key.user
|
14
|
+
json[:key][:label].should == @key.label
|
15
|
+
json[:key][:private_access].should == @key.private_access
|
16
|
+
json[:key][:permissions].each_index do |permission_index|
|
17
|
+
json[:key][:permissions][permission_index][:access_methods].should == @key.permissions[permission_index].access_methods
|
18
|
+
json[:key][:permissions][permission_index][:label].should == @key.permissions[permission_index].label
|
19
|
+
json[:key][:permissions][permission_index][:referer].should == @key.permissions[permission_index].referer
|
20
|
+
json[:key][:permissions][permission_index][:source_ip].should == @key.permissions[permission_index].source_ip
|
21
|
+
json[:key][:permissions][permission_index][:minimum_interval].should == @key.permissions[permission_index].minimum_interval
|
22
|
+
json[:key][:permissions][permission_index][:resources].each_index do |res_index|
|
23
|
+
json[:key][:permissions][permission_index][:resources][res_index][:feed_id].should == @key.permissions[permission_index].resources[res_index].feed_id
|
24
|
+
json[:key][:permissions][permission_index][:resources][res_index][:datastream_id].should == @key.permissions[permission_index].resources[res_index].datastream_id
|
25
|
+
json[:key][:permissions][permission_index][:resources][res_index][:datastream_trigger_id].should == @key.permissions[permission_index].resources[res_index].datastream_trigger_id
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "default search result json templates" do
|
4
|
+
before(:each) do
|
5
|
+
@search_result = Cosm::SearchResult.new(search_result_as_(:hash))
|
6
|
+
end
|
7
|
+
|
8
|
+
context "1.0.0" do
|
9
|
+
it "should represent Pachube v2 json for search results" do
|
10
|
+
@search_result.results.each do |feed|
|
11
|
+
feed.should_receive(:generate_json).with("1.0.0").and_return("feed_100_json")
|
12
|
+
end
|
13
|
+
@search_result.generate_json("1.0.0").should == {
|
14
|
+
:totalResults => "10000",
|
15
|
+
:startIndex => "0",
|
16
|
+
:itemsPerPage => "100",
|
17
|
+
:results => ["feed_100_json"]
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "0.6-alpha" do
|
23
|
+
it "should represent Pachube v1 json for search results" do
|
24
|
+
@search_result.results.each do |feed|
|
25
|
+
feed.should_receive(:generate_json).with("0.6-alpha").and_return("feed_6_json")
|
26
|
+
end
|
27
|
+
@search_result.generate_json("0.6-alpha").should == {
|
28
|
+
:startIndex => "0",
|
29
|
+
:totalResults => "10000",
|
30
|
+
:itemsPerPage => "100",
|
31
|
+
:results => ["feed_6_json"]
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "default feed json templates" do
|
4
|
+
before(:each) do
|
5
|
+
@trigger = Cosm::Trigger.new(trigger_as_(:hash))
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should represent Pachube JSON (used by API v2)" do
|
9
|
+
json = @trigger.generate_json
|
10
|
+
json[:id].should == @trigger.id
|
11
|
+
json[:threshold_value].should == @trigger.threshold_value
|
12
|
+
json[:notified_at].should == nil
|
13
|
+
json[:url].should == @trigger.url
|
14
|
+
json[:trigger_type].should == @trigger.trigger_type
|
15
|
+
json[:stream_id].should == @trigger.stream_id
|
16
|
+
json[:environment_id].should == @trigger.environment_id
|
17
|
+
json[:user].should == @trigger.user
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "default datapoint xml templates" do
|
4
|
+
before(:each) do
|
5
|
+
@datapoint = Cosm::Datapoint.new(datapoint_as_(:hash))
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should represent Pachube datapoints" do
|
9
|
+
xml = Nokogiri.parse(@datapoint.generate_xml)
|
10
|
+
xml.should describe_eeml_for_version("0.5.1")
|
11
|
+
xml.should contain_datapoint_eeml_for_version("0.5.1")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|