amee 3.1.2 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +3 -0
- data/VERSION +1 -1
- data/amee.gemspec +2 -2
- data/lib/amee/v3/connection.rb +5 -0
- data/lib/amee/v3/item_definition.rb +10 -4
- data/lib/amee/v3/item_value_definition.rb +2 -2
- data/lib/amee/v3/item_value_definition_list.rb +1 -1
- data/lib/amee/v3/return_value_definition.rb +4 -4
- data/lib/amee/v3.rb +0 -2
- data/spec/data_category_spec.rb +1 -1
- data/spec/fixtures/itemdef.xml +6 -1
- data/spec/fixtures/itemdef_441BF4BEA15B.xml +20 -12
- data/spec/item_definition_spec.rb +4 -4
- data/spec/item_value_definition_spec.rb +8 -8
- data/spec/v3/connection_spec.rb +10 -10
- data/spec/v3/item_definition_spec.rb +12 -10
- data/spec/v3/item_value_definition_spec.rb +5 -5
- data/spec/v3/return_value_definition_spec.rb +8 -8
- metadata +15 -15
data/CHANGELOG.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.2.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 = "3.
|
8
|
+
s.version = "3.2.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-10
|
12
|
+
s.date = %q{2011-11-10}
|
13
13
|
s.default_executable = %q{ameesh}
|
14
14
|
s.email = %q{james@floppy.org.uk}
|
15
15
|
s.executables = ["ameesh"]
|
data/lib/amee/v3/connection.rb
CHANGED
@@ -9,11 +9,12 @@ module AMEE
|
|
9
9
|
|
10
10
|
def initialize_with_v3(data = {})
|
11
11
|
@usages = data[:usages] || []
|
12
|
+
@algorithms = data[:algorithms] || {}
|
12
13
|
initialize_without_v3(data)
|
13
14
|
end
|
14
15
|
alias_method_chain :initialize, :v3
|
15
16
|
|
16
|
-
attr_accessor :usages
|
17
|
+
attr_accessor :usages, :algorithms
|
17
18
|
|
18
19
|
def self.metaxmlpathpreamble
|
19
20
|
'/Representation/ItemDefinition/'
|
@@ -25,7 +26,7 @@ module AMEE
|
|
25
26
|
|
26
27
|
def self.v3_get(connection, uid, options={})
|
27
28
|
# Load data from path
|
28
|
-
response = connection.v3_get("/#{
|
29
|
+
response = connection.v3_get("/#{AMEE::Connection.api_version}/definitions/#{uid};full", options)
|
29
30
|
# Parse response
|
30
31
|
item_definition = ItemDefinition.parse(connection, response, false)
|
31
32
|
# Done
|
@@ -45,6 +46,11 @@ module AMEE
|
|
45
46
|
data[:name] = x 'Name', :doc => doc, :meta => true
|
46
47
|
data[:drillDown] = x('DrillDown', :doc => doc, :meta => true).split(",") rescue nil
|
47
48
|
data[:usages] = [(x 'Usages/Usage/Name', :doc => doc, :meta => true)].flatten.delete_if{|x| x.nil?}
|
49
|
+
data[:algorithms] = begin
|
50
|
+
names = [(x 'Algorithms/Algorithm/Name', :doc => doc, :meta => true)].flatten.delete_if{|x| x.nil?}
|
51
|
+
uids = [(x 'Algorithms/Algorithm/@uid', :doc => doc, :meta => true)].flatten.delete_if{|x| x.nil?}
|
52
|
+
Hash[names.zip(uids)]
|
53
|
+
end
|
48
54
|
# Create object
|
49
55
|
ItemDefinition.new(data)
|
50
56
|
rescue
|
@@ -59,11 +65,11 @@ module AMEE
|
|
59
65
|
:usages => @usages.join(','),
|
60
66
|
:name => @name
|
61
67
|
}
|
62
|
-
@connection.v3_put("/#{
|
68
|
+
@connection.v3_put("/#{AMEE::Connection.api_version}/definitions/#{@uid}",save_options)
|
63
69
|
end
|
64
70
|
|
65
71
|
def expire_cache_with_v3
|
66
|
-
@connection.expire_matching("/#{
|
72
|
+
@connection.expire_matching("/#{AMEE::Connection.api_version}/definitions/#{@uid}.*")
|
67
73
|
expire_cache_without_v3
|
68
74
|
end
|
69
75
|
alias_method_chain :expire_cache, :v3
|
@@ -13,7 +13,7 @@ module AMEE
|
|
13
13
|
alias_method_chain :initialize, :v3
|
14
14
|
|
15
15
|
def metapath
|
16
|
-
"/#{
|
16
|
+
"/#{AMEE::Connection.api_version}/definitions/#{itemdefuid}/values/#{uid};wikiDoc;usages"
|
17
17
|
end
|
18
18
|
def metaxmlpathpreamble
|
19
19
|
'/Representation/ItemValueDefinition/'
|
@@ -89,7 +89,7 @@ EOF
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def expire_cache_with_v3
|
92
|
-
@connection.expire_matching("/#{
|
92
|
+
@connection.expire_matching("/#{AMEE::Connection.api_version}/definitions/#{itemdefuid}/values/#{uid}.*")
|
93
93
|
expire_cache_without_v3
|
94
94
|
end
|
95
95
|
alias_method_chain :expire_cache, :v3
|
@@ -15,7 +15,7 @@ module AMEE
|
|
15
15
|
ReturnValueDefinition
|
16
16
|
end
|
17
17
|
def collectionpath
|
18
|
-
"/#{
|
18
|
+
"/#{AMEE::Connection.api_version}/definitions/#{@uid}/returnvalues;full"
|
19
19
|
end
|
20
20
|
|
21
21
|
def jsoncollector
|
@@ -138,7 +138,7 @@ module AMEE
|
|
138
138
|
|
139
139
|
|
140
140
|
def self.load(connection,itemdefuid,ivduid,options={})
|
141
|
-
ReturnValueDefinition.get(connection,"/#{
|
141
|
+
ReturnValueDefinition.get(connection,"/#{AMEE::Connection.api_version}/definitions/#{itemdefuid}/returnvalues/#{ivduid};full",options)
|
142
142
|
end
|
143
143
|
|
144
144
|
def reload(connection)
|
@@ -178,7 +178,7 @@ module AMEE
|
|
178
178
|
end
|
179
179
|
|
180
180
|
options.merge!(:returnobj=>true)
|
181
|
-
response = connection.v3_post("/#{
|
181
|
+
response = connection.v3_post("/#{AMEE::Connection.api_version}/definitions/#{itemdefuid}/returnvalues", options)
|
182
182
|
return ReturnValueDefinition.load(connection,itemdefuid , response['Location'].split('/')[7])
|
183
183
|
rescue
|
184
184
|
raise AMEE::BadData.new("Couldn't create ReturnValueDefinition. Check that your information is correct.\n#{response}")
|
@@ -189,7 +189,7 @@ module AMEE
|
|
189
189
|
# Deleting takes a while... up the timeout to 120 seconds temporarily
|
190
190
|
t = connection.timeout
|
191
191
|
connection.timeout = 120
|
192
|
-
connection.v3_delete("/#{
|
192
|
+
connection.v3_delete("/#{AMEE::Connection.api_version}/definitions/#{itemdefuid}/returnvalues/" + return_value_definition.uid)
|
193
193
|
connection.timeout = t
|
194
194
|
rescue
|
195
195
|
raise AMEE::BadData.new("Couldn't delete ReturnValueDefinition. Check that your information is correct.")
|
data/lib/amee/v3.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
|
2
2
|
# Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
|
3
3
|
|
4
|
-
AMEE_API_VERSION = '3.3'
|
5
|
-
|
6
4
|
require 'amee/v3/meta_helper'
|
7
5
|
require 'amee/v3/collection'
|
8
6
|
require 'amee/v3/connection'
|
data/spec/data_category_spec.rb
CHANGED
@@ -127,7 +127,7 @@ describe AMEE::Data::Category, "with an authenticated XML connection" do
|
|
127
127
|
connection = flexmock "connection"
|
128
128
|
connection.should_receive(:retries).and_return(0)
|
129
129
|
connection.should_receive(:get).with("/data/transport/plane/generic", {:itemsPerPage => 10}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><DataCategoryResource><Path>/transport/plane/generic</Path><DataCategory created="2007-08-01 09:00:23.0" modified="2007-08-01 09:00:23.0" uid="FBA97B70DBDF"><Name>Generic</Name><Path>generic</Path><Environment uid="5F5887BCF726"/><DataCategory uid="6F3692D81CD9"><Name>Plane</Name><Path>plane</Path></DataCategory><ItemDefinition uid="441BF4BEA15B"/></DataCategory><Children><DataCategories/><DataItems><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="AD63A83B4D41"><kgCO2PerPassengerJourney>0</kgCO2PerPassengerJourney><type>domestic</type><label>domestic</label><size>-</size><path>AD63A83B4D41</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0.158</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="FFC7A05D54AD"><kgCO2PerPassengerJourney>73</kgCO2PerPassengerJourney><type>domestic</type><label>domestic, one way</label><size>one way</size><path>FFC7A05D54AD</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="F5498AD6FC75"><kgCO2PerPassengerJourney>146</kgCO2PerPassengerJourney><type>domestic</type><label>domestic, return</label><size>return</size><path>F5498AD6FC75</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="7D4220DF72F9"><kgCO2PerPassengerJourney>0</kgCO2PerPassengerJourney><type>long haul</type><label>long haul</label><size>-</size><path>7D4220DF72F9</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0.105</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="46117F6C0B7E"><kgCO2PerPassengerJourney>801</kgCO2PerPassengerJourney><type>long haul</type><label>long haul, one way</label><size>one way</size><path>46117F6C0B7E</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="96D538B1B246"><kgCO2PerPassengerJourney>1602</kgCO2PerPassengerJourney><type>long haul</type><label>long haul, return</label><size>return</size><path>96D538B1B246</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="9DA419052FDF"><kgCO2PerPassengerJourney>0</kgCO2PerPassengerJourney><type>short haul</type><label>short haul</label><size>-</size><path>9DA419052FDF</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0.13</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="84B4A14C7424"><kgCO2PerPassengerJourney>170</kgCO2PerPassengerJourney><type>short haul</type><label>short haul, one way</label><size>one way</size><path>84B4A14C7424</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="8DA1BEAA1013"><kgCO2PerPassengerJourney>340</kgCO2PerPassengerJourney><type>short haul</type><label>short haul, return</label><size>return</size><path>8DA1BEAA1013</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0</kgCO2PerPassengerKm></DataItem></DataItems><Pager><Start>0</Start><From>1</From><To>9</To><Items>9</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>9</ItemsFound></Pager></Children></DataCategoryResource></Resources>'))
|
130
|
-
connection.should_receive(:v3_get).with("
|
130
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/441BF4BEA15B;full",{}).and_return(fixture('itemdef_441BF4BEA15B.xml')).once
|
131
131
|
@data = AMEE::Data::Category.get(connection, "/data/transport/plane/generic")
|
132
132
|
@data.uid.should == "FBA97B70DBDF"
|
133
133
|
@data.itemdef.should == "441BF4BEA15B"
|
data/spec/fixtures/itemdef.xml
CHANGED
@@ -14,7 +14,12 @@
|
|
14
14
|
<Name>usageOther</Name>
|
15
15
|
</Usage>
|
16
16
|
</Usages>
|
17
|
+
<Algorithms>
|
18
|
+
<Algorithm uid="D4E4779CA7AB">
|
19
|
+
<Name>default</Name>
|
20
|
+
</Algorithm>
|
21
|
+
</Algorithms>
|
17
22
|
</ItemDefinition>
|
18
23
|
<Status>OK</Status>
|
19
|
-
<Version>3.
|
24
|
+
<Version>3.6.0</Version>
|
20
25
|
</Representation>
|
@@ -1,14 +1,22 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
2
|
<Representation>
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
</
|
3
|
+
<ItemDefinition created="2007-07-27T07:30:44Z" modified="2011-08-17T08:09:06Z" status="ACTIVE" uid="441BF4BEA15B">
|
4
|
+
<Name>Plane Generic</Name>
|
5
|
+
<DrillDown>type,size</DrillDown>
|
6
|
+
<Usages>
|
7
|
+
<Usage present="true">
|
8
|
+
<Name>default</Name>
|
9
|
+
</Usage>
|
10
|
+
</Usages>
|
11
|
+
<Algorithms>
|
12
|
+
<Algorithm uid="EC4B78451B43">
|
13
|
+
<Name>default</Name>
|
14
|
+
</Algorithm>
|
15
|
+
<Algorithm uid="595AF9E4E1E5">
|
16
|
+
<Name>perMonth</Name>
|
17
|
+
</Algorithm>
|
18
|
+
</Algorithms>
|
19
|
+
</ItemDefinition>
|
20
|
+
<Status>OK</Status>
|
21
|
+
<Version>3.6.0</Version>
|
22
|
+
</Representation>
|
@@ -35,7 +35,7 @@ describe AMEE::Admin::ItemDefinition, "with an authenticated connection" do
|
|
35
35
|
|
36
36
|
it "should parse XML correctly" do
|
37
37
|
connection = flexmock "connection"
|
38
|
-
connection.should_receive(:v3_get).with("
|
38
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/BD88D30D1214;full", {}).and_return(fixture('BD88D30D1214.xml'))
|
39
39
|
@data = AMEE::Admin::ItemDefinition.load(connection,"BD88D30D1214")
|
40
40
|
@data.uid.should == "BD88D30D1214"
|
41
41
|
@data.created.should == DateTime.new(2007,7,27,7,30,44)
|
@@ -47,7 +47,7 @@ describe AMEE::Admin::ItemDefinition, "with an authenticated connection" do
|
|
47
47
|
|
48
48
|
it "should parse JSON correctly" do
|
49
49
|
connection = flexmock "connection"
|
50
|
-
connection.should_receive(:v3_get).with("
|
50
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/BD88D30D1214;full", {}).and_return(fixture('BD88D30D1214.xml'))
|
51
51
|
@data = AMEE::Admin::ItemDefinition.load(connection,"BD88D30D1214")
|
52
52
|
@data.uid.should == "BD88D30D1214"
|
53
53
|
@data.created.should == DateTime.new(2007,7,27,7,30,44)
|
@@ -59,9 +59,9 @@ describe AMEE::Admin::ItemDefinition, "with an authenticated connection" do
|
|
59
59
|
|
60
60
|
it "should be able to load an item value definition list" do
|
61
61
|
connection = flexmock "connection"
|
62
|
-
connection.should_receive(:v3_get).with("
|
62
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/BD88D30D1214;full", {}).and_return(fixture('BD88D30D1214.xml'))
|
63
63
|
connection.should_receive(:retries).and_return(0).once
|
64
|
-
connection.should_receive(:v3_get).with("
|
64
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_return(fixture('ivdlist_BD88D30D1214.xml')).once
|
65
65
|
@data = AMEE::Admin::ItemDefinition.load(connection,"BD88D30D1214")
|
66
66
|
@data.uid.should == "BD88D30D1214"
|
67
67
|
@list=@data.item_value_definition_list
|
@@ -35,7 +35,7 @@ describe AMEE::Admin::ItemValueDefinitionList, "with an authenticated connection
|
|
35
35
|
it "should parse XML correctly" do
|
36
36
|
connection = flexmock "connection"
|
37
37
|
connection.should_receive(:retries).and_return(0).once
|
38
|
-
connection.should_receive(:v3_get).with("
|
38
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_return(fixture('ivdlist_BD88D30D1214.xml')).once
|
39
39
|
@data = AMEE::Admin::ItemValueDefinitionList.new(connection,"BD88D30D1214")
|
40
40
|
@data.length.should==15
|
41
41
|
@data.first.uid.should=='9813267B616E'
|
@@ -51,7 +51,7 @@ describe AMEE::Admin::ItemValueDefinitionList, "with an authenticated connection
|
|
51
51
|
it "should apply block filter correctly" do
|
52
52
|
connection = flexmock "connection"
|
53
53
|
connection.should_receive(:retries).and_return(0).once
|
54
|
-
connection.should_receive(:v3_get).with("
|
54
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_return(fixture('ivdlist_BD88D30D1214.xml')).once
|
55
55
|
@data = AMEE::Admin::ItemValueDefinitionList.new(connection,"BD88D30D1214") do |x|
|
56
56
|
x.uid == 'A8A212610A57' ? x : nil
|
57
57
|
end
|
@@ -69,7 +69,7 @@ describe AMEE::Admin::ItemValueDefinitionList, "with an authenticated connection
|
|
69
69
|
it "should parse JSON correctly" do
|
70
70
|
connection = flexmock "connection"
|
71
71
|
connection.should_receive(:retries).and_return(0).once
|
72
|
-
connection.should_receive(:v3_get).with("
|
72
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_return(fixture('ivdlist_BD88D30D1214.xml')).once
|
73
73
|
@data = AMEE::Admin::ItemValueDefinitionList.new(connection,"BD88D30D1214")
|
74
74
|
@data.length.should==15
|
75
75
|
@data.first.uid.should=='9813267B616E'
|
@@ -86,8 +86,8 @@ describe AMEE::Admin::ItemValueDefinitionList, "with an authenticated connection
|
|
86
86
|
connection = flexmock "connection"
|
87
87
|
connection.should_receive(:retries).and_return(0).once
|
88
88
|
xml = '<?xml version="1.0" encoding="UTF-8"?><Resources></Resources>'
|
89
|
-
connection.should_receive(:v3_get).with("
|
90
|
-
connection.should_receive(:expire).with("
|
89
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_return(xml)
|
90
|
+
connection.should_receive(:expire).with("/#{AMEE::Connection.api_version}/definitions/BD88D30D1214/values;full").once
|
91
91
|
lambda{AMEE::Admin::ItemValueDefinitionList.new(connection, "BD88D30D1214")}.should raise_error(AMEE::BadData)
|
92
92
|
end
|
93
93
|
|
@@ -95,15 +95,15 @@ describe AMEE::Admin::ItemValueDefinitionList, "with an authenticated connection
|
|
95
95
|
connection = flexmock "connection"
|
96
96
|
connection.should_receive(:retries).and_return(0).once
|
97
97
|
json = '{}'
|
98
|
-
connection.should_receive(:v3_get).with("
|
99
|
-
connection.should_receive(:expire).with("
|
98
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_return(json)
|
99
|
+
connection.should_receive(:expire).with("/#{AMEE::Connection.api_version}/definitions/BD88D30D1214/values;full").once
|
100
100
|
lambda{AMEE::Admin::ItemValueDefinitionList.new(connection, "BD88D30D1214")}.should raise_error(AMEE::BadData)
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should fail gracefully on other errors" do
|
104
104
|
connection = flexmock "connection"
|
105
105
|
connection.should_receive(:retries).and_return(0).once
|
106
|
-
connection.should_receive(:v3_get).with("
|
106
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_raise(Timeout::Error)
|
107
107
|
lambda{AMEE::Admin::ItemValueDefinitionList.new(connection, "BD88D30D1214")}.should raise_error(Timeout::Error)
|
108
108
|
end
|
109
109
|
end
|
data/spec/v3/connection_spec.rb
CHANGED
@@ -26,7 +26,7 @@ describe AMEE::Connection do
|
|
26
26
|
mock.should_receive(:finish => nil)
|
27
27
|
mock
|
28
28
|
}
|
29
|
-
@c.v3_get("/#{
|
29
|
+
@c.v3_get("/#{AMEE::Connection.api_version}/categories/SomeCategory").should == "OK"
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should be able to get from meta server" do
|
@@ -35,7 +35,7 @@ describe AMEE::Connection do
|
|
35
35
|
mock.should_receive(:request).and_return(flexmock(:code => '200', :body => "OK"))
|
36
36
|
mock.should_receive(:finish => nil)
|
37
37
|
end
|
38
|
-
@c.v3_get("/#{
|
38
|
+
@c.v3_get("/#{AMEE::Connection.api_version}/categories/SomeCategory").should == "OK"
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should be able to handle failed gets from meta server" do
|
@@ -45,8 +45,8 @@ describe AMEE::Connection do
|
|
45
45
|
mock.should_receive(:finish => nil)
|
46
46
|
end
|
47
47
|
lambda {
|
48
|
-
@c.v3_get("/#{
|
49
|
-
}.should raise_error(AMEE::NotFound, "The URL was not found on the server.\nRequest: GET /#{
|
48
|
+
@c.v3_get("/#{AMEE::Connection.api_version}/categories/SomeCategory").should == nil
|
49
|
+
}.should raise_error(AMEE::NotFound, "The URL was not found on the server.\nRequest: GET /#{AMEE::Connection.api_version}/categories/SomeCategory")
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should be able to post to meta server" do
|
@@ -55,7 +55,7 @@ describe AMEE::Connection do
|
|
55
55
|
mock.should_receive(:request).and_return(flexmock(:code => '200', :body => "OK"))
|
56
56
|
mock.should_receive(:finish => nil)
|
57
57
|
end
|
58
|
-
@c.v3_put("/#{
|
58
|
+
@c.v3_put("/#{AMEE::Connection.api_version}/categories/SomeCategory", {:arg => "test"}).should == "OK"
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should be able to handle failed gets from meta server" do
|
@@ -65,7 +65,7 @@ describe AMEE::Connection do
|
|
65
65
|
mock.should_receive(:finish => nil)
|
66
66
|
end
|
67
67
|
lambda {
|
68
|
-
@c.v3_put("/#{
|
68
|
+
@c.v3_put("/#{AMEE::Connection.api_version}/categories/SomeCategory", {:arg => "test"}).should == "OK"
|
69
69
|
}.should raise_error
|
70
70
|
end
|
71
71
|
|
@@ -120,7 +120,7 @@ describe AMEE::Connection, "with retry enabled" do
|
|
120
120
|
mock.should_receive(:finish => nil)
|
121
121
|
end
|
122
122
|
lambda {
|
123
|
-
@c.v3_get("/#{
|
123
|
+
@c.v3_get("/#{AMEE::Connection.api_version}/categories/SomeCategory")
|
124
124
|
}.should_not raise_error
|
125
125
|
end
|
126
126
|
|
@@ -131,7 +131,7 @@ describe AMEE::Connection, "with retry enabled" do
|
|
131
131
|
mock.should_receive(:finish => nil)
|
132
132
|
end
|
133
133
|
lambda {
|
134
|
-
@c.v3_get("/#{
|
134
|
+
@c.v3_get("/#{AMEE::Connection.api_version}/categories/SomeCategory")
|
135
135
|
}.should raise_error(e)
|
136
136
|
end
|
137
137
|
end
|
@@ -150,7 +150,7 @@ describe AMEE::Connection, "with retry enabled" do
|
|
150
150
|
mock.should_receive(:finish => nil)
|
151
151
|
end
|
152
152
|
lambda {
|
153
|
-
@c.v3_get("/#{
|
153
|
+
@c.v3_get("/#{AMEE::Connection.api_version}/categories/SomeCategory")
|
154
154
|
}.should_not raise_error
|
155
155
|
end
|
156
156
|
|
@@ -161,7 +161,7 @@ describe AMEE::Connection, "with retry enabled" do
|
|
161
161
|
mock.should_receive(:finish => nil)
|
162
162
|
end
|
163
163
|
lambda {
|
164
|
-
@c.v3_get("/#{
|
164
|
+
@c.v3_get("/#{AMEE::Connection.api_version}/categories/SomeCategory")
|
165
165
|
}.should raise_error(AMEE::ConnectionFailed)
|
166
166
|
end
|
167
167
|
end
|
@@ -19,7 +19,7 @@ describe AMEE::Admin::ItemDefinition, "with an authenticated v3 connection" do
|
|
19
19
|
|
20
20
|
it "should parse XML correctly" do
|
21
21
|
connection = flexmock "connection"
|
22
|
-
connection.should_receive(:v3_get).with("/#{
|
22
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef.xml'))
|
23
23
|
@data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E")
|
24
24
|
@data.uid.should == "472D78F6584E"
|
25
25
|
@data.created.should == DateTime.new(2009,8,31,12,41,18)
|
@@ -27,27 +27,29 @@ describe AMEE::Admin::ItemDefinition, "with an authenticated v3 connection" do
|
|
27
27
|
@data.name.should == "Power Stations And Stuff"
|
28
28
|
@data.drill_downs.should == %w{state county metroArea city zipCode plantName powWowWow}
|
29
29
|
@data.usages.should == ['usageOne', 'usageThree', 'usageOther']
|
30
|
+
@data.algorithms['default'].should eql "D4E4779CA7AB"
|
30
31
|
end
|
31
32
|
|
32
|
-
it "should parse XML correctly if there are no usages" do
|
33
|
+
it "should parse XML correctly if there are no usages or algorithms" do
|
33
34
|
connection = flexmock "connection"
|
34
|
-
connection.should_receive(:v3_get).with("/#{
|
35
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef_no_usages.xml'))
|
35
36
|
@data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E")
|
36
37
|
@data.usages.should == []
|
38
|
+
@data.algorithms.should == {}
|
37
39
|
end
|
38
40
|
|
39
41
|
it "should parse XML correctly if there is just one usage" do
|
40
42
|
connection = flexmock "connection"
|
41
|
-
connection.should_receive(:v3_get).with("/#{
|
43
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef_one_usage.xml'))
|
42
44
|
@data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E")
|
43
45
|
@data.usages.should == ['usageOne']
|
44
46
|
end
|
45
47
|
|
46
48
|
it "should be able to load an item value definition list" do
|
47
49
|
connection = flexmock "connection"
|
48
|
-
connection.should_receive(:v3_get).with("/#{
|
50
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef.xml')).once
|
49
51
|
connection.should_receive(:retries).and_return(0).once
|
50
|
-
connection.should_receive(:v3_get).with("/#{
|
52
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E/values;full", {:resultStart => 0, :resultLimit => 10}).and_return(fixture('ivdlist.xml')).once
|
51
53
|
@data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E")
|
52
54
|
@data.uid.should == "472D78F6584E"
|
53
55
|
@list=@data.item_value_definition_list
|
@@ -77,20 +79,20 @@ describe AMEE::Admin::ItemDefinition, "with an authenticated v3 connection" do
|
|
77
79
|
it "should fail gracefully with incorrect data" do
|
78
80
|
connection = flexmock "connection"
|
79
81
|
xml = '<?xml version="1.0" encoding="UTF-8"?><Resources>'
|
80
|
-
connection.should_receive(:v3_get).with("/#{
|
82
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_return(xml)
|
81
83
|
lambda{AMEE::Admin::ItemDefinition.load(connection, "472D78F6584E")}.should raise_error(AMEE::BadData)
|
82
84
|
end
|
83
85
|
|
84
86
|
it "should fail gracefully on other errors" do
|
85
87
|
connection = flexmock "connection"
|
86
|
-
connection.should_receive(:v3_get).with("/#{
|
88
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_raise("unidentified error")
|
87
89
|
lambda{AMEE::Admin::ItemDefinition.load(connection, "472D78F6584E")}.should raise_error(AMEE::BadData)
|
88
90
|
end
|
89
91
|
|
90
92
|
it "should support updating" do
|
91
93
|
connection = flexmock "connection"
|
92
|
-
connection.should_receive(:v3_get).with("/#{
|
93
|
-
connection.should_receive(:v3_put).with("/#{
|
94
|
+
connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_return('<?xml version="1.0" encoding="UTF-8" standalone="no"?><Representation><ItemDefinition created="2009-08-31T12:41:18Z" modified="2010-08-13T14:54:33Z" status="ACTIVE" uid="472D78F6584E"><Name>Power Stations And Stuff</Name><DrillDown>state,county,metroArea,city,zipCode,plantName,powWowWow</DrillDown><Usages><Usage present="true"><Name>usageOne</Name></Usage><Usage present="true"><Name>usageThree</Name></Usage><Usage present="false"><Name>usageOther</Name></Usage></Usages></ItemDefinition><Status>OK</Status><Version>#{AMEE::Connection.api_version}.0</Version></Representation>').once
|
95
|
+
connection.should_receive(:v3_put).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E", :usages => 'usageOther,usageThree,usageOne', :name => 'Power Stations And Stuff').once
|
94
96
|
@data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E")
|
95
97
|
@data.usages.should == ['usageOne', 'usageThree', 'usageOther']
|
96
98
|
@data.usages.reverse!
|
@@ -12,14 +12,14 @@ describe AMEE::Admin::ItemValueDefinition, "with an authenticated XML connection
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should set metadata" do
|
15
|
-
@connection.should_receive(:v3_get).with("/#{
|
15
|
+
@connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/PQR/values/ABC;wikiDoc;usages").
|
16
16
|
and_return(<<HERE
|
17
17
|
#{XMLPreamble}
|
18
18
|
<Representation>
|
19
19
|
</Representation>
|
20
20
|
HERE
|
21
21
|
).once
|
22
|
-
@connection.should_receive(:v3_put).with("/#{
|
22
|
+
@connection.should_receive(:v3_put).with("/#{AMEE::Connection.api_version}/definitions/PQR/values/ABC;wikiDoc;usages",
|
23
23
|
:body => <<EOF
|
24
24
|
#{XMLPreamble}
|
25
25
|
<ItemValueDefinition>
|
@@ -37,7 +37,7 @@ HERE
|
|
37
37
|
</ItemValueDefinition>
|
38
38
|
EOF
|
39
39
|
).once
|
40
|
-
@connection.should_receive(:v3_get).with("/#{
|
40
|
+
@connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/PQR/values/ABC;wikiDoc;usages").
|
41
41
|
and_return(<<HERE
|
42
42
|
#{XMLPreamble}
|
43
43
|
<Representation>
|
@@ -51,7 +51,7 @@ HERE
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should get metadata" do
|
54
|
-
@connection.should_receive(:v3_get).with("/#{
|
54
|
+
@connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/PQR/values/ABC;wikiDoc;usages").
|
55
55
|
and_return(<<HERE
|
56
56
|
#{XMLPreamble}
|
57
57
|
<Representation>
|
@@ -87,7 +87,7 @@ HERE
|
|
87
87
|
<FromProfile>false</FromProfile>
|
88
88
|
</ItemValueDefinition>
|
89
89
|
<Status>OK</Status>
|
90
|
-
<Version>#{
|
90
|
+
<Version>#{AMEE::Connection.api_version}.0</Version>
|
91
91
|
</Representation>
|
92
92
|
HERE
|
93
93
|
).once
|
@@ -31,7 +31,7 @@ describe AMEE::Admin::ReturnValueDefinition, "with an authenticated XML connecti
|
|
31
31
|
connection = flexmock "connection"
|
32
32
|
connection.should_receive(:retries).and_return(0).once
|
33
33
|
connection.should_receive(:v3_get).
|
34
|
-
with("/#{
|
34
|
+
with("/#{AMEE::Connection.api_version}/definitions/#{Testcativduid}/returnvalues;full", {:resultLimit=>10, :resultStart=>0}).
|
35
35
|
and_return(fixture('return_value_definition_list.xml')).once
|
36
36
|
list=AMEE::Admin::ReturnValueDefinitionList.new(connection,Testcativduid)
|
37
37
|
list.should have(3).items
|
@@ -40,7 +40,7 @@ describe AMEE::Admin::ReturnValueDefinition, "with an authenticated XML connecti
|
|
40
40
|
connection = flexmock "connection"
|
41
41
|
connection.should_receive(:retries).and_return(0).once
|
42
42
|
connection.should_receive(:v3_get).
|
43
|
-
with("/#{
|
43
|
+
with("/#{AMEE::Connection.api_version}/definitions/#{Testcativduid}/returnvalues;full", {:resultLimit=>10, :resultStart=>0}).
|
44
44
|
and_return(fixture('empty_return_value_definition_list.xml')).once
|
45
45
|
list=AMEE::Admin::ReturnValueDefinitionList.new(connection,Testcativduid)
|
46
46
|
list.should have(0).items
|
@@ -48,13 +48,13 @@ describe AMEE::Admin::ReturnValueDefinition, "with an authenticated XML connecti
|
|
48
48
|
it "should create a return value definition" do
|
49
49
|
connection = flexmock "connection"
|
50
50
|
connection.should_receive(:v3_get).
|
51
|
-
with("/#{
|
51
|
+
with("/#{AMEE::Connection.api_version}/definitions/#{Testcativduid}/returnvalues/#{Testrvduid};full", {}).
|
52
52
|
and_return(fixture('return_value_definition.xml')).once
|
53
53
|
connection.should_receive(:v3_post).
|
54
|
-
with("/#{
|
54
|
+
with("/#{AMEE::Connection.api_version}/definitions/#{Testcativduid}/returnvalues",
|
55
55
|
{:type=>"CO2", :valueDefinition=>"45433E48B39F",
|
56
56
|
:returnobj=>true, :unit=>"kg", :perUnit=>"month"}).
|
57
|
-
and_return({'Location'=>"///#{
|
57
|
+
and_return({'Location'=>"///#{AMEE::Connection.api_version}/definitions/#{Testcativduid}/returnvalues/#{Testrvduid}"}).once
|
58
58
|
rvd=AMEE::Admin::ReturnValueDefinition.create(connection,Testcativduid,
|
59
59
|
:type=>'CO2',:unit=>'kg',:perUnit=>'month')
|
60
60
|
|
@@ -66,7 +66,7 @@ describe AMEE::Admin::ReturnValueDefinition, "with an authenticated XML connecti
|
|
66
66
|
it "should read a return value definition" do
|
67
67
|
connection = flexmock "connection"
|
68
68
|
connection.should_receive(:v3_get).
|
69
|
-
with("/#{
|
69
|
+
with("/#{AMEE::Connection.api_version}/definitions/#{Testcativduid}/returnvalues/#{Testrvduid};full", {}).
|
70
70
|
and_return(fixture('return_value_definition.xml')).once
|
71
71
|
rvd=AMEE::Admin::ReturnValueDefinition.load(connection,Testcativduid,Testrvduid)
|
72
72
|
|
@@ -78,10 +78,10 @@ describe AMEE::Admin::ReturnValueDefinition, "with an authenticated XML connecti
|
|
78
78
|
it "should delete a return value definition" do
|
79
79
|
connection = flexmock "connection"
|
80
80
|
connection.should_receive(:v3_get).
|
81
|
-
with("/#{
|
81
|
+
with("/#{AMEE::Connection.api_version}/definitions/#{Testcativduid}/returnvalues/#{Testrvduid};full", {}).
|
82
82
|
and_return(fixture('return_value_definition.xml')).once
|
83
83
|
connection.should_receive(:v3_delete).
|
84
|
-
with("/#{
|
84
|
+
with("/#{AMEE::Connection.api_version}/definitions/#{Testcativduid}/returnvalues/#{Testrvduid}").once
|
85
85
|
connection.should_receive(:timeout=)
|
86
86
|
connection.should_receive(:timeout)
|
87
87
|
rvd=AMEE::Admin::ReturnValueDefinition.load(connection,Testcativduid,Testrvduid)
|
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: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 3
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 3.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Smith
|
@@ -18,12 +18,11 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2011-10
|
21
|
+
date: 2011-11-10 00:00:00 +00:00
|
22
22
|
default_executable: ameesh
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
25
|
prerelease: false
|
26
|
-
type: :runtime
|
27
26
|
requirement: &id001 !ruby/object:Gem::Requirement
|
28
27
|
none: false
|
29
28
|
requirements:
|
@@ -35,11 +34,11 @@ dependencies:
|
|
35
34
|
- 3
|
36
35
|
- 5
|
37
36
|
version: 2.3.5
|
37
|
+
type: :runtime
|
38
38
|
name: activesupport
|
39
39
|
version_requirements: *id001
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
prerelease: false
|
42
|
-
type: :runtime
|
43
42
|
requirement: &id002 !ruby/object:Gem::Requirement
|
44
43
|
none: false
|
45
44
|
requirements:
|
@@ -49,11 +48,11 @@ dependencies:
|
|
49
48
|
segments:
|
50
49
|
- 0
|
51
50
|
version: "0"
|
51
|
+
type: :runtime
|
52
52
|
name: json
|
53
53
|
version_requirements: *id002
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
prerelease: false
|
56
|
-
type: :runtime
|
57
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
58
57
|
none: false
|
59
58
|
requirements:
|
@@ -63,11 +62,11 @@ dependencies:
|
|
63
62
|
segments:
|
64
63
|
- 0
|
65
64
|
version: "0"
|
65
|
+
type: :runtime
|
66
66
|
name: log4r
|
67
67
|
version_requirements: *id003
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
69
|
prerelease: false
|
70
|
-
type: :runtime
|
71
70
|
requirement: &id004 !ruby/object:Gem::Requirement
|
72
71
|
none: false
|
73
72
|
requirements:
|
@@ -80,11 +79,11 @@ dependencies:
|
|
80
79
|
- 3
|
81
80
|
- 1
|
82
81
|
version: 1.4.3.1
|
82
|
+
type: :runtime
|
83
83
|
name: nokogiri
|
84
84
|
version_requirements: *id004
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
prerelease: false
|
87
|
-
type: :development
|
88
87
|
requirement: &id005 !ruby/object:Gem::Requirement
|
89
88
|
none: false
|
90
89
|
requirements:
|
@@ -96,11 +95,11 @@ dependencies:
|
|
96
95
|
- 0
|
97
96
|
- 0
|
98
97
|
version: 1.0.0
|
98
|
+
type: :development
|
99
99
|
name: bundler
|
100
100
|
version_requirements: *id005
|
101
101
|
- !ruby/object:Gem::Dependency
|
102
102
|
prerelease: false
|
103
|
-
type: :development
|
104
103
|
requirement: &id006 !ruby/object:Gem::Requirement
|
105
104
|
none: false
|
106
105
|
requirements:
|
@@ -112,11 +111,11 @@ dependencies:
|
|
112
111
|
- 6
|
113
112
|
- 4
|
114
113
|
version: 1.6.4
|
114
|
+
type: :development
|
115
115
|
name: jeweler
|
116
116
|
version_requirements: *id006
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
prerelease: false
|
119
|
-
type: :development
|
120
119
|
requirement: &id007 !ruby/object:Gem::Requirement
|
121
120
|
none: false
|
122
121
|
requirements:
|
@@ -128,11 +127,11 @@ dependencies:
|
|
128
127
|
- 3
|
129
128
|
- 0
|
130
129
|
version: 1.3.0
|
130
|
+
type: :development
|
131
131
|
name: rspec
|
132
132
|
version_requirements: *id007
|
133
133
|
- !ruby/object:Gem::Dependency
|
134
134
|
prerelease: false
|
135
|
-
type: :development
|
136
135
|
requirement: &id008 !ruby/object:Gem::Requirement
|
137
136
|
none: false
|
138
137
|
requirements:
|
@@ -142,11 +141,11 @@ dependencies:
|
|
142
141
|
segments:
|
143
142
|
- 0
|
144
143
|
version: "0"
|
144
|
+
type: :development
|
145
145
|
name: rcov
|
146
146
|
version_requirements: *id008
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
prerelease: false
|
149
|
-
type: :development
|
150
149
|
requirement: &id009 !ruby/object:Gem::Requirement
|
151
150
|
none: false
|
152
151
|
requirements:
|
@@ -158,11 +157,11 @@ dependencies:
|
|
158
157
|
- 1
|
159
158
|
- 3
|
160
159
|
version: 1.1.3
|
160
|
+
type: :development
|
161
161
|
name: rspec_spinner
|
162
162
|
version_requirements: *id009
|
163
163
|
- !ruby/object:Gem::Dependency
|
164
164
|
prerelease: false
|
165
|
-
type: :development
|
166
165
|
requirement: &id010 !ruby/object:Gem::Requirement
|
167
166
|
none: false
|
168
167
|
requirements:
|
@@ -174,11 +173,11 @@ dependencies:
|
|
174
173
|
- 3
|
175
174
|
- 5
|
176
175
|
version: 2.3.5
|
176
|
+
type: :development
|
177
177
|
name: activerecord
|
178
178
|
version_requirements: *id010
|
179
179
|
- !ruby/object:Gem::Dependency
|
180
180
|
prerelease: false
|
181
|
-
type: :development
|
182
181
|
requirement: &id011 !ruby/object:Gem::Requirement
|
183
182
|
none: false
|
184
183
|
requirements:
|
@@ -188,6 +187,7 @@ dependencies:
|
|
188
187
|
segments:
|
189
188
|
- 0
|
190
189
|
version: "0"
|
190
|
+
type: :development
|
191
191
|
name: flexmock
|
192
192
|
version_requirements: *id011
|
193
193
|
description:
|