hookercookerman-amee 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. data/History.txt +1 -0
  2. data/LICENSE.txt +20 -0
  3. data/Manifest.txt +79 -0
  4. data/README.rdoc +33 -0
  5. data/Rakefile +29 -0
  6. data/features/config.feature +22 -0
  7. data/features/data/data_category.feature +26 -0
  8. data/features/data/data_item.feature +19 -0
  9. data/features/data/data_item_value.feature +17 -0
  10. data/features/data/drill_down.feature +48 -0
  11. data/features/development.feature +13 -0
  12. data/features/profile/create.profile.feature +15 -0
  13. data/features/profile/create.profile_item.feature +12 -0
  14. data/features/profile/delete.profile.feature +12 -0
  15. data/features/profile/delete.profile_item.feature +13 -0
  16. data/features/profile/get.profile.feature +13 -0
  17. data/features/profile/profile_category.feature +14 -0
  18. data/features/profile/profile_item.feature +15 -0
  19. data/features/profile/profiles.feature +15 -0
  20. data/features/profile/update.profile_item.feature +14 -0
  21. data/features/session/reauthenticate.feature +16 -0
  22. data/features/step_definitions/amee_steps.rb +67 -0
  23. data/features/step_definitions/common_steps.rb +194 -0
  24. data/features/step_definitions/config_steps.rb +13 -0
  25. data/features/step_definitions/data_steps.rb +142 -0
  26. data/features/step_definitions/profile_category_steps.rb +23 -0
  27. data/features/step_definitions/profile_item_steps.rb +62 -0
  28. data/features/step_definitions/profile_steps.rb +41 -0
  29. data/features/support/amee/auth/response.json +11 -0
  30. data/features/support/amee/data.json +84 -0
  31. data/features/support/amee/data/transport/car/generic.json +3 -0
  32. data/features/support/amee/data/transport/car/generic/drill.json +66 -0
  33. data/features/support/amee/data/transport/car/generic/drill?fuel=diesel&size=large.json +55 -0
  34. data/features/support/amee/data/transport/car/generic/drill?fuel=diesel.json +59 -0
  35. data/features/support/amee/data/transport/plane/generic.json +225 -0
  36. data/features/support/amee/data/transport/plane/generic/FFC7A05D54AD.json +224 -0
  37. data/features/support/amee/data/transport/plane/generic/FFC7A05D54AD/kgCO2PerPassengerJourney.json +42 -0
  38. data/features/support/amee/data_category.json +84 -0
  39. data/features/support/amee/data_category_with_data_items.json +225 -0
  40. data/features/support/amee/profiles.json +73 -0
  41. data/features/support/amee/profiles/155DD3C63646/transport/motorcycle/generic/D47C465B8157.json +190 -0
  42. data/features/support/amee/profiles/155DD3C63646/transport/motorcycle/generic/D47C465B8157?distance=400&representation=true.json +190 -0
  43. data/features/support/amee/profiles/48B97680BCCF/home/energy/quantity/response.json +9 -0
  44. data/features/support/amee/profiles/7C7D68C2A7CD/home.json +65 -0
  45. data/features/support/amee/profiles/BB1BDB4FDD77/home/energy/quantity/920B54ED665B.json +201 -0
  46. data/features/support/amee/profiles/E0BCB3704D15.json +19 -0
  47. data/features/support/amee/profiles/E0BCB3704D15/Business.json +6 -0
  48. data/features/support/amee/profiles/profile.json +27 -0
  49. data/features/support/env.rb +24 -0
  50. data/init.rb +4 -0
  51. data/lib/amee.rb +37 -0
  52. data/lib/amee/config.rb +59 -0
  53. data/lib/amee/data_api/data_category.rb +50 -0
  54. data/lib/amee/data_api/data_item.rb +28 -0
  55. data/lib/amee/data_api/data_item_value.rb +13 -0
  56. data/lib/amee/data_api/drill_down.rb +23 -0
  57. data/lib/amee/data_api/item_definition.rb +11 -0
  58. data/lib/amee/data_api/item_value_definition.rb +13 -0
  59. data/lib/amee/data_api/value_definition.rb +10 -0
  60. data/lib/amee/logging.rb +43 -0
  61. data/lib/amee/model.rb +128 -0
  62. data/lib/amee/parser.rb +137 -0
  63. data/lib/amee/profile_api/profile.rb +39 -0
  64. data/lib/amee/profile_api/profile_category.rb +42 -0
  65. data/lib/amee/profile_api/profile_item.rb +47 -0
  66. data/lib/amee/service.rb +78 -0
  67. data/lib/amee/session.rb +222 -0
  68. data/lib/amee/utils/string.rb +11 -0
  69. data/script/console +10 -0
  70. data/script/destroy +14 -0
  71. data/script/generate +14 -0
  72. data/script/txt2html +71 -0
  73. data/spec/amee_spec.rb +1 -0
  74. data/spec/service_spec.rb +53 -0
  75. data/spec/session_spec.rb +45 -0
  76. data/spec/spec.opts +1 -0
  77. data/spec/spec_helper.rb +19 -0
  78. data/tasks/rspec.rake +21 -0
  79. data/tasks/yard.rake +4 -0
  80. metadata +184 -0
