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.
Files changed (35) hide show
  1. data/cosm-rb.gemspec +2 -5
  2. data/lib/cosm-rb.rb +1 -5
  3. data/lib/cosm-rb/datapoint.rb +1 -1
  4. data/lib/cosm-rb/datastream.rb +1 -1
  5. data/lib/cosm-rb/feed.rb +1 -1
  6. data/lib/cosm-rb/key.rb +1 -1
  7. data/lib/cosm-rb/parsers/json/datapoint_defaults.rb +2 -2
  8. data/lib/cosm-rb/parsers/json/datastream_defaults.rb +2 -2
  9. data/lib/cosm-rb/parsers/json/feed_defaults.rb +2 -2
  10. data/lib/cosm-rb/parsers/json/key_defaults.rb +2 -2
  11. data/lib/cosm-rb/parsers/json/search_result_defaults.rb +2 -2
  12. data/lib/cosm-rb/parsers/json/trigger_defaults.rb +2 -2
  13. data/lib/cosm-rb/search_result.rb +1 -1
  14. data/lib/cosm-rb/trigger.rb +1 -1
  15. data/lib/cosm-rb/version.rb +1 -1
  16. data/spec/cosm-rb/datapoint_spec.rb +1 -1
  17. data/spec/cosm-rb/datastream_spec.rb +1 -1
  18. data/spec/cosm-rb/feed_spec.rb +2 -2
  19. data/spec/cosm-rb/key_spec.rb +1 -1
  20. data/spec/cosm-rb/parsers/json/datapoint_defaults_spec.rb +1 -1
  21. data/spec/cosm-rb/parsers/json/datastream_defaults_spec.rb +4 -4
  22. data/spec/cosm-rb/parsers/json/trigger_defaults_spec.rb +1 -1
  23. data/spec/cosm-rb/search_result_spec.rb +2 -2
  24. data/spec/cosm-rb/trigger_spec.rb +1 -1
  25. data/spec/support/datapoint_helper.rb +1 -1
  26. data/spec/support/datastream_helper.rb +1 -1
  27. data/spec/support/feed_helper.rb +1 -1
  28. data/spec/support/fully_represent_datastream_matcher.rb +1 -1
  29. data/spec/support/fully_represent_feed_matcher.rb +1 -1
  30. data/spec/support/fully_represent_key_matcher.rb +1 -1
  31. data/spec/support/fully_represent_search_result_matcher.rb +1 -1
  32. data/spec/support/key_helper.rb +1 -1
  33. data/spec/support/search_result_helper.rb +1 -1
  34. data/spec/support/trigger_helper.rb +1 -1
  35. 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
- if defined?(JRUBY_VERSION)
21
- s.add_dependency("json_pure")
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
@@ -1,9 +1,5 @@
1
1
  require 'nokogiri'
2
- if defined?(JRUBY_VERSION)
3
- require 'json/pure'
4
- else
5
- require 'yajl/json_gem'
6
- end
2
+ require 'multi_json'
7
3
 
8
4
  $:.unshift(File.dirname(File.expand_path(__FILE__)))
9
5
 
@@ -57,7 +57,7 @@ module Cosm
57
57
  end
58
58
 
59
59
  def to_json(options = {})
60
- ::JSON.generate as_json(options)
60
+ MultiJson.dump as_json(options)
61
61
  end
62
62
 
63
63
  def to_xml(options = {})
@@ -110,7 +110,7 @@ module Cosm
110
110
  end
111
111
 
112
112
  def to_json(options = {})
113
- ::JSON.generate as_json(options)
113
+ MultiJson.dump as_json(options)
114
114
  end
115
115
 
116
116
  def to_xml(options = {})
data/lib/cosm-rb/feed.rb CHANGED
@@ -90,7 +90,7 @@ module Cosm
90
90
  end
91
91
 
92
92
  def to_json(options = {})
93
- ::JSON.generate as_json(options)
93
+ MultiJson.dump as_json(options)
94
94
  end
95
95
 
96
96
  def to_xml(options = {})
data/lib/cosm-rb/key.rb CHANGED
@@ -68,7 +68,7 @@ module Cosm
68
68
  end
69
69
 
70
70
  def to_json(options = nil)
71
- ::JSON.generate as_json(options)
71
+ MultiJson.dump(as_json(options))
72
72
  end
73
73
 
74
74
  def permissions
@@ -4,8 +4,8 @@ module Cosm
4
4
  module DatapointDefaults
5
5
  def from_json(json)
6
6
  begin
7
- ::JSON.parse(json)
8
- rescue ::JSON::ParserError => e
7
+ MultiJson.load(json)
8
+ rescue MultiJson::DecodeError => e
9
9
  raise InvalidJSONError, e.message
10
10
  end
11
11
  end
@@ -4,8 +4,8 @@ module Cosm
4
4
  module DatastreamDefaults
5
5
  def from_json(json)
6
6
  begin
7
- hash = ::JSON.parse(json)
8
- rescue ::JSON::ParserError => e
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 = ::JSON.parse(json)
12
- rescue ::JSON::ParserError => e
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 = ::JSON.parse(json)["key"]
8
- rescue ::JSON::ParserError => e
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 = ::JSON.parse(json)
10
- rescue ::JSON::ParserError => e
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)
@@ -4,8 +4,8 @@ module Cosm
4
4
  module TriggerDefaults
5
5
  def from_json(json)
6
6
  begin
7
- ::JSON.parse(json)
8
- rescue ::JSON::ParserError => e
7
+ MultiJson.load(json)
8
+ rescue MultiJson::DecodeError => e
9
9
  raise InvalidJSONError, e.message
