xively-rb 0.2.09
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rbenv-version +1 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +91 -0
- data/CONTRIBUTING.md +95 -0
- data/Gemfile +15 -0
- data/LICENSE.md +13 -0
- data/README.md +10 -0
- data/Rakefile +25 -0
- data/ci/build_hudson.sh +24 -0
- data/init.rb +2 -0
- data/lib/xively-rb.rb +44 -0
- data/lib/xively-rb/array_extensions.rb +6 -0
- data/lib/xively-rb/base.rb +52 -0
- data/lib/xively-rb/base/instance_methods.rb +28 -0
- data/lib/xively-rb/client.rb +43 -0
- data/lib/xively-rb/datapoint.rb +72 -0
- data/lib/xively-rb/datastream.rb +127 -0
- data/lib/xively-rb/exceptions.rb +5 -0
- data/lib/xively-rb/feed.rb +109 -0
- data/lib/xively-rb/hash_extensions.rb +16 -0
- data/lib/xively-rb/helpers.rb +41 -0
- data/lib/xively-rb/key.rb +99 -0
- data/lib/xively-rb/nil_content.rb +15 -0
- data/lib/xively-rb/object_extensions.rb +6 -0
- data/lib/xively-rb/parsers/csv/datastream_defaults.rb +50 -0
- data/lib/xively-rb/parsers/csv/feed_defaults.rb +97 -0
- data/lib/xively-rb/parsers/defaults.rb +15 -0
- data/lib/xively-rb/parsers/json/datapoint_defaults.rb +16 -0
- data/lib/xively-rb/parsers/json/datastream_defaults.rb +58 -0
- data/lib/xively-rb/parsers/json/feed_defaults.rb +114 -0
- data/lib/xively-rb/parsers/json/key_defaults.rb +20 -0
- data/lib/xively-rb/parsers/json/search_result_defaults.rb +24 -0
- data/lib/xively-rb/parsers/json/trigger_defaults.rb +16 -0
- data/lib/xively-rb/parsers/xml/datapoint_defaults.rb +27 -0
- data/lib/xively-rb/parsers/xml/datastream_defaults.rb +53 -0
- data/lib/xively-rb/parsers/xml/errors.rb +7 -0
- data/lib/xively-rb/parsers/xml/feed_defaults.rb +83 -0
- data/lib/xively-rb/parsers/xml/helpers.rb +116 -0
- data/lib/xively-rb/parsers/xml/key_defaults.rb +46 -0
- data/lib/xively-rb/parsers/xml/trigger_defaults.rb +28 -0
- data/lib/xively-rb/permission.rb +67 -0
- data/lib/xively-rb/resource.rb +43 -0
- data/lib/xively-rb/search_result.rb +68 -0
- data/lib/xively-rb/string_extensions.rb +6 -0
- data/lib/xively-rb/templates/csv/datapoint_defaults.rb +22 -0
- data/lib/xively-rb/templates/csv/datastream_defaults.rb +43 -0
- data/lib/xively-rb/templates/csv/feed_defaults.rb +47 -0
- data/lib/xively-rb/templates/defaults.rb +14 -0
- data/lib/xively-rb/templates/json/datapoint_defaults.rb +15 -0
- data/lib/xively-rb/templates/json/datastream_defaults.rb +61 -0
- data/lib/xively-rb/templates/json/feed_defaults.rb +90 -0
- data/lib/xively-rb/templates/json/key_defaults.rb +39 -0
- data/lib/xively-rb/templates/json/search_result_defaults.rb +42 -0
- data/lib/xively-rb/templates/json/trigger_defaults.rb +21 -0
- data/lib/xively-rb/templates/xml/datapoint_defaults.rb +25 -0
- data/lib/xively-rb/templates/xml/datastream_defaults.rb +66 -0
- data/lib/xively-rb/templates/xml/feed_defaults.rb +112 -0
- data/lib/xively-rb/templates/xml/search_result_defaults.rb +118 -0
- data/lib/xively-rb/templates/xml_headers.rb +17 -0
- data/lib/xively-rb/trigger.rb +66 -0
- data/lib/xively-rb/validations.rb +9 -0
- data/lib/xively-rb/version.rb +3 -0
- data/spec/fixtures/models.rb +81 -0
- data/spec/spec_helper.rb +29 -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 +98 -0
- data/spec/support/datapoint_helper.rb +53 -0
- data/spec/support/datastream_helper.rb +324 -0
- data/spec/support/describe_eeml_matcher.rb +23 -0
- data/spec/support/feed_helper.rb +783 -0
- data/spec/support/fully_represent_datapoint_matcher.rb +30 -0
- data/spec/support/fully_represent_datastream_matcher.rb +96 -0
- data/spec/support/fully_represent_feed_matcher.rb +234 -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
- data/spec/xively-rb/array_extensions_spec.rb +9 -0
- data/spec/xively-rb/base/instance_methods_spec.rb +109 -0
- data/spec/xively-rb/base_spec.rb +56 -0
- data/spec/xively-rb/client_spec.rb +51 -0
- data/spec/xively-rb/datapoint_spec.rb +187 -0
- data/spec/xively-rb/datastream_spec.rb +344 -0
- data/spec/xively-rb/feed_spec.rb +341 -0
- data/spec/xively-rb/hash_extensions_spec.rb +20 -0
- data/spec/xively-rb/helpers_spec.rb +56 -0
- data/spec/xively-rb/key_spec.rb +198 -0
- data/spec/xively-rb/parsers/csv/datastream_defaults_spec.rb +110 -0
- data/spec/xively-rb/parsers/csv/feed_defaults_spec.rb +234 -0
- data/spec/xively-rb/parsers/json/datapoint_defaults_spec.rb +21 -0
- data/spec/xively-rb/parsers/json/datastream_defaults_spec.rb +105 -0
- data/spec/xively-rb/parsers/json/feed_defaults_spec.rb +45 -0
- data/spec/xively-rb/parsers/json/key_defaults_spec.rb +14 -0
- data/spec/xively-rb/parsers/json/search_result_defaults_spec.rb +18 -0
- data/spec/xively-rb/parsers/json/trigger_defaults_spec.rb +22 -0
- data/spec/xively-rb/parsers/xml/datapoint_defaults_spec.rb +19 -0
- data/spec/xively-rb/parsers/xml/datastream_defaults_spec.rb +148 -0
- data/spec/xively-rb/parsers/xml/feed_defaults_spec.rb +254 -0
- data/spec/xively-rb/parsers/xml/key_defaults_spec.rb +22 -0
- data/spec/xively-rb/parsers/xml/trigger_defaults_spec.rb +22 -0
- data/spec/xively-rb/search_result_spec.rb +257 -0
- data/spec/xively-rb/string_extensions_spec.rb +12 -0
- data/spec/xively-rb/templates/csv/datapoint_defaults_spec.rb +41 -0
- data/spec/xively-rb/templates/csv/datastream_defaults_spec.rb +131 -0
- data/spec/xively-rb/templates/csv/feed_defaults_spec.rb +78 -0
- data/spec/xively-rb/templates/json/datapoint_defaults_spec.rb +14 -0
- data/spec/xively-rb/templates/json/datastream_defaults_spec.rb +170 -0
- data/spec/xively-rb/templates/json/feed_defaults_spec.rb +399 -0
- data/spec/xively-rb/templates/json/key_defaults_spec.rb +29 -0
- data/spec/xively-rb/templates/json/search_result_defaults_spec.rb +37 -0
- data/spec/xively-rb/templates/json/trigger_defaults_spec.rb +19 -0
- data/spec/xively-rb/templates/xml/datapoint_defaults_spec.rb +14 -0
- data/spec/xively-rb/templates/xml/datastream_defaults_spec.rb +113 -0
- data/spec/xively-rb/templates/xml/feed_defaults_spec.rb +131 -0
- data/spec/xively-rb/templates/xml/search_result_defaults_spec.rb +44 -0
- data/spec/xively-rb/trigger_spec.rb +157 -0
- data/xively-rb.gemspec +41 -0
- metadata +333 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
module Xively
|
2
|
+
module Templates
|
3
|
+
module JSON
|
4
|
+
module TriggerDefaults
|
5
|
+
def generate_json(version = nil)
|
6
|
+
{
|
7
|
+
:id => self.id,
|
8
|
+
:threshold_value => self.threshold_value,
|
9
|
+
:notified_at => self.notified_at,
|
10
|
+
:url => self.url,
|
11
|
+
:trigger_type => self.trigger_type,
|
12
|
+
:stream_id => self.stream_id,
|
13
|
+
:environment_id => self.environment_id,
|
14
|
+
:user => self.user,
|
15
|
+
}.delete_if_nil_value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Xively
|
2
|
+
module Templates
|
3
|
+
module XML
|
4
|
+
module DatapointDefaults
|
5
|
+
include XMLHeaders
|
6
|
+
def generate_xml(version = nil)
|
7
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
8
|
+
xml.eeml(_eeml_0_5_1) do |eeml|
|
9
|
+
eeml.environment do |environment|
|
10
|
+
environment.data do |data|
|
11
|
+
data.datapoints do |datapoints|
|
12
|
+
datapoints.value(value, :at => at.iso8601(6))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
builder.to_xml
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Xively
|
2
|
+
module Templates
|
3
|
+
module XML
|
4
|
+
module DatastreamDefaults
|
5
|
+
include XMLHeaders
|
6
|
+
include Helpers
|
7
|
+
|
8
|
+
def generate_xml(version, options={})
|
9
|
+
case version
|
10
|
+
when "0.5.1"
|
11
|
+
xml_0_5_1 options
|
12
|
+
when "5"
|
13
|
+
xml_5 options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# As used by http://xively.com/api/v2/FEED_ID/datastreams/DATASTREAM_ID.xml
|
20
|
+
def xml_0_5_1(options={})
|
21
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
22
|
+
xml.eeml(_eeml_0_5_1) do |eeml|
|
23
|
+
eeml.environment(:updated => updated.iso8601(6), :id => feed_id, :creator => feed_creator) do |environment|
|
24
|
+
environment.data(:id => id) do |data|
|
25
|
+
parse_tag_string(tags).each do |tag|
|
26
|
+
data.tag tag
|
27
|
+
end if tags
|
28
|
+
data.current_value current_value, :at => updated.iso8601(6)
|
29
|
+
data.max_value max_value if max_value
|
30
|
+
data.min_value min_value if min_value
|
31
|
+
data.unit unit_label, {:type => unit_type, :symbol => unit_symbol}.delete_if_nil_value if unit_label || unit_type || unit_symbol
|
32
|
+
data.datapoints({"function" => datapoints_function}.delete_if_nil_value) do
|
33
|
+
datapoints.each do |datapoint|
|
34
|
+
data.value(datapoint.value, "at" => datapoint.at.iso8601(6))
|
35
|
+
end
|
36
|
+
end if datapoints.any?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
builder.to_xml
|
42
|
+
end
|
43
|
+
|
44
|
+
# As used by http://xively.com/api/v1/FEED_ID/datastreams/DATASTREAM_ID.xml
|
45
|
+
def xml_5(options={})
|
46
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
47
|
+
xml.eeml(_eeml_5) do |eeml|
|
48
|
+
eeml.environment(:updated => updated.iso8601, :id => feed_id, :creator => "http://www.haque.co.uk") do |environment|
|
49
|
+
environment.data(:id => id) do |data|
|
50
|
+
parse_tag_string(tags).each do |tag|
|
51
|
+
data.tag tag
|
52
|
+
end if tags
|
53
|
+
data.value current_value, {:minValue => min_value, :maxValue => max_value}.delete_if_nil_value
|
54
|
+
data.unit unit_label, {:type => unit_type, :symbol => unit_symbol}.delete_if_nil_value if unit_label || unit_type || unit_symbol
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
builder.to_xml
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Xively
|
2
|
+
module Templates
|
3
|
+
module XML
|
4
|
+
module FeedDefaults
|
5
|
+
include XMLHeaders
|
6
|
+
include Helpers
|
7
|
+
|
8
|
+
def generate_xml(version, options={})
|
9
|
+
case version
|
10
|
+
when "0.5.1"
|
11
|
+
xml_0_5_1 options
|
12
|
+
when "5"
|
13
|
+
xml_5 options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# As used by http://xively.com/api/v2/FEED_ID/datastreams/DATASTREAM_ID.xml
|
20
|
+
def xml_0_5_1(options={})
|
21
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
22
|
+
xml.eeml(_eeml_0_5_1) do |eeml|
|
23
|
+
eeml.environment(:updated => updated.iso8601(6), :created => created.iso8601(6), :id => id, :creator => creator) do |environment|
|
24
|
+
environment.title title unless title.blank?
|
25
|
+
environment.feed "#{feed}.xml" unless feed.blank?
|
26
|
+
environment.auto_feed_url auto_feed_url unless auto_feed_url.blank?
|
27
|
+
environment.status status unless status.blank?
|
28
|
+
environment.description description unless description.blank?
|
29
|
+
environment.icon icon unless icon.blank?
|
30
|
+
environment.website website unless website.blank?
|
31
|
+
environment.email email unless email.blank?
|
32
|
+
environment.product_id product_id unless product_id.blank?
|
33
|
+
environment.device_serial device_serial unless device_serial.blank?
|
34
|
+
environment.private_ self.private.to_s
|
35
|
+
parse_tag_string(tags).each do |tag|
|
36
|
+
environment.tag tag
|
37
|
+
end if tags
|
38
|
+
environment.location({:disposition => location_disposition, :exposure => location_exposure, :domain => location_domain}.delete_if_nil_value) do |location|
|
39
|
+
location.name location_name
|
40
|
+
location.lat location_lat
|
41
|
+
location.lon location_lon
|
42
|
+
location.ele location_ele
|
43
|
+
end
|
44
|
+
environment.user do |user|
|
45
|
+
user.login owner_login
|
46
|
+
end if owner_login
|
47
|
+
datastreams.each do |ds|
|
48
|
+
environment.data(:id => ds.id) do |data|
|
49
|
+
parse_tag_string(ds.tags).each do |tag|
|
50
|
+
data.tag tag
|
51
|
+
end if ds.tags
|
52
|
+
data.current_value ds.current_value, :at => ds.updated.iso8601(6)
|
53
|
+
data.max_value ds.max_value if ds.max_value
|
54
|
+
data.min_value ds.min_value if ds.min_value
|
55
|
+
if ds.unit_symbol || ds.unit_type
|
56
|
+
units = {:type => ds.unit_type, :symbol => ds.unit_symbol}.delete_if_nil_value
|
57
|
+
end
|
58
|
+
data.unit ds.unit_label, units if !ds.unit_label.empty? || !units.empty?
|
59
|
+
data.datapoints do
|
60
|
+
ds.datapoints.each do |datapoint|
|
61
|
+
data.value(datapoint.value, "at" => datapoint.at.iso8601(6))
|
62
|
+
end
|
63
|
+
end if ds.datapoints.any?
|
64
|
+
end
|
65
|
+
end if datastreams
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
builder.to_xml
|
70
|
+
end
|
71
|
+
|
72
|
+
# As used by http://xively.com/api/v1/FEED_ID/datastreams/DATASTREAM_ID.xml
|
73
|
+
def xml_5(options={})
|
74
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
75
|
+
xml.eeml(_eeml_5) do |eeml|
|
76
|
+
eeml.environment(:updated => updated.iso8601, :id => id, :creator => "http://www.haque.co.uk") do |environment|
|
77
|
+
environment.title title unless title.blank?
|
78
|
+
environment.feed "#{feed}.xml" unless feed.blank?
|
79
|
+
environment.status status unless status.blank?
|
80
|
+
environment.description description unless description.blank?
|
81
|
+
environment.icon icon unless icon.blank?
|
82
|
+
environment.website website unless website.blank?
|
83
|
+
environment.email email unless email.blank?
|
84
|
+
environment.location({:disposition => location_disposition, :exposure => location_exposure, :domain => location_domain}.delete_if_nil_value) do |location|
|
85
|
+
location.name location_name
|
86
|
+
location.lat location_lat
|
87
|
+
location.lon location_lon
|
88
|
+
location.ele location_ele
|
89
|
+
end if location_disposition || location_exposure || location_domain || location_name || location_lat || location_lon || location_ele
|
90
|
+
datastreams.each do |ds|
|
91
|
+
environment.data(:id => ds.id) do |data|
|
92
|
+
parse_tag_string(ds.tags).each do |tag|
|
93
|
+
data.tag tag
|
94
|
+
end if ds.tags
|
95
|
+
data.value ds.current_value, {:minValue => ds.min_value, :maxValue => ds.max_value}.delete_if_nil_value
|
96
|
+
if ds.unit_symbol || ds.unit_type
|
97
|
+
units = {:type => ds.unit_type, :symbol => ds.unit_symbol}.delete_if_nil_value
|
98
|
+
end
|
99
|
+
data.unit ds.unit_label, units if !ds.unit_label.empty? || !units.empty?
|
100
|
+
end
|
101
|
+
end if datastreams
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
builder.to_xml
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module Xively
|
2
|
+
module Templates
|
3
|
+
module XML
|
4
|
+
module SearchResultDefaults
|
5
|
+
include XMLHeaders
|
6
|
+
include Helpers
|
7
|
+
|
8
|
+
def generate_xml(version)
|
9
|
+
case version
|
10
|
+
when "0.5.1"
|
11
|
+
xml_0_5_1
|
12
|
+
when "5"
|
13
|
+
xml_5
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# As used by http://xively.com/api/v2/feeds.xml
|
20
|
+
def xml_0_5_1
|
21
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
22
|
+
xml.eeml(_eeml_0_5_1.merge({"xmlns:opensearch" => "http://a9.com/-/spec/opensearch/1.1/"})) do |eeml|
|
23
|
+
eeml['opensearch'].totalResults totalResults
|
24
|
+
eeml['opensearch'].startIndex startIndex
|
25
|
+
eeml['opensearch'].itemsPerPage itemsPerPage
|
26
|
+
results.each do |env|
|
27
|
+
eeml.environment(:created => env.created.iso8601(6), :updated => env.updated.iso8601(6), :id => env.id, :creator => env.creator) do |environment|
|
28
|
+
environment.title env.title
|
29
|
+
environment.feed "#{env.feed}.xml"
|
30
|
+
environment.status env.status
|
31
|
+
environment.description env.description
|
32
|
+
environment.icon env.icon
|
33
|
+
environment.website env.website
|
34
|
+
environment.email env.email
|
35
|
+
environment.product_id env.product_id
|
36
|
+
environment.device_serial env.device_serial
|
37
|
+
environment.private_ env.private
|
38
|
+
parse_tag_string(env.tags).each do |tag|
|
39
|
+
environment.tag tag
|
40
|
+
end if env.tags
|
41
|
+
environment.location({:disposition => env.location_disposition, :exposure => env.location_exposure, :domain => env.location_domain}.delete_if_nil_value) do |location|
|
42
|
+
location.name env.location_name
|
43
|
+
location.lat env.location_lat
|
44
|
+
location.lon env.location_lon
|
45
|
+
location.ele env.location_ele
|
46
|
+
end if env.location_disposition || env.location_exposure || env.location_domain || env.location_name || env.location_lat || env.location_lon || env.location_ele
|
47
|
+
env.datastreams.each do |ds|
|
48
|
+
environment.data(:id => ds.id) do |data|
|
49
|
+
parse_tag_string(ds.tags).each do |tag|
|
50
|
+
data.tag tag
|
51
|
+
end if ds.tags
|
52
|
+
data.current_value ds.current_value, :at => ds.updated.iso8601(6)
|
53
|
+
data.max_value ds.max_value if ds.max_value
|
54
|
+
data.min_value ds.min_value if ds.min_value
|
55
|
+
if ds.unit_symbol || ds.unit_type
|
56
|
+
units = {:type => ds.unit_type, :symbol => ds.unit_symbol}.delete_if_nil_value
|
57
|
+
end
|
58
|
+
data.unit ds.unit_label, units if !ds.unit_label.empty? || !units.empty?
|
59
|
+
data.datapoints do
|
60
|
+
ds.datapoints.each do |datapoint|
|
61
|
+
data.value(datapoint.value, "at" => datapoint.at.iso8601(6))
|
62
|
+
end
|
63
|
+
end if ds.datapoints.any?
|
64
|
+
end
|
65
|
+
end if env.datastreams
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
builder.to_xml
|
71
|
+
end
|
72
|
+
|
73
|
+
# As used by http://xively.com/api/v1/feeds.xml
|
74
|
+
def xml_5
|
75
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
76
|
+
xml.eeml(_eeml_5.merge({"xmlns:opensearch" => "http://a9.com/-/spec/opensearch/1.1/"})) do |eeml|
|
77
|
+
eeml['opensearch'].totalResults totalResults
|
78
|
+
eeml['opensearch'].startIndex startIndex
|
79
|
+
eeml['opensearch'].itemsPerPage itemsPerPage
|
80
|
+
results.each do |env|
|
81
|
+
eeml.environment(:updated => env.updated.iso8601, :id => env.id, :creator => "http://www.haque.co.uk") do |environment|
|
82
|
+
environment.title env.title
|
83
|
+
environment.feed "#{env.feed}.xml"
|
84
|
+
environment.status env.status
|
85
|
+
environment.description env.description
|
86
|
+
environment.icon env.icon
|
87
|
+
environment.website env.website
|
88
|
+
environment.email env.email
|
89
|
+
environment.location({:disposition => env.location_disposition, :exposure => env.location_exposure, :domain => env.location_domain}.delete_if_nil_value) do |location|
|
90
|
+
location.name env.location_name
|
91
|
+
location.lat env.location_lat
|
92
|
+
location.lon env.location_lon
|
93
|
+
location.ele env.location_ele
|
94
|
+
end
|
95
|
+
env.datastreams.each do |ds|
|
96
|
+
environment.data(:id => ds.id) do |data|
|
97
|
+
parse_tag_string(ds.tags).each do |tag|
|
98
|
+
data.tag tag
|
99
|
+
end if ds.tags
|
100
|
+
data.value ds.current_value, {:minValue => ds.min_value, :maxValue => ds.max_value}.delete_if_nil_value
|
101
|
+
if ds.unit_symbol || ds.unit_type
|
102
|
+
units = {:type => ds.unit_type, :symbol => ds.unit_symbol}.delete_if_nil_value
|
103
|
+
end
|
104
|
+
data.unit ds.unit_label, units if !ds.unit_label.empty? || !units.empty?
|
105
|
+
end
|
106
|
+
end if env.datastreams
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
builder.to_xml
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Xively
|
2
|
+
module Templates
|
3
|
+
module XMLHeaders
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def _eeml_0_5_1
|
8
|
+
{:xmlns => "http://www.eeml.org/xsd/0.5.1", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", :version => "0.5.1", "xsi:schemaLocation" => "http://www.eeml.org/xsd/0.5.1 http://www.eeml.org/xsd/0.5.1/0.5.1.xsd"}
|
9
|
+
end
|
10
|
+
|
11
|
+
def _eeml_5
|
12
|
+
{:xmlns => "http://www.eeml.org/xsd/005", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", :version => "5", "xsi:schemaLocation" => "http://www.eeml.org/xsd/005 http://www.eeml.org/xsd/005/005.xsd"}
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Xively
|
2
|
+
class Trigger
|
3
|
+
ALLOWED_KEYS = %w(threshold_value user notified_at url trigger_type id environment_id stream_id)
|
4
|
+
ALLOWED_KEYS.each { |key| attr_accessor(key.to_sym) }
|
5
|
+
|
6
|
+
include Xively::Templates::JSON::TriggerDefaults
|
7
|
+
include Xively::Parsers::JSON::TriggerDefaults
|
8
|
+
include Xively::Parsers::XML::TriggerDefaults
|
9
|
+
|
10
|
+
# validates_presence_of :url
|
11
|
+
# validates_presence_of :stream_id
|
12
|
+
# validates_presence_of :environment_id
|
13
|
+
# validates_presence_of :user
|
14
|
+
|
15
|
+
include Validations
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
pass = true
|
19
|
+
[:url, :stream_id, :environment_id, :user].each do |attr|
|
20
|
+
if self.send(attr).blank?
|
21
|
+
errors[attr] = ["can't be blank"]
|
22
|
+
pass = false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
return pass
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(input = {}, format = nil)
|
29
|
+
raise InvalidFormatError, "Unknown format specified, currently we can only parse JSON or XML." unless [nil,:json,:xml].include?(format)
|
30
|
+
if input.is_a?(Hash)
|
31
|
+
self.attributes = input
|
32
|
+
elsif format == :json || (format.nil? && input.strip[0...1].to_s == "{")
|
33
|
+
self.attributes = from_json(input)
|
34
|
+
else
|
35
|
+
self.attributes = from_xml(input)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def attributes
|
40
|
+
h = {}
|
41
|
+
ALLOWED_KEYS.each do |key|
|
42
|
+
value = self.send(key)
|
43
|
+
h[key] = value unless value.nil?
|
44
|
+
end
|
45
|
+
return h
|
46
|
+
end
|
47
|
+
|
48
|
+
def attributes=(input)
|
49
|
+
return if input.nil?
|
50
|
+
ALLOWED_KEYS.each { |key| self.send("#{key}=", input[key]) }
|
51
|
+
return attributes
|
52
|
+
end
|
53
|
+
|
54
|
+
def as_json(options = {})
|
55
|
+
generate_json
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_json(options = {})
|
59
|
+
MultiJson.dump as_json(options)
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|