@@ -0,0 +1,9 @@
1
+ HTTP/1.1 201 Created
2
+ Location: whatever
3
+ Cache-Control: private
4
+ Content-Type: text/html; charset=UTF-8
5
+ Date: Thu, 23 Apr 2009 17:11:42 GMT
6
+ Server: gws
7
+ Content-Length: 221
8
+
9
+ egg
@@ -0,0 +1,65 @@
1
+ {
2
+ "dataCategory":{
3
+ "uid":"BBA3AC3E795E",
4
+ "name":"Home",
5
+ "path":"home"
6
+ },
7
+ "totalAmountPerMonth":"0",
8
+ "path":"/home",
9
+ "children":{
10
+ "pager":{
11
+ },
12
+ "dataCategories":[
13
+ {
14
+ "uid":"427DFCC65E52",
15
+ "name":"Appliances",
16
+ "path":"appliances"
17
+ },
18
+ {
19
+ "uid":"30BA55A0C472",
20
+ "name":"Energy",
21
+ "path":"energy"
22
+ },
23
+ {
24
+ "uid":"A46ECFA19333",
25
+ "name":"Heating",
26
+ "path":"heating"
27
+ },
28
+ {
29
+ "uid":"150266DD4434",
30
+ "name":"Lighting",
31
+ "path":"lighting"
32
+ },
33
+ {
34
+ "uid":"6553150F96CE",
35
+ "name":"Waste",
36
+ "path":"waste"
37
+ },
38
+ {
39
+ "uid":"07362DCC9E7B",
40
+ "name":"Water",
41
+ "path":"water"
42
+ }
43
+ ],
44
+ "profileItems":{
45
+ }
46
+ },
47
+ "profileItemActions":{
48
+ "allowCreate":true,
49
+ "allowView":true,
50
+ "allowList":true,
51
+ "allowModify":true,
52
+ "allowDelete":true
53
+ },
54
+ "profileDate":"200903",
55
+ "actions":{
56
+ "allowCreate":true,
57
+ "allowView":true,
58
+ "allowList":true,
59
+ "allowModify":true,
60
+ "allowDelete":true
61
+ },
62
+ "profile":{
63
+ "uid":"17A4CE4C3D91"
64
+ }
65
+ }
@@ -0,0 +1,201 @@
1
+ {
2
+ "profileItem":{
3
+ "uid":"920B54ED665B",
4
+ "itemValues":[
5
+ {
6
+ "itemValueDefinition":{
7
+ "uid":"51D072825D41",
8
+ "name":"kg Per Month",
9
+ "path":"kgPerMonth",
10
+ "valueDefinition":{
11
+ "uid":"36A771FC1D1A",
12
+ "name":"kg",
13
+ "valueType":"DECIMAL"
14
+ }
15
+ },
16
+ "uid":"869D6084EB9C",
17
+ "name":"kg Per Month",
18
+ "value":"0",
19
+ "path":"kgPerMonth"
20
+ },
21
+ {
22
+ "itemValueDefinition":{
23
+ "uid":"4DF458FD0E4D",
24
+ "name":"kWh Per Month",
25
+ "path":"kWhPerMonth",
26
+ "valueDefinition":{
27
+ "uid":"26A5C97D3728",
28
+ "name":"kWh",
29
+ "valueType":"DECIMAL"
30
+ }
31
+ },
32
+ "uid":"CFA69C6E4D3F",
33
+ "name":"kWh Per Month",
34
+ "value":"10",
35
+ "path":"kWhPerMonth"
36
+ },
37
+ {
38
+ "itemValueDefinition":{
39
+ "uid":"C9B7E19269A5",
40
+ "name":"Litres Per Month",
41
+ "path":"litresPerMonth",
42
+ "valueDefinition":{
43
+ "uid":"06B8CFC5A521",
44
+ "name":"litre",
45
+ "valueType":"DECIMAL"
46
+ }
47
+ },
48
+ "uid":"A5E88E093F9F",
49
+ "name":"Litres Per Month",
50
+ "value":"0",
51
+ "path":"litresPerMonth"
52
+ },
53
+ {
54
+ "itemValueDefinition":{
55
+ "uid":"8A468E75C8E8",
56
+ "name":"kWh reading current",
57
+ "path":"kWhReadingCurrent",
58
+ "valueDefinition":{
59
+ "uid":"45433E48B39F",
60
+ "name":"amount",
61
+ "valueType":"DECIMAL"
62
+ }
63
+ },
64
+ "uid":"335A93429B77",
65
+ "name":"kWh reading current",
66
+ "value":"0",
67
+ "path":"kWhReadingCurrent"
68
+ },
69
+ {
70
+ "itemValueDefinition":{
71
+ "uid":"2328DC7F23AE",
72
+ "name":"kWh reading last",
73
+ "path":"kWhReadingLast",
74
+ "valueDefinition":{
75
+ "uid":"45433E48B39F",
76
+ "name":"amount",
77
+ "valueType":"DECIMAL"
78
+ }
79
+ },
80
+ "uid":"38FAFEE33F01",
81
+ "name":"kWh reading last",
82
+ "value":"0",
83
+ "path":"kWhReadingLast"
84
+ },
85
+ {
86
+ "itemValueDefinition":{
87
+ "uid":"E0EFED6FD7E6",
88
+ "name":"Payment frequency",
89
+ "path":"paymentFrequency",
90
+ "valueDefinition":{
91
+ "uid":"CCEB59CACE1B",
92
+ "name":"text",
93
+ "valueType":"TEXT"
94
+ }
95
+ },
96
+ "uid":"EBC261EDC5D2",
97
+ "name":"Payment frequency",
98
+ "value":"",
99
+ "path":"paymentFrequency"
100
+ },
101
+ {
102
+ "itemValueDefinition":{
103
+ "uid":"63005554AE8A",
104
+ "name":"Green tariff",
105
+ "path":"greenTariff",
106
+ "valueDefinition":{
107
+ "uid":"CCEB59CACE1B",
108
+ "name":"text",
109
+ "valueType":"TEXT"
110
+ }
111
+ },
112
+ "uid":"3D90D411DC4B",
113
+ "name":"Green tariff",
114
+ "value":"",
115
+ "path":"greenTariff"
116
+ },
117
+ {
118
+ "itemValueDefinition":{
119
+ "uid":"527AADFB3B65",
120
+ "name":"Season",
121
+ "path":"season",
122
+ "valueDefinition":{
123
+ "uid":"CCEB59CACE1B",
124
+ "name":"text",
125
+ "valueType":"TEXT"
126
+ }
127
+ },
128
+ "uid":"67D489724500",
129
+ "name":"Season",
130
+ "value":"",
131
+ "path":"season"
132
+ },
133
+ {
134
+ "itemValueDefinition":{
135
+ "uid":"1740E500BDAB",
136
+ "name":"Includes Heating",
137
+ "path":"includesHeating",
138
+ "valueDefinition":{
139
+ "uid":"CCEB59CACE1B",
140
+ "name":"text",
141
+ "valueType":"TEXT"
142
+ }
143
+ },
144
+ "uid":"A0C15D226883",
145
+ "name":"Includes Heating",
146
+ "value":"false",
147
+ "path":"includesHeating"
148
+ },
149
+ {
150
+ "itemValueDefinition":{
151
+ "uid":"AA1D1C349119",
152
+ "name":"Number of deliveries",
153
+ "path":"numberOfDeliveries",
154
+ "valueDefinition":{
155
+ "uid":"45433E48B39F",
156
+ "name":"amount",
157
+ "valueType":"DECIMAL"
158
+ }
159
+ },
160
+ "uid":"FCABCD89A8D8",
161
+ "name":"Number of deliveries",
162
+ "value":"",
163
+ "path":"numberOfDeliveries"
164
+ }
165
+ ],
166
+ "dataCategory":{
167
+ "uid":"A92693A99BAD",
168
+ "name":"Quantity",
169
+ "path":"quantity"
170
+ },
171
+ "itemDefinition":{
172
+ "uid":"212C818D8F16"
173
+ },
174
+ "dataItem":{
175
+ "uid":"66056991EE23"
176
+ },
177
+ "modified":"2009-03-19 15:25:40.0",
178
+ "environment":{
179
+ "uid":"5F5887BCF726"
180
+ },
181
+ "created":"2009-03-19 15:25:40.0",
182
+ "name":"920B54ED665B",
183
+ "validFrom":"20090301",
184
+ "end":"false",
185
+ "amountPerMonth":2.055,
186
+ "profile":{
187
+ "uid":"BB1BDB4FDD77"
188
+ }
189
+ },
190
+ "path":"/home/energy/quantity/920B54ED665B",
191
+ "actions":{
192
+ "allowCreate":true,
193
+ "allowView":true,
194
+ "allowList":true,
195
+ "allowModify":true,
196
+ "allowDelete":true
197
+ },
198
+ "profile":{
199
+ "uid":"BB1BDB4FDD77"
200
+ }
201
+ }
@@ -0,0 +1,19 @@
1
+ {"dataCategory":{"name":"Root","uid":"CD310BEBAC52","path":""},
2
+ "profile":{"modified":"2009-01-19 20:54:35.0","name":"E0BCB3704D15","uid":"E0BCB3704D15",
3
+ "permission":{"modified":"2009-01-19 20:54:35.0",
4
+ "group":{"name":"amee","uid":"AC65FFA5F9D9"},
5
+ "auth":{"username":"whateverman","uid":"5861D2B0ABBD"},
6
+ "uid":"5FEF6A85F47F","environmentUid":"5F5887BCF726","created":"2009-01-19 20:54:35.0"},
7
+ "path":"E0BCB3704D15","environment":{"uid":"5F5887BCF726"},"created":"2009-01-19 20:54:35.0"},
8
+ "profileDate":"200904","path":"","totalAmountPerMonth":"0",
9
+ "children":{
10
+ "profileItems":{},
11
+ "pager":{},
12
+ "dataCategories":[{"name":"Business","uid":"99B121BB416C","path":"business"},
13
+ {"name":"Home","uid":"BBA3AC3E795E","path":"home"},{"name":"Import","uid":"85A9172C31AF","path":"import"},
14
+ {"name":"Metadata","uid":"9E5362EAB0E7","path":"metadata"},
15
+ {"name":"Personal","uid":"A0CF90F6C0B9","path":"personal"},
16
+ {"name":"Planet","uid":"6FF29F7DACDA","path":"planet"},
17
+ {"name":"Test","uid":"6153F468BE05","path":"test"},
18
+ {"name":"Transport","uid":"263FC0186834","path":"transport"},
19
+ {"name":"User","uid":"2957AE9B6E6B","path":"user"}]}}
@@ -0,0 +1,6 @@
1
+ {"dataCategory":{"name":"Business","uid":"99B121BB416C","path":"business"},
2
+ "profile":{"uid":"E0BCB3704D15"},"profileDate":"200904","path":"/business","totalAmountPerMonth":"0",
3
+ "children":{"profileItems":{},"pager":{},
4
+ "dataCategories":[{"name":"Energy","uid":"066196F049DD","path":"energy"},
5
+ {"name":"Globalwarmingpotentials","uid":"31A2C4DED365","path":"globalWarmingPotentials"},
6
+ {"name":"Waste","uid":"3035D381872B","path":"waste"}]}}
@@ -0,0 +1,27 @@
1
+ {
2
+ "apiVersion":"2.0",
3
+ "profile":{
4
+ "uid":"180D73DA5229",
5
+ "environment":{
6
+ "uid":"5F5887BCF726"
7
+ },
8
+ "created":"Wed Mar 18 10:23:59 GMT 2009",
9
+ "name":"180D73DA5229",
10
+ "path":"180D73DA5229",
11
+ "permission":{
12
+ "uid":"2F093CD55011",
13
+ "created":"Wed Mar 18 10:23:59 GMT 2009",
14
+ "group":{
15
+ "uid":"AC65FFA5F9D9",
16
+ "name":"amee"
17
+ },
18
+ "environmentUid":"5F5887BCF726",
19
+ "auth":{
20
+ "uid":"BA6EB0039D69",
21
+ "username":"v2user"
22
+ },
23
+ "modified":"Wed Mar 18 10:23:59 GMT 2009"
24
+ },
25
+ "modified":"Wed Mar 18 10:23:59 GMT 2009"
26
+ }
27
+ }
@@ -0,0 +1,24 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'amee'
3
+
4
+ gem 'cucumber'
5
+ require 'cucumber'
6
+ gem 'rspec'
7
+ require 'spec'
8
+
9
+ # yes I know not meant to have this but I need the auth_token
10
+ # stubbed so there ok deal with it
11
+ require "spec/mocks"
12
+
13
+
14
+ gem "fakeweb"
15
+ require "fakeweb"
16
+
17
+ # amee fixtures or canned responses
18
+ AMEE_FIXTURE_PATH = File.dirname(__FILE__) + "/amee"
19
+
20
+ # dont want any real
21
+ FakeWeb.allow_net_connect = false
22
+
23
+
24
+
data/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'amee'
2
+
3
+ # enable logger before including everything else, in case we ever want to log initialization
4
+ Amee.logger = RAILS_DEFAULT_LOGGER if Object.const_defined? :RAILS_DEFAULT_LOGGER
data/lib/amee.rb ADDED
@@ -0,0 +1,37 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require "rubygems"
5
+ begin
6
+ gem "json"
7
+ require "json/ext"
8
+ rescue LoadError
9
+ gem "json_pure"
10
+ require "json/pure"
11
+ end
12
+
13
+ require "httparty"
14
+ require "moneta"
15
+ require "moneta/memory"
16
+
17
+ require "amee/utils/string"
18
+ require "amee/config"
19
+ require "amee/logging"
20
+ require "amee/service"
21
+ require "amee/session"
22
+ require "amee/parser"
23
+ require "amee/model"
24
+ require "amee/data_api/data_item"
25
+ require "amee/data_api/data_category"
26
+ require "amee/data_api/item_definition"
27
+ require "amee/data_api/data_item_value"
28
+ require "amee/data_api/drill_down"
29
+ require "amee/data_api/item_value_definition"
30
+ require "amee/data_api/value_definition"
31
+ require "amee/profile_api/profile_item"
32
+ require "amee/profile_api/profile_category"
33
+ require "amee/profile_api/profile"
34
+
35
+ module Amee
36
+ VERSION = '0.0.1'
37
+ end
@@ -0,0 +1,59 @@
1
+ module Amee
2
+ class Config
3
+ class << self
4
+ attr_accessor :configuration
5
+
6
+ def defaults
7
+ @defaults ||= {
8
+ :cache => true,
9
+ :cache_store => Moneta::Memory,
10
+ :expires_in => 60*60*24,
11
+ :server => "stage.amee.com",
12
+ :auth_path => "/auth",
13
+ :accept => "application/json",
14
+ :logging => true
15
+ }
16
+ end
17
+
18
+ # yields the configuration
19
+ #
20
+ # @example
21
+ # Amee::Config.set |config| do
22
+ # config[:server] = "dev.aimee.com"
23
+ # end
24
+ #
25
+ # @return nil
26
+ def set
27
+ @configuration ||= defaults
28
+ yield @configuration
29
+ nil
30
+ end
31
+
32
+
33
+ def key?(key)
34
+ (@configuration ||= defaults).key?(key)
35
+ end
36
+
37
+ # Retrieve the value from the config
38
+ #
39
+ # @param [Object] key the key to return the value from
40
+ #
41
+ # @return [Object]
42
+ def [](key)
43
+ (@configuration ||= defaults)[key]
44
+ end
45
+
46
+ # sets the value of the config
47
+ def []=(key, val)
48
+ (@configuration ||= defaults)[key] = val
49
+ end
50
+
51
+ # deletes the value from the config
52
+ def delete(key)
53
+ (@configuration ||= defaults).delete(key)
54
+ end
55
+
56
+ end
57
+
58
+ end # Config
59
+ end # Amee