amee 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +8 -1
- data/VERSION +1 -1
- data/amee.gemspec +7 -3
- data/lib/amee.rb +8 -5
- data/lib/amee/config.rb +37 -0
- data/lib/amee/core-extensions/hash.rb +43 -0
- data/spec/amee_config_spec.rb +46 -0
- data/spec/fixtures/rails_config.yml +13 -0
- metadata +45 -41
data/CHANGELOG.txt
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
= Changelog
|
2
2
|
|
3
|
+
== 4.1.0
|
4
|
+
* Add option to set connection details using environment variables, for
|
5
|
+
instance in Heroku deployments.
|
6
|
+
|
7
|
+
== 4.0.0
|
8
|
+
* Rails 3 support. Rails 2 apps will not work with this version.
|
9
|
+
|
3
10
|
== 3.0.0
|
4
11
|
* Add some pre-release functionality for AMEEconnect v3 in order to support
|
5
12
|
AMEEappkit gems.
|
@@ -43,4 +50,4 @@
|
|
43
50
|
* Include accessors from other objects
|
44
51
|
* Internal improvements including
|
45
52
|
* Improved paging support
|
46
|
-
* Tidier code for collections
|
53
|
+
* Tidier code for collections
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.
|
1
|
+
4.1.0
|
data/amee.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{amee}
|
8
|
-
s.version = "4.
|
8
|
+
s.version = "4.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["James Smith", "James Hetherington", "Andrew Hill", "Andrew Berkeley"]
|
12
|
-
s.date = %q{2011-09-
|
12
|
+
s.date = %q{2011-09-29}
|
13
13
|
s.default_executable = %q{ameesh}
|
14
14
|
s.email = %q{james@floppy.org.uk}
|
15
15
|
s.executables = ["ameesh"]
|
@@ -38,7 +38,9 @@ Gem::Specification.new do |s|
|
|
38
38
|
"examples/view_profile_item.rb",
|
39
39
|
"lib/amee.rb",
|
40
40
|
"lib/amee/collection.rb",
|
41
|
+
"lib/amee/config.rb",
|
41
42
|
"lib/amee/connection.rb",
|
43
|
+
"lib/amee/core-extensions/hash.rb",
|
42
44
|
"lib/amee/data_category.rb",
|
43
45
|
"lib/amee/data_item.rb",
|
44
46
|
"lib/amee/data_item_value.rb",
|
@@ -68,6 +70,7 @@ Gem::Specification.new do |s|
|
|
68
70
|
"lib/amee/v3/item_value_definition_list.rb",
|
69
71
|
"lib/amee/v3/meta_helper.rb",
|
70
72
|
"lib/amee/v3/return_value_definition.rb",
|
73
|
+
"spec/amee_config_spec.rb",
|
71
74
|
"spec/amee_spec.rb",
|
72
75
|
"spec/cache_spec.rb",
|
73
76
|
"spec/connection_spec.rb",
|
@@ -97,6 +100,7 @@ Gem::Specification.new do |s|
|
|
97
100
|
"spec/fixtures/ivdlist.xml",
|
98
101
|
"spec/fixtures/ivdlist_BD88D30D1214.xml",
|
99
102
|
"spec/fixtures/parse_test.xml",
|
103
|
+
"spec/fixtures/rails_config.yml",
|
100
104
|
"spec/fixtures/return_value_definition.xml",
|
101
105
|
"spec/fixtures/return_value_definition_list.xml",
|
102
106
|
"spec/fixtures/v0_data_transport_transport_drill_transportType_Car1.xml",
|
@@ -122,7 +126,7 @@ Gem::Specification.new do |s|
|
|
122
126
|
s.homepage = %q{http://github.com/AMEE/amee-ruby}
|
123
127
|
s.licenses = ["BSD 3-Clause"]
|
124
128
|
s.require_paths = ["lib"]
|
125
|
-
s.rubygems_version = %q{1.
|
129
|
+
s.rubygems_version = %q{1.6.2}
|
126
130
|
s.summary = %q{Ruby interface to the AMEE carbon calculator}
|
127
131
|
|
128
132
|
if s.respond_to? :specification_version then
|
data/lib/amee.rb
CHANGED
@@ -31,7 +31,7 @@ class String
|
|
31
31
|
is_xml? && (include?('<feed ') || include?('<entry ')) && include?('xmlns:amee="http://schemas.amee.cc/2.0"')
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
require 'amee/core-extensions/hash'
|
35
35
|
require 'amee/logger'
|
36
36
|
require 'amee/exceptions'
|
37
37
|
require 'amee/connection'
|
@@ -54,14 +54,17 @@ require 'amee/item_definition'
|
|
54
54
|
require 'amee/item_value_definition'
|
55
55
|
require 'amee/user'
|
56
56
|
require 'amee/v3'
|
57
|
+
require 'amee/config'
|
57
58
|
|
58
59
|
if defined?(Rails)
|
59
60
|
require 'amee/rails'
|
60
61
|
ActiveRecord::Base.send :include, AMEE::Rails
|
61
|
-
|
62
|
-
|
63
|
-
if File.exist?
|
64
|
-
$AMEE_CONFIG =
|
62
|
+
|
63
|
+
|
64
|
+
if File.exist? amee_config
|
65
|
+
$AMEE_CONFIG = AMEE::Config.setup(amee_config, Rails.env)
|
66
|
+
else
|
67
|
+
$AMEE_CONFIG = AMEE::Config.setup
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
data/lib/amee/config.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
|
2
|
+
# Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
|
3
|
+
|
4
|
+
module AMEE
|
5
|
+
|
6
|
+
class Config
|
7
|
+
|
8
|
+
|
9
|
+
# Tries to load defaults from a yaml file, then if there are environment variables
|
10
|
+
# present (i.e. if we're using a service like heroku for determine them, or we want to
|
11
|
+
# manually override them), uses those values instead
|
12
|
+
def self.setup(amee_config_file = nil, environment = 'test')
|
13
|
+
|
14
|
+
if amee_config_file
|
15
|
+
# first try loading the yaml file
|
16
|
+
yaml_config = YAML.load_file(amee_config_file)
|
17
|
+
config = yaml_config[environment]
|
18
|
+
|
19
|
+
# make config[:username] possible instead of just config['username']
|
20
|
+
config.recursive_symbolize_keys!
|
21
|
+
else
|
22
|
+
config = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
# then either override, or load in config deets from heroku
|
26
|
+
config[:username] = ENV['AMEE_USERNAME'] if ENV['AMEE_USERNAME']
|
27
|
+
config[:server] = ENV['AMEE_SERVER'] if ENV['AMEE_SERVER']
|
28
|
+
config[:password] = ENV['AMEE_PASSWORD'] if ENV['AMEE_PASSWORD']
|
29
|
+
|
30
|
+
return config
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Copyright (C) 2011 AMEE UK Ltd. - http://www.amee.com
|
2
|
+
# Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
|
3
|
+
|
4
|
+
# :title: Class: Hash
|
5
|
+
|
6
|
+
class Hash
|
7
|
+
|
8
|
+
# Return a new instance of <i>Hash</i> which represents the same data as
|
9
|
+
# <tt>self</tt> but with all keys - including those of sub-hashes - symbolized
|
10
|
+
#
|
11
|
+
def recursive_symbolize_keys
|
12
|
+
new_hash = {}
|
13
|
+
self.each_pair do |k,v|
|
14
|
+
new_hash[k.to_sym] = value_or_symbolize_value(v)
|
15
|
+
end
|
16
|
+
new_hash
|
17
|
+
end
|
18
|
+
|
19
|
+
# Modify <tt>self</tt> in place, transforming all keys - including those of
|
20
|
+
# sub-hashes - in to symbols
|
21
|
+
#
|
22
|
+
def recursive_symbolize_keys!
|
23
|
+
self.each_pair do |k,v|
|
24
|
+
value = delete(k)
|
25
|
+
self[k.to_sym] = value_or_symbolize_value(value)
|
26
|
+
end
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Symbolize any hash key or sub-hash key containing within <tt>value</tt>.
|
33
|
+
def value_or_symbolize_value(value)
|
34
|
+
if value.is_a? Hash
|
35
|
+
return value.recursive_symbolize_keys
|
36
|
+
elsif value.is_a? Array
|
37
|
+
return value.map { |elem| value_or_symbolize_value(elem) }
|
38
|
+
else
|
39
|
+
return value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
|
2
|
+
# Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
|
3
|
+
require 'spec_helper.rb'
|
4
|
+
|
5
|
+
describe AMEE::Config do
|
6
|
+
|
7
|
+
# make sure environment variables are clear for each test
|
8
|
+
before(:each) do
|
9
|
+
ENV['AMEE_SERVER'] = nil
|
10
|
+
ENV['AMEE_USERNAME'] = nil
|
11
|
+
ENV['AMEE_PASSWORD'] = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
context "loading config details from the environment"
|
15
|
+
|
16
|
+
it "should let us use ENV variables so we can use heroku" do
|
17
|
+
# fake the ENV variables setting
|
18
|
+
ENV['AMEE_SERVER'] = "stage.amee.com"
|
19
|
+
ENV['AMEE_USERNAME'] = "joe_shmoe"
|
20
|
+
ENV['AMEE_PASSWORD'] = "top_sekrit123"
|
21
|
+
|
22
|
+
amee_config = AMEE::Config.setup()
|
23
|
+
|
24
|
+
amee_config[:username].should eq "joe_shmoe"
|
25
|
+
amee_config[:server].should eq "stage.amee.com"
|
26
|
+
amee_config[:password].should eq "top_sekrit123"
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "loading config details from a yaml file" do
|
31
|
+
|
32
|
+
it "so we don't rely on heroku ALL the time" do
|
33
|
+
|
34
|
+
config_path = File.dirname(__FILE__)+'/fixtures/rails_config.yml'
|
35
|
+
|
36
|
+
amee_config = AMEE::Config.setup(config_path, 'test')
|
37
|
+
|
38
|
+
amee_config[:username].should eq "joe_shmoe"
|
39
|
+
amee_config[:server].should eq "stage.amee.com"
|
40
|
+
amee_config[:password].should eq "top_sekrit123"
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 59
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 4
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 4.0.0
|
10
|
+
version: 4.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Smith
|
@@ -18,14 +18,13 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2011-09-
|
21
|
+
date: 2011-09-29 00:00:00 +01:00
|
22
22
|
default_executable: ameesh
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
25
|
prerelease: false
|
26
|
-
name: activesupport
|
27
26
|
type: :runtime
|
28
|
-
|
27
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
30
|
- - ~>
|
@@ -36,12 +35,12 @@ dependencies:
|
|
36
35
|
- 0
|
37
36
|
- 10
|
38
37
|
version: 3.0.10
|
39
|
-
|
38
|
+
name: activesupport
|
39
|
+
version_requirements: *id001
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
prerelease: false
|
42
|
-
name: json
|
43
42
|
type: :runtime
|
44
|
-
|
43
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
45
44
|
none: false
|
46
45
|
requirements:
|
47
46
|
- - ">="
|
@@ -50,12 +49,12 @@ dependencies:
|
|
50
49
|
segments:
|
51
50
|
- 0
|
52
51
|
version: "0"
|
53
|
-
|
52
|
+
name: json
|
53
|
+
version_requirements: *id002
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
prerelease: false
|
56
|
-
name: log4r
|
57
56
|
type: :runtime
|
58
|
-
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
59
58
|
none: false
|
60
59
|
requirements:
|
61
60
|
- - ">="
|
@@ -64,12 +63,12 @@ dependencies:
|
|
64
63
|
segments:
|
65
64
|
- 0
|
66
65
|
version: "0"
|
67
|
-
|
66
|
+
name: log4r
|
67
|
+
version_requirements: *id003
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
69
|
prerelease: false
|
70
|
-
name: nokogiri
|
71
70
|
type: :runtime
|
72
|
-
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
72
|
none: false
|
74
73
|
requirements:
|
75
74
|
- - ~>
|
@@ -81,12 +80,12 @@ dependencies:
|
|
81
80
|
- 3
|
82
81
|
- 1
|
83
82
|
version: 1.4.3.1
|
84
|
-
|
83
|
+
name: nokogiri
|
84
|
+
version_requirements: *id004
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
prerelease: false
|
87
|
-
name: bundler
|
88
87
|
type: :development
|
89
|
-
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
90
89
|
none: false
|
91
90
|
requirements:
|
92
91
|
- - ~>
|
@@ -97,12 +96,12 @@ dependencies:
|
|
97
96
|
- 0
|
98
97
|
- 0
|
99
98
|
version: 1.0.0
|
100
|
-
|
99
|
+
name: bundler
|
100
|
+
version_requirements: *id005
|
101
101
|
- !ruby/object:Gem::Dependency
|
102
102
|
prerelease: false
|
103
|
-
name: jeweler
|
104
103
|
type: :development
|
105
|
-
|
104
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
106
105
|
none: false
|
107
106
|
requirements:
|
108
107
|
- - ~>
|
@@ -113,12 +112,12 @@ dependencies:
|
|
113
112
|
- 6
|
114
113
|
- 4
|
115
114
|
version: 1.6.4
|
116
|
-
|
115
|
+
name: jeweler
|
116
|
+
version_requirements: *id006
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
prerelease: false
|
119
|
-
name: rspec
|
120
119
|
type: :development
|
121
|
-
|
120
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
122
121
|
none: false
|
123
122
|
requirements:
|
124
123
|
- - "="
|
@@ -129,12 +128,12 @@ dependencies:
|
|
129
128
|
- 6
|
130
129
|
- 0
|
131
130
|
version: 2.6.0
|
132
|
-
|
131
|
+
name: rspec
|
132
|
+
version_requirements: *id007
|
133
133
|
- !ruby/object:Gem::Dependency
|
134
134
|
prerelease: false
|
135
|
-
name: flexmock
|
136
135
|
type: :development
|
137
|
-
|
136
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
138
137
|
none: false
|
139
138
|
requirements:
|
140
139
|
- - ">"
|
@@ -145,12 +144,12 @@ dependencies:
|
|
145
144
|
- 8
|
146
145
|
- 6
|
147
146
|
version: 0.8.6
|
148
|
-
|
147
|
+
name: flexmock
|
148
|
+
version_requirements: *id008
|
149
149
|
- !ruby/object:Gem::Dependency
|
150
150
|
prerelease: false
|
151
|
-
name: memcache-client
|
152
151
|
type: :development
|
153
|
-
|
152
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
154
153
|
none: false
|
155
154
|
requirements:
|
156
155
|
- - ">="
|
@@ -159,12 +158,12 @@ dependencies:
|
|
159
158
|
segments:
|
160
159
|
- 0
|
161
160
|
version: "0"
|
162
|
-
|
161
|
+
name: memcache-client
|
162
|
+
version_requirements: *id009
|
163
163
|
- !ruby/object:Gem::Dependency
|
164
164
|
prerelease: false
|
165
|
-
name: rcov
|
166
165
|
type: :development
|
167
|
-
|
166
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
168
167
|
none: false
|
169
168
|
requirements:
|
170
169
|
- - ">="
|
@@ -173,12 +172,12 @@ dependencies:
|
|
173
172
|
segments:
|
174
173
|
- 0
|
175
174
|
version: "0"
|
176
|
-
|
175
|
+
name: rcov
|
176
|
+
version_requirements: *id010
|
177
177
|
- !ruby/object:Gem::Dependency
|
178
178
|
prerelease: false
|
179
|
-
name: rdoc
|
180
179
|
type: :development
|
181
|
-
|
180
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
182
181
|
none: false
|
183
182
|
requirements:
|
184
183
|
- - ">="
|
@@ -187,12 +186,12 @@ dependencies:
|
|
187
186
|
segments:
|
188
187
|
- 0
|
189
188
|
version: "0"
|
190
|
-
|
189
|
+
name: rdoc
|
190
|
+
version_requirements: *id011
|
191
191
|
- !ruby/object:Gem::Dependency
|
192
192
|
prerelease: false
|
193
|
-
name: activerecord
|
194
193
|
type: :development
|
195
|
-
|
194
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
196
195
|
none: false
|
197
196
|
requirements:
|
198
197
|
- - ~>
|
@@ -203,7 +202,8 @@ dependencies:
|
|
203
202
|
- 0
|
204
203
|
- 10
|
205
204
|
version: 3.0.10
|
206
|
-
|
205
|
+
name: activerecord
|
206
|
+
version_requirements: *id012
|
207
207
|
description:
|
208
208
|
email: james@floppy.org.uk
|
209
209
|
executables:
|
@@ -234,7 +234,9 @@ files:
|
|
234
234
|
- examples/view_profile_item.rb
|
235
235
|
- lib/amee.rb
|
236
236
|
- lib/amee/collection.rb
|
237
|
+
- lib/amee/config.rb
|
237
238
|
- lib/amee/connection.rb
|
239
|
+
- lib/amee/core-extensions/hash.rb
|
238
240
|
- lib/amee/data_category.rb
|
239
241
|
- lib/amee/data_item.rb
|
240
242
|
- lib/amee/data_item_value.rb
|
@@ -264,6 +266,7 @@ files:
|
|
264
266
|
- lib/amee/v3/item_value_definition_list.rb
|
265
267
|
- lib/amee/v3/meta_helper.rb
|
266
268
|
- lib/amee/v3/return_value_definition.rb
|
269
|
+
- spec/amee_config_spec.rb
|
267
270
|
- spec/amee_spec.rb
|
268
271
|
- spec/cache_spec.rb
|
269
272
|
- spec/connection_spec.rb
|
@@ -293,6 +296,7 @@ files:
|
|
293
296
|
- spec/fixtures/ivdlist.xml
|
294
297
|
- spec/fixtures/ivdlist_BD88D30D1214.xml
|
295
298
|
- spec/fixtures/parse_test.xml
|
299
|
+
- spec/fixtures/rails_config.yml
|
296
300
|
- spec/fixtures/return_value_definition.xml
|
297
301
|
- spec/fixtures/return_value_definition_list.xml
|
298
302
|
- spec/fixtures/v0_data_transport_transport_drill_transportType_Car1.xml
|
@@ -344,7 +348,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
344
348
|
requirements: []
|
345
349
|
|
346
350
|
rubyforge_project:
|
347
|
-
rubygems_version: 1.
|
351
|
+
rubygems_version: 1.6.2
|
348
352
|
signing_key:
|
349
353
|
specification_version: 3
|
350
354
|
summary: Ruby interface to the AMEE carbon calculator
|