cosm-rb 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,3 +8,9 @@ rvm:
8
8
  - 1.8.7
9
9
  - 1.9.2
10
10
  - 1.9.3
11
+ - jruby-18mode
12
+ - jruby-19mode
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: jruby-18mode
16
+ - rvm: jruby-19mode
@@ -1,4 +1,4 @@
1
- Copyright (C) 2011 by Connected Enviroments Ltd.
1
+ Copyright (C) 2012 Cosm Ltd.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,195 +1,18 @@
1
1
  [![Build Status](https://secure.travis-ci.org/cosm/cosm-rb.png)](http://travis-ci.org/cosm/cosm-rb)
2
2
 
3
- Cosm gem
4
- ========================
3
+ ## Cosm gem
5
4
 
6
- WORK IN PROGRESS
5
+ Use this gem if you would like to convert between Cosm data formats or represent Cosm objects in Ruby.
6
+ You can also interact with the Cosm REST API using this gem.
7
7
 
8
- This gem will convert between Cosm Data Formats.
9
- You can use it to prepare data for sending to Cosm or for parsing data received from Cosm.
10
-
11
- Allowed inputs
12
- --------------
13
-
14
- * XML (EEML)
15
- * JSON
16
- * CSV
17
-
18
- Outputs
19
- -------
20
-
21
- * XML (EEML)
22
- * JSON
23
- * CSV
24
-
25
- Cosm Interface
26
- ----------------------------
27
-
28
- If you have your own model that maps to a Cosm Feed (such as an ActiveRecord model), this plugin will provide many convenience methods to convert your objects into Cosm objects.
29
-
30
- ### Example with ActiveRecord
31
-
32
- class Datastream < ActiveRecord::Base
33
- belongs_to :feed
34
- end
35
-
36
- class Feed < ActiveRecord::Base
37
- has_many :datastreams
38
- extend Cosm::Base
39
- is_cosm :feed
40
- end
41
-
42
- ### Provided methods
43
-
44
- @cosm_feed = feed.to_cosm # returns an instance of Cosm::Feed
45
- @cosm_feed.to_json(:version => "1.0.0") # converts your feed and associated datastreams into Cosm V2 JSON
46
- @cosm_feed.as_json(:version => "0.6-alpha") # provides a json hash for 0.6-alpha
47
- @cosm_feed.to_xml(:version => "0.5.1") # converts your feed and associated datastreams into Cosm V2 XML (EEML)
48
-
49
- ### Supported formats
50
-
51
- * JSON "1.0.0" - used by Cosm API v2
52
- * JSON "0.6-alpha" - used by Cosm API v1
53
- * XML "0.5.1" - used by Cosm API v2
54
- * XML "5" - used by Cosm API v1
55
- * CSV v1 - used by Cosm API v1
56
- * CSV v2 - used by Cosm API v2
57
-
58
- ### Mapped fields
59
-
60
- See [the Cosm Api docs] [1] for a description of each field.
8
+ ### Documentation
61
9
 
62
- [1]: https://cosm.com/docs/v2/ "Cosm Api Docs"
10
+ Documentation can be found on the [wiki](https://github.com/cosm/cosm-rb/wiki/Documentation).
63
11
 
64
- By default the gem expects your object to have the following fields:
12
+ ### Examples
65
13
 
66
- #### Feeds
14
+ A working example using this gem can be found [here](https://github.com/levent/cosm_app-rb/)
67
15
 
68
- * creator
69
- * datastreams
70
- * description
71
- * email
72
- * feed
73
- * icon
74
- * id
75
- * location_disposition
76
- * location_domain
77
- * location_ele
78
- * location_exposure
79
- * location_lat
80
- * location_lon
81
- * location_name
82
- * private
83
- * status
84
- * tags
85
- * title
86
- * updated
87
- * website
88
-
89
-
90
- #### Datastreams
91
-
92
- * current_value
93
- * datapoints
94
- * feed_creator
95
- * feed_id
96
- * id
97
- * max_value
98
- * min_value
99
- * tags
100
- * unit_label
101
- * unit_symbol
102
- * unit_type
103
- * updated
104
-
105
- #### Datapoints
106
-
107
- * at
108
- * value
109
- * feed_id
110
- * datastream_id
111
-
112
- If you use different field names, want to map custom fields or want to map fields onto instance methods you can:
113
-
114
- class Feed < ActiveRecord::Base
115
- extend Cosm::Base
116
-
117
- has_one :geo_location
118
- is_cosm :feed, {:location_lat => :geo_lat, :location_lon => :geo_lon}
119
-
120
- def geo_lat
121
- geo_location.try(:latitude)
122
- end
123
-
124
- def geo_lon
125
- geo_location.try(:longitude)
126
- end
127
- end
128
-
129
- Examples using the Cosm objects
130
- --------------------------------------------
131
-
132
- feed = Cosm::Feed.new('{"title":"Cosm Office Environment"}')
133
- feed.as_json # {"title" => "Cosm Office Environment"}
134
- feed.to_json # {"title":"Cosm Office Environment"}
135
- feed.to_xml
136
- # <?xml version="1.0" encoding="UTF-8"?
137
- # <eeml 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">
138
- # <environment updated="2010-11-11T15:57:17.637887Z" id="12567" creator="https://cosm.com">
139
- # <title>Cosm Office Environment</title>
140
- # </environment>
141
- # </eeml>
142
- feed.attributes # {:title => "Cosm Office Environment"}
143
-
144
- ### Parsing a Datastream using json
145
-
146
- json = '
147
- {
148
- "max_value": "658.0",
149
- "current_value": "14",
150
- "datapoints": [{
151
- "value": "1",
152
- "at": "2011-03-02T15:59:56.895922Z"
153
- },
154
- {
155
- "value": "1",
156
- "at": "2011-03-02T16:00:07.188648Z"
157
- },
158
- {
159
- "value": "2",
160
- "at": "2011-03-02T16:00:18.416500Z"
161
- }],
162
- "min_value": "0.0",
163
- "id": "0",
164
- "tags": ["humidity", "Temperature", "freakin lasers"],
165
- "version": "1.0.0",
166
- "unit": {
167
- "label": "percentage",
168
- "symbol": "%",
169
- "type": "derived SI"
170
- },
171
- "at": "2011-02-16T16:21:01.834174Z"
172
- }'
173
- datastream = Cosm::Datastream.new(json)
174
- datastream.to_xml # =>
175
- # <?xml version="1.0" encoding="UTF-8"?>
176
- # <eeml 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">
177
- # <environment creator="" updated="2011-02-16T16:21:01.834174Z" id="">
178
- # <data id="0">
179
- # <tag>freakin lasers</tag>
180
- # <tag>humidity</tag>
181
- # <tag>Temperature</tag>
182
- # <current_value at="2011-02-16T16:21:01.834174Z">14</current_value>
183
- # <max_value>658.0</max_value>
184
- # <min_value>0.0</min_value>
185
- # <unit type="derived SI" symbol="%">percentage</unit>
186
- # <datapoints>
187
- # <value at="2011-03-02T15:59:56.895922Z">1</value>
188
- # <value at="2011-03-02T16:00:07.188648Z">1</value>
189
- # <value at="2011-03-02T16:00:18.416500Z">2</value>
190
- # </datapoints>
191
- # </data>
192
- # </environment>
193
- # </eeml>
16
+ This gem will convert between Cosm Data Formats.
17
+ You can use it to prepare data for sending to Cosm or for parsing data received from Cosm.
194
18
 
195
-
@@ -17,12 +17,16 @@ 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
- s.add_dependency("yajl-ruby", ">=0.8.1")
20
+ if defined?(JRUBY_VERSION)
21
+ s.add_dependency("json_pure")
22
+ else
23
+ s.add_dependency("yajl-ruby", ">=0.8.1")
24
+ end
21
25
  s.add_dependency("nokogiri", ">=1.4.4")
22
26
  s.add_dependency("httparty", ">=0.8.3")
23
27
 
24
28
  begin
25
- if RUBY_VERSION < "1.9"
29
+ if RUBY_VERSION < "1.9" && !defined?(JRUBY_VERSION)
26
30
  s.add_development_dependency("ruby-debug")
27
31
  s.add_development_dependency("rcov", ">=0.9.9")
28
32
  end
@@ -1,5 +1,9 @@
1
1
  require 'nokogiri'
2
- require 'yajl/json_gem'
2
+ if defined?(JRUBY_VERSION)
3
+ require 'json/pure'
4
+ else
5
+ require 'yajl/json_gem'
6
+ end
3
7
  require 'csv'
4
8
 
5
9
  $:.unshift(File.dirname(File.expand_path(__FILE__)))
@@ -1,3 +1,3 @@
1
1
  module Cosm #:nodoc:
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
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
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Paul Bellamy
@@ -17,10 +17,12 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-05-21 00:00:00 +01:00
20
+ date: 2012-06-11 00:00:00 +01:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
+ prerelease: false
25
+ type: :runtime
24
26
  version_requirements: &id001 !ruby/object:Gem::Requirement
25
27
  none: false
26
28
  requirements:
@@ -32,11 +34,11 @@ dependencies:
32
34
  - 8
33
35
  - 1
34
36
  version: 0.8.1
35
- prerelease: false
36
- type: :runtime
37
37
  requirement: *id001
38
38
  name: yajl-ruby
39
39
  - !ruby/object:Gem::Dependency
40
+ prerelease: false
41
+ type: :runtime
40
42
  version_requirements: &id002 !ruby/object:Gem::Requirement
41
43
  none: false
42
44
  requirements:
@@ -48,11 +50,11 @@ dependencies:
48
50
  - 4
49
51
  - 4
50
52
  version: 1.4.4
51
- prerelease: false
52
- type: :runtime
53
53
  requirement: *id002
54
54
  name: nokogiri
55
55
  - !ruby/object:Gem::Dependency
56
+ prerelease: false
57
+ type: :runtime
56
58
  version_requirements: &id003 !ruby/object:Gem::Requirement
57
59
  none: false
58
60
  requirements:
@@ -64,11 +66,11 @@ dependencies:
64
66
  - 8
65
67
  - 3
66
68
  version: 0.8.3
67
- prerelease: false
68
- type: :runtime
69
69
  requirement: *id003
70
70
  name: httparty
71
71
  - !ruby/object:Gem::Dependency
72
+ prerelease: false
73
+ type: :development
72
74
  version_requirements: &id004 !ruby/object:Gem::Requirement
73
75
  none: false
74
76
  requirements:
@@ -78,11 +80,11 @@ dependencies:
78
80
  segments:
79
81
  - 0
80
82
  version: "0"
81
- prerelease: false
82
- type: :development
83
83
  requirement: *id004
84
84
  name: ruby-debug
85
85
  - !ruby/object:Gem::Dependency
86
+ prerelease: false
87
+ type: :development
86
88
  version_requirements: &id005 !ruby/object:Gem::Requirement
87
89
  none: false
88
90
  requirements:
@@ -94,11 +96,11 @@ dependencies:
94
96
  - 9
95
97
  - 9
96
98
  version: 0.9.9
97
- prerelease: false
98
- type: :development
99
99
  requirement: *id005
100
100
  name: rcov
101
101
  - !ruby/object:Gem::Dependency
102
+ prerelease: false
103
+ type: :development
102
104
  version_requirements: &id006 !ruby/object:Gem::Requirement
103
105
  none: false
104
106
  requirements:
@@ -110,11 +112,11 @@ dependencies:
110
112
  - 8
111
113
  - 7
112
114
  version: 0.8.7
113
- prerelease: false
114
- type: :development
115
115
  requirement: *id006
116
116
  name: rake
117
117
  - !ruby/object:Gem::Dependency
118
+ prerelease: false
119
+ type: :development
118
120
  version_requirements: &id007 !ruby/object:Gem::Requirement
119
121
  none: false
120
122
  requirements:
@@ -126,8 +128,6 @@ dependencies:
126
128
  - 6
127
129
  - 0
128
130
  version: 2.6.0
129
- prerelease: false
130
- type: :development
131
131
  requirement: *id007
132
132
  name: rspec
133
133
  description: A library for communicating with the Cosm REST API, parsing and rendering Cosm feed formats