cosm-rb 0.1.00 → 0.1.01
Sign up to get free protection for your applications and to get access to all the features.
- data/cosm-rb.gemspec +2 -5
- data/lib/cosm-rb.rb +1 -5
- data/lib/cosm-rb/datapoint.rb +1 -1
- data/lib/cosm-rb/datastream.rb +1 -1
- data/lib/cosm-rb/feed.rb +1 -1
- data/lib/cosm-rb/key.rb +1 -1
- data/lib/cosm-rb/parsers/json/datapoint_defaults.rb +2 -2
- data/lib/cosm-rb/parsers/json/datastream_defaults.rb +2 -2
- data/lib/cosm-rb/parsers/json/feed_defaults.rb +2 -2
- data/lib/cosm-rb/parsers/json/key_defaults.rb +2 -2
- data/lib/cosm-rb/parsers/json/search_result_defaults.rb +2 -2
- data/lib/cosm-rb/parsers/json/trigger_defaults.rb +2 -2
- data/lib/cosm-rb/search_result.rb +1 -1
- data/lib/cosm-rb/trigger.rb +1 -1
- data/lib/cosm-rb/version.rb +1 -1
- data/spec/cosm-rb/datapoint_spec.rb +1 -1
- data/spec/cosm-rb/datastream_spec.rb +1 -1
- data/spec/cosm-rb/feed_spec.rb +2 -2
- data/spec/cosm-rb/key_spec.rb +1 -1
- data/spec/cosm-rb/parsers/json/datapoint_defaults_spec.rb +1 -1
- data/spec/cosm-rb/parsers/json/datastream_defaults_spec.rb +4 -4
- data/spec/cosm-rb/parsers/json/trigger_defaults_spec.rb +1 -1
- data/spec/cosm-rb/search_result_spec.rb +2 -2
- data/spec/cosm-rb/trigger_spec.rb +1 -1
- data/spec/support/datapoint_helper.rb +1 -1
- data/spec/support/datastream_helper.rb +1 -1
- data/spec/support/feed_helper.rb +1 -1
- data/spec/support/fully_represent_datastream_matcher.rb +1 -1
- data/spec/support/fully_represent_feed_matcher.rb +1 -1
- data/spec/support/fully_represent_key_matcher.rb +1 -1
- data/spec/support/fully_represent_search_result_matcher.rb +1 -1
- data/spec/support/key_helper.rb +1 -1
- data/spec/support/search_result_helper.rb +1 -1
- data/spec/support/trigger_helper.rb +1 -1
- metadata +39 -23
data/cosm-rb.gemspec
CHANGED
@@ -17,11 +17,8 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
else
|
23
|
-
s.add_dependency("yajl-ruby", ">=0.8.1")
|
24
|
-
end
|
20
|
+
s.add_dependency("multi_json", ">=1.3.6")
|
21
|
+
s.add_dependency("yajl-ruby", ">=1.1.0")
|
25
22
|
s.add_dependency("nokogiri", ">=1.4.4")
|
26
23
|
s.add_dependency("httparty", ">=0.8.3")
|
27
24
|
|
data/lib/cosm-rb.rb
CHANGED
data/lib/cosm-rb/datapoint.rb
CHANGED
data/lib/cosm-rb/datastream.rb
CHANGED
data/lib/cosm-rb/feed.rb
CHANGED
data/lib/cosm-rb/key.rb
CHANGED
@@ -4,8 +4,8 @@ module Cosm
|
|
4
4
|
module DatastreamDefaults
|
5
5
|
def from_json(json)
|
6
6
|
begin
|
7
|
-
hash =
|
8
|
-
rescue ::
|
7
|
+
hash = MultiJson.load(json)
|
8
|
+
rescue MultiJson::DecodeError => e
|
9
9
|
raise InvalidJSONError, e.message
|
10
10
|
end
|
11
11
|
raise InvalidJSONError, "JSON doesn't appear to be a hash" unless hash.is_a?(Hash)
|
@@ -8,8 +8,8 @@ module Cosm
|
|
8
8
|
|
9
9
|
def from_json(json)
|
10
10
|
begin
|
11
|
-
hash =
|
12
|
-
rescue ::
|
11
|
+
hash = MultiJson.load(json)
|
12
|
+
rescue MultiJson::DecodeError => e
|
13
13
|
raise InvalidJSONError, e.message
|
14
14
|
end
|
15
15
|
raise InvalidJSONError, "JSON doesn't appear to be a hash" unless hash.is_a?(Hash)
|
@@ -4,8 +4,8 @@ module Cosm
|
|
4
4
|
module KeyDefaults
|
5
5
|
def from_json(json)
|
6
6
|
begin
|
7
|
-
hash =
|
8
|
-
rescue ::
|
7
|
+
hash = MultiJson.load(json)["key"]
|
8
|
+
rescue MultiJson::DecodeError => e
|
9
9
|
raise InvalidJSONError, e.message
|
10
10
|
end
|
11
11
|
raise InvalidJSONError, "JSON doesn't appear to be a hash" unless hash.is_a?(Hash)
|
@@ -6,8 +6,8 @@ module Cosm
|
|
6
6
|
|
7
7
|
def from_json(json)
|
8
8
|
begin
|
9
|
-
hash =
|
10
|
-
rescue ::
|
9
|
+
hash = MultiJson.load(json)
|
10
|
+
rescue MultiJson::DecodeError => e
|
11
11
|
raise InvalidJSONError, e.message
|
12
12
|
end
|
13
13
|
raise InvalidJSONError, "JSON doesn't appear to be a hash" unless hash.is_a?(Hash)
|
data/lib/cosm-rb/trigger.rb
CHANGED
data/lib/cosm-rb/version.rb
CHANGED
@@ -179,7 +179,7 @@ describe Cosm::Datapoint do
|
|
179
179
|
datapoint_hash = {"id" => "env001", "value" => "2344"}
|
180
180
|
datapoint = Cosm::Datapoint.new(datapoint_hash)
|
181
181
|
datapoint.should_receive(:as_json).and_return({:awesome => "hash"})
|
182
|
-
|
182
|
+
MultiJson.should_receive(:dump).with({:awesome => "hash"})
|
183
183
|
datapoint.to_json
|
184
184
|
end
|
185
185
|
end
|
@@ -336,7 +336,7 @@ describe Cosm::Datastream do
|
|
336
336
|
datastream_hash = {"id" => "env001", "value" => "2344"}
|
337
337
|
datastream = Cosm::Datastream.new(datastream_hash)
|
338
338
|
datastream.should_receive(:as_json).and_return({:awesome => "hash"})
|
339
|
-
|
339
|
+
MultiJson.should_receive(:dump).with({:awesome => "hash"})
|
340
340
|
datastream.to_json
|
341
341
|
end
|
342
342
|
end
|
data/spec/cosm-rb/feed_spec.rb
CHANGED
@@ -326,14 +326,14 @@ describe Cosm::Feed do
|
|
326
326
|
it "should generate datastreams" do
|
327
327
|
feed = Cosm::Feed.new(feed_as_('hash'))
|
328
328
|
feed.datastreams = datastream_as_(:hash)
|
329
|
-
|
329
|
+
MultiJson.load(feed.to_json)["datastreams"].should_not be_nil
|
330
330
|
end
|
331
331
|
|
332
332
|
it "should pass the output of #as_json to yajl" do
|
333
333
|
feed_hash = {"title" => "Environment"}
|
334
334
|
feed = Cosm::Feed.new(feed_hash)
|
335
335
|
feed.should_receive(:as_json).and_return({:awesome => "hash"})
|
336
|
-
|
336
|
+
MultiJson.should_receive(:dump).with({:awesome => "hash"})
|
337
337
|
feed.to_json
|
338
338
|
end
|
339
339
|
end
|
data/spec/cosm-rb/key_spec.rb
CHANGED
@@ -190,7 +190,7 @@ describe Cosm::Key do
|
|
190
190
|
it "should pass the output of #as_json to yajl" do
|
191
191
|
key = Cosm::Key.new(@key_hash)
|
192
192
|
key.should_receive(:as_json).and_return({:awesome => "hash"})
|
193
|
-
|
193
|
+
MultiJson.should_receive(:dump).with({:awesome => "hash"})
|
194
194
|
key.to_json
|
195
195
|
end
|
196
196
|
end
|
@@ -8,7 +8,7 @@ describe "default datapoint json parser" do
|
|
8
8
|
it "should convert into attributes hash" do
|
9
9
|
@json = datapoint_as_(:json)
|
10
10
|
attributes = @datapoint.from_json(@json)
|
11
|
-
json =
|
11
|
+
json = MultiJson.load(@json)
|
12
12
|
attributes["at"].should == json["at"]
|
13
13
|
attributes["value"].should == json["value"]
|
14
14
|
end
|
@@ -10,7 +10,7 @@ describe "default datastream json parser" do
|
|
10
10
|
it "should default to v2 if no version is present" do
|
11
11
|
@json = datastream_as_(:json, :version => "1.0.0", :except => [:version])
|
12
12
|
attributes = @datastream.from_json(@json)
|
13
|
-
json =
|
13
|
+
json = MultiJson.load(@json)
|
14
14
|
attributes["id"].should == json["id"]
|
15
15
|
attributes["updated"].should == json["at"]
|
16
16
|
attributes["current_value"].should == json["current_value"]
|
@@ -40,7 +40,7 @@ describe "default datastream json parser" do
|
|
40
40
|
it "should convert into attributes hash" do
|
41
41
|
@json = datastream_as_(:json)
|
42
42
|
attributes = @datastream.from_json(@json)
|
43
|
-
json =
|
43
|
+
json = MultiJson.load(@json)
|
44
44
|
attributes["id"].should == json["id"]
|
45
45
|
attributes["updated"].should == json["at"]
|
46
46
|
attributes["current_value"].should == json["current_value"]
|
@@ -68,7 +68,7 @@ describe "default datastream json parser" do
|
|
68
68
|
it "should capture timestamp" do
|
69
69
|
@json = datastream_as_(:json, :version => "1.0.0-minimal_timestamp")
|
70
70
|
attributes = @datastream.from_json(@json)
|
71
|
-
json =
|
71
|
+
json = MultiJson.load(@json)
|
72
72
|
attributes["updated"].should_not be_nil
|
73
73
|
attributes["updated"].should == json["at"]
|
74
74
|
end
|
@@ -79,7 +79,7 @@ describe "default datastream json parser" do
|
|
79
79
|
it "should convert into attributes hash" do
|
80
80
|
@json = datastream_as_(:json, :version => "0.6-alpha")
|
81
81
|
attributes = @datastream.from_json(@json)
|
82
|
-
json =
|
82
|
+
json = MultiJson.load(@json)
|
83
83
|
attributes["id"].should == json["id"]
|
84
84
|
attributes["updated"].should == json["values"].first["recorded_at"]
|
85
85
|
attributes["current_value"].should == json["values"].first["value"]
|
@@ -8,7 +8,7 @@ describe "default trigger json parser" do
|
|
8
8
|
it "should convert into attributes hash" do
|
9
9
|
@json = trigger_as_(:json)
|
10
10
|
attributes = @trigger.from_json(@json)
|
11
|
-
json =
|
11
|
+
json = MultiJson.load(@json)
|
12
12
|
Cosm::Trigger::ALLOWED_KEYS.each do |key|
|
13
13
|
attributes[key].should == json[key]
|
14
14
|
end
|
@@ -240,14 +240,14 @@ describe Cosm::SearchResult do
|
|
240
240
|
it "should generate feeds" do
|
241
241
|
search_result = Cosm::SearchResult.new("results" => [feed_as_('hash')])
|
242
242
|
search_result.results = feed_as_(:hash)
|
243
|
-
|
243
|
+
MultiJson.load(search_result.to_json)["results"].should_not be_nil
|
244
244
|
end
|
245
245
|
|
246
246
|
it "should pass the output of #as_json to yajl" do
|
247
247
|
search_result_hash = {"totalResults" => 100}
|
248
248
|
search_result = Cosm::SearchResult.new(search_result_hash)
|
249
249
|
search_result.should_receive(:as_json).and_return({:awesome => "hash"})
|
250
|
-
|
250
|
+
MultiJson.should_receive(:dump).with({:awesome => "hash"})
|
251
251
|
search_result.to_json
|
252
252
|
end
|
253
253
|
end
|
@@ -148,7 +148,7 @@ describe Cosm::Trigger do
|
|
148
148
|
trigger_hash = {"title" => "Environment"}
|
149
149
|
trigger = Cosm::Trigger.new(trigger_hash)
|
150
150
|
trigger.should_receive(:as_json).and_return({:awesome => "hash"})
|
151
|
-
|
151
|
+
MultiJson.should_receive(:dump).with({:awesome => "hash"})
|
152
152
|
trigger.to_json
|
153
153
|
end
|
154
154
|
end
|
data/spec/support/feed_helper.rb
CHANGED
@@ -75,7 +75,7 @@ RSpec::Matchers.define :fully_represent_datastream do |format, formatted_datastr
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def match_json_datastream(datastream, formatted_datastream)
|
78
|
-
json =
|
78
|
+
json = MultiJson.load(formatted_datastream)
|
79
79
|
case json['version']
|
80
80
|
when '1.0.0'
|
81
81
|
raise "Not implemented"
|
@@ -149,7 +149,7 @@ RSpec::Matchers.define :fully_represent_feed do |format, formatted_feed|
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def match_json_feed(feed, formatted_feed)
|
152
|
-
json =
|
152
|
+
json = MultiJson.load(formatted_feed)
|
153
153
|
case json['version']
|
154
154
|
when '1.0.0'
|
155
155
|
feed.title.should == json["title"]
|
@@ -47,7 +47,7 @@ RSpec::Matchers.define :fully_represent_key do |format, formatted_key|
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def match_json_key(key, formatted_key)
|
50
|
-
json =
|
50
|
+
json = MultiJson.load(formatted_key)["key"]
|
51
51
|
key.id.should == json["id"]
|
52
52
|
key.expires_at.should == json["expires_at"]
|
53
53
|
key.key.should == json["api_key"]
|
@@ -12,7 +12,7 @@ RSpec::Matchers.define :fully_represent_search_result do |format, formatted_sear
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def match_json_search_result(search_result, formatted_search_result)
|
15
|
-
json =
|
15
|
+
json = MultiJson.load(formatted_search_result)
|
16
16
|
search_result.totalResults.should == json['totalResults']
|
17
17
|
search_result.startIndex.should == json['startIndex']
|
18
18
|
search_result.itemsPerPage.should == json['itemsPerPage']
|
data/spec/support/key_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cosm-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.01
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Paul Bellamy
|
@@ -17,29 +17,45 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2012-09-
|
20
|
+
date: 2012-09-06 00:00:00 +00:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
|
-
name:
|
24
|
+
name: multi_json
|
25
25
|
prerelease: false
|
26
26
|
requirement: &id001 !ruby/object:Gem::Requirement
|
27
27
|
none: false
|
28
28
|
requirements:
|
29
29
|
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
hash:
|
31
|
+
hash: 23
|
32
32
|
segments:
|
33
|
-
- 0
|
34
|
-
- 8
|
35
33
|
- 1
|
36
|
-
|
34
|
+
- 3
|
35
|
+
- 6
|
36
|
+
version: 1.3.6
|
37
37
|
type: :runtime
|
38
38
|
version_requirements: *id001
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
|
-
name:
|
40
|
+
name: yajl-ruby
|
41
41
|
prerelease: false
|
42
42
|
requirement: &id002 !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 19
|
48
|
+
segments:
|
49
|
+
- 1
|
50
|
+
- 1
|
51
|
+
- 0
|
52
|
+
version: 1.1.0
|
53
|
+
type: :runtime
|
54
|
+
version_requirements: *id002
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
prerelease: false
|
58
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
43
59
|
none: false
|
44
60
|
requirements:
|
45
61
|
- - ">="
|
@@ -51,11 +67,11 @@ dependencies:
|
|
51
67
|
- 4
|
52
68
|
version: 1.4.4
|
53
69
|
type: :runtime
|
54
|
-
version_requirements: *
|
70
|
+
version_requirements: *id003
|
55
71
|
- !ruby/object:Gem::Dependency
|
56
72
|
name: httparty
|
57
73
|
prerelease: false
|
58
|
-
requirement: &
|
74
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
59
75
|
none: false
|
60
76
|
requirements:
|
61
77
|
- - ">="
|
@@ -67,11 +83,11 @@ dependencies:
|
|
67
83
|
- 3
|
68
84
|
version: 0.8.3
|
69
85
|
type: :runtime
|
70
|
-
version_requirements: *
|
86
|
+
version_requirements: *id004
|
71
87
|
- !ruby/object:Gem::Dependency
|
72
88
|
name: fastercsv
|
73
89
|
prerelease: false
|
74
|
-
requirement: &
|
90
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
75
91
|
none: false
|
76
92
|
requirements:
|
77
93
|
- - ">="
|
@@ -83,11 +99,11 @@ dependencies:
|
|
83
99
|
- x
|
84
100
|
version: 1.5.x
|
85
101
|
type: :runtime
|
86
|
-
version_requirements: *
|
102
|
+
version_requirements: *id005
|
87
103
|
- !ruby/object:Gem::Dependency
|
88
104
|
name: ruby-debug
|
89
105
|
prerelease: false
|
90
|
-
requirement: &
|
106
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
91
107
|
none: false
|
92
108
|
requirements:
|
93
109
|
- - ">="
|
@@ -97,11 +113,11 @@ dependencies:
|
|
97
113
|
- 0
|
98
114
|
version: "0"
|
99
115
|
type: :development
|
100
|
-
version_requirements: *
|
116
|
+
version_requirements: *id006
|
101
117
|
- !ruby/object:Gem::Dependency
|
102
118
|
name: rcov
|
103
119
|
prerelease: false
|
104
|
-
requirement: &
|
120
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
105
121
|
none: false
|
106
122
|
requirements:
|
107
123
|
- - ">="
|
@@ -113,11 +129,11 @@ dependencies:
|
|
113
129
|
- 9
|
114
130
|
version: 0.9.9
|
115
131
|
type: :development
|
116
|
-
version_requirements: *
|
132
|
+
version_requirements: *id007
|
117
133
|
- !ruby/object:Gem::Dependency
|
118
134
|
name: rake
|
119
135
|
prerelease: false
|
120
|
-
requirement: &
|
136
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
121
137
|
none: false
|
122
138
|
requirements:
|
123
139
|
- - "="
|
@@ -129,11 +145,11 @@ dependencies:
|
|
129
145
|
- 7
|
130
146
|
version: 0.8.7
|
131
147
|
type: :development
|
132
|
-
version_requirements: *
|
148
|
+
version_requirements: *id008
|
133
149
|
- !ruby/object:Gem::Dependency
|
134
150
|
name: rspec
|
135
151
|
prerelease: false
|
136
|
-
requirement: &
|
152
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
137
153
|
none: false
|
138
154
|
requirements:
|
139
155
|
- - "="
|
@@ -145,7 +161,7 @@ dependencies:
|
|
145
161
|
- 0
|
146
162
|
version: 2.6.0
|
147
163
|
type: :development
|
148
|
-
version_requirements: *
|
164
|
+
version_requirements: *id009
|
149
165
|
description: A library for communicating with the Cosm REST API, parsing and rendering Cosm feed formats
|
150
166
|
email:
|
151
167
|
- paul.a.bellamy@gmail.com
|