10
10
  end
11
11
  end
@@ -55,7 +55,7 @@ module Cosm
55
55
  end
56
56
 
57
57
  def to_json(options = {})
58
- ::JSON.generate as_json(options)
58
+ MultiJson.dump as_json(options)
59
59
  end
60
60
 
61
61
  def to_xml(options = {})
@@ -56,7 +56,7 @@ module Cosm
56
56
  end
57
57
 
58
58
  def to_json(options = {})
59
- ::JSON.generate as_json(options)
59
+ MultiJson.dump as_json(options)
60
60
  end
61
61
 
62
62
 
@@ -1,3 +1,3 @@
1
1
  module Cosm #:nodoc:
2
- VERSION = '0.1.00'
2
+ VERSION = '0.1.01'
3
3
  end
@@ -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
- ::JSON.should_receive(:generate).with({:awesome => "hash"})
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
- ::JSON.should_receive(:generate).with({:awesome => "hash"})
339
+ MultiJson.should_receive(:dump).with({:awesome => "hash"})
340
340
  datastream.to_json
341
341
  end
342
342
  end
@@ -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
- JSON.parse(feed.to_json)["datastreams"].should_not be_nil
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
- ::JSON.should_receive(:generate).with({:awesome => "hash"})
336
+ MultiJson.should_receive(:dump).with({:awesome => "hash"})
337
337
  feed.to_json
338
338
  end
339
339
  end
@@ -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
- ::JSON.should_receive(:generate).with({:awesome => "hash"})
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 = JSON.parse(@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 = JSON.parse(@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 = JSON.parse(@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 = JSON.parse(@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 = JSON.parse(@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 = JSON.parse(@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
- JSON.parse(search_result.to_json)["results"].should_not be_nil
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
- ::JSON.should_receive(:generate).with({:awesome => "hash"})
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
- ::JSON.should_receive(:generate).with({:awesome => "hash"})
151
+ MultiJson.should_receive(:dump).with({:awesome => "hash"})
152
152
  trigger.to_json
153
153
  end
154
154
  end
@@ -44,7 +44,7 @@ XML
44
44
  when 'hash'
45
45
  data
46
46
  when 'json'
47
- data.to_json
47
+ MultiJson.dump(data)
48
48
  when 'xml'
49
49
  data
50
50
  else
@@ -53,7 +53,7 @@ def datastream_as_(format, options = {})
53
53
  when 'hash'
54
54
  data
55
55
  when 'json'
56
- data.to_json
56
+ MultiJson.dump(data)
57
57
  when 'xml'
58
58
  data
59
59
  when 'csv'
@@ -136,7 +136,7 @@ def feed_as_(format, options = {})
136
136
  when 'hash'
137
137
  data
138
138
  when 'json'
139
- data.to_json
139
+ MultiJson.dump(data)
140
140
  when 'xml'
141
141
  data
142
142
  when 'csv'
@@ -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 = JSON.parse(formatted_datastream)
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 = JSON.parse(formatted_feed)
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 = JSON.parse(formatted_key)["key"]
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 = JSON.parse(formatted_search_result)
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']
@@ -64,7 +64,7 @@ XML
64
64
  when 'hash'
65
65
  data
66
66
  when 'json'
67
- { "key" => data }.to_json
67
+ MultiJson.dump({ "key" => data })
68
68
  when 'xml'
69
69
  data
70
70
  else
@@ -136,7 +136,7 @@ def search_result_as_(format, options = {})
136
136
  when 'hash'
137
137
  data
138
138
  when 'json'
139
- data.to_json
139
+ MultiJson.dump(data)
140
140
  when 'xml'
141
141
  data
142
142
  else
@@ -41,7 +41,7 @@ XML
41
41
  when 'hash'
42
42
  data
43
43
  when 'json'
44
- data.to_json
44
+ MultiJson.dump(data)
45
45
  when 'xml'
46
46
  data
47
47
  else
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.00
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-01 00:00:00 +00:00
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: yajl-ruby
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: 61
31
+ hash: 23
32
32
  segments:
33
- - 0
34
- - 8
35
33
  - 1
36
- version: 0.8.1
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: nokogiri
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: *id002
70
+ version_requirements: *id003
55
71
  - !ruby/object:Gem::Dependency
56
72
  name: httparty
57
73
  prerelease: false
58
- requirement: &id003 !ruby/object:Gem::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: *id003
86
+ version_requirements: *id004
71
87
  - !ruby/object:Gem::Dependency
72
88
  name: fastercsv
73
89
  prerelease: false
74
- requirement: &id004 !ruby/object:Gem::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: *id004
102
+ version_requirements: *id005
87
103
  - !ruby/object:Gem::Dependency
88
104
  name: ruby-debug
89
105
  prerelease: false
90
- requirement: &id005 !ruby/object:Gem::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: *id005
116
+ version_requirements: *id006
101
117
  - !ruby/object:Gem::Dependency
102
118
  name: rcov
103
119
  prerelease: false
104
- requirement: &id006 !ruby/object:Gem::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: *id006
132
+ version_requirements: *id007
117
133
  - !ruby/object:Gem::Dependency
118
134
  name: rake
119
135
  prerelease: false
120
- requirement: &id007 !ruby/object:Gem::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: *id007
148
+ version_requirements: *id008
133
149
  - !ruby/object:Gem::Dependency
134
150
  name: rspec
135
151
  prerelease: false
136
- requirement: &id008 !ruby/object:Gem::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: *id008
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