amee 4.3.2 → 4.4.0
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.
- data/CHANGELOG.txt +6 -0
- data/Gemfile +7 -1
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/amee.gemspec +57 -6
- data/amee_test_credentials.example.yml +11 -0
- data/cassettes/AMEE_Connection/v2/raising_unhandled_errors.yml +36 -0
- data/cassettes/AMEE_Connection/v3/retries/502.yml +36 -0
- data/cassettes/AMEE_Connection/v3/retries/503.yml +36 -0
- data/cassettes/AMEE_Connection/v3/retries/504.yml +36 -0
- data/cassettes/AMEE_Connection/v3/retries/AMEE_TimeOut.yml +36 -0
- data/cassettes/AMEE_Connection/v3/should_be_able_to_get_from_meta_server.yml +30 -0
- data/cassettes/AMEE_Connection/v3/should_be_able_to_handle_failed_gets_from_meta_server.yml +30 -0
- data/cassettes/AMEE_Connection/v3/should_be_able_to_post_to_meta_server.yml +59 -0
- data/cassettes/AMEE_Connection/v3/should_have_a_connection_to_meta_server.yml +36 -0
- data/cassettes/AMEE_Connection/v3/should_login_and_know_the_path_to_the_server.yml +36 -0
- data/cassettes/AMEE_Connection_Caching_Off/authenticating.yml +36 -0
- data/cassettes/AMEE_Connection_Caching_Off/first_request.yml +40 -0
- data/cassettes/AMEE_Connection_Caching_Off/second_request.yml +40 -0
- data/cassettes/AMEE_Connection_Caching_On/authenticating.yml +36 -0
- data/cassettes/AMEE_Connection_Caching_On/first_request.yml +40 -0
- data/cassettes/AMEE_Connection_Caching_clear_all/second_request.yml +40 -0
- data/cassettes/AMEE_Connection_Caching_clear_manually/second_request.yml +40 -0
- data/cassettes/AMEE_Connection_Caching_further_down_tree/second_request.yml +79 -0
- data/cassettes/AMEE_Connection_with_authentication/handling_404s.yml +69 -0
- data/cassettes/AMEE_Connection_with_authentication/hitting_private_urls.yml +75 -0
- data/cassettes/AMEE_Connection_with_authentication/raising_errors_if_permission_denied.yml +69 -0
- data/cassettes/AMEE_Connection_with_authentication/should_re-authenticate_and_refresh_authtoken_when_authtoken_expires.yml +104 -0
- data/cassettes/AMEE_Connection_with_authentication/should_refresh_authtoken_when_authtoken_is_changed.yml +114 -0
- data/cassettes/AMEE_Connection_with_authentication/using_a_v1_key.yml +71 -0
- data/cassettes/AMEE_Connection_with_authentication/using_a_v2_key/detects_the_API_version_for_JSON.yml +36 -0
- data/cassettes/AMEE_Connection_with_authentication/using_a_v2_key/detects_the_API_version_for_XML.yml +36 -0
- data/cassettes/AMEE_Connection_with_authentication_doing_write-requests.yml +75 -0
- data/cassettes/AMEE_Connection_with_authentication_doing_write-requests/working_with_an_existing_profile/deleting_existing_items.yml +108 -0
- data/cassettes/AMEE_Connection_with_authentication_doing_write-requests/working_with_an_existing_profile/sending_updates_to_existing_items.yml +108 -0
- data/cassettes/AMEE_Connection_with_bad_authentication_information/hitting_a_private_url.yml +29 -0
- data/cassettes/AMEE_Connection_with_bad_authentication_information/hitting_a_public_url.yml +32 -0
- data/cassettes/AMEE_Connection_with_incorrect_server_name.yml +16 -0
- data/cassettes/AMEE_Connection_with_retry_enabled.yml +36 -0
- data/lib/amee/connection.rb +234 -110
- data/lib/amee/data_category.rb +2 -2
- data/lib/amee/data_item.rb +45 -2
- data/lib/amee/data_item_value.rb +1 -1
- data/lib/amee/exceptions.rb +5 -2
- data/lib/amee/parse_helper.rb +2 -0
- data/lib/amee/profile_item.rb +6 -2
- data/lib/amee/v3/connection.rb +77 -70
- data/lib/amee/v3/item_value_definition.rb +1 -1
- data/lib/amee/v3/return_value_definition.rb +1 -1
- data/spec/cache_spec.rb +107 -48
- data/spec/connection_spec.rb +224 -183
- data/spec/data_item_spec.rb +12 -0
- data/spec/data_item_value_history_spec.rb +4 -4
- data/spec/data_item_value_spec.rb +2 -2
- data/spec/fixtures/AD63A83B4D41.json +1 -1
- data/spec/fixtures/AD63A83B4D41.xml +1 -1
- data/spec/profile_item_spec.rb +14 -10
- data/spec/spec_helper.rb +29 -0
- data/spec/v3/connection_spec.rb +77 -65
- data/spec/v3/item_value_definition_spec.rb +1 -0
- data/spec/v3/return_value_definition_spec.rb +1 -1
- metadata +140 -24
- data/Gemfile.lock +0 -63
data/spec/connection_spec.rb
CHANGED
@@ -6,34 +6,32 @@ require 'spec_helper.rb'
|
|
6
6
|
describe AMEE::Connection do
|
7
7
|
|
8
8
|
it "requires server name, username, and password" do
|
9
|
-
|
9
|
+
|
10
10
|
lambda{AMEE::Connection.new(nil, nil, nil)}.should raise_error
|
11
11
|
lambda{AMEE::Connection.new(nil, 'username', nil)}.should raise_error
|
12
12
|
lambda{AMEE::Connection.new(nil, nil, 'password')}.should raise_error
|
13
13
|
lambda{AMEE::Connection.new(nil, 'username', 'password')}.should raise_error
|
14
|
-
lambda{AMEE::Connection.new('
|
15
|
-
lambda{AMEE::Connection.new('
|
16
|
-
lambda{AMEE::Connection.new('
|
17
|
-
c = AMEE::Connection.new('
|
14
|
+
lambda{AMEE::Connection.new('stage.amee.com', nil, nil)}.should raise_error
|
15
|
+
lambda{AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, nil)}.should raise_error
|
16
|
+
lambda{AMEE::Connection.new('stage.amee.com', nil, 'password')}.should raise_error
|
17
|
+
c = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
18
18
|
c.should be_valid
|
19
19
|
end
|
20
20
|
|
21
21
|
it "has default timeout of 60 seconds" do
|
22
|
-
|
23
|
-
c = AMEE::Connection.new('
|
22
|
+
|
23
|
+
c = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
24
24
|
c.timeout.should be(60)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "can set timeout" do
|
28
|
-
|
29
|
-
c = AMEE::Connection.new('server.example.com', 'username', 'password')
|
28
|
+
c = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
30
29
|
c.timeout = 30
|
31
30
|
c.timeout.should be(30)
|
32
31
|
end
|
33
32
|
|
34
33
|
it "can set timeout on creation" do
|
35
|
-
|
36
|
-
c = AMEE::Connection.new('server.example.com', 'username', 'password', :timeout => 30)
|
34
|
+
c = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD, :timeout => 30)
|
37
35
|
c.timeout.should be(30)
|
38
36
|
end
|
39
37
|
|
@@ -41,199 +39,210 @@ end
|
|
41
39
|
|
42
40
|
describe AMEE::Connection, "with authentication" do
|
43
41
|
|
42
|
+
describe "using a version 1 api key" do
|
43
|
+
use_vcr_cassette "AMEE_Connection_with_authentication/using a v1 key", :record => :new_episodes
|
44
|
+
it "detects the API version (1)" do
|
45
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V1_API_KEY, AMEE_V1_PASSWORD)
|
46
|
+
amee.authenticate
|
47
|
+
amee.authenticated?.should be_true
|
48
|
+
amee.version.should == 1.0
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "using a version 2 api key" do
|
53
|
+
|
44
54
|
it "should start out unauthenticated" do
|
45
|
-
|
46
|
-
amee = AMEE::Connection.new('server.example.com', 'username', 'password')
|
55
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
47
56
|
amee.authenticated?.should be_false
|
48
57
|
end
|
49
58
|
|
50
|
-
it "detects the API version (
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
59
|
+
it "detects the API version (2 - XML) normally" do
|
60
|
+
VCR.use_cassette('AMEE_Connection_with_authentication/using_a_v2_key/detects the API version for XML') do
|
61
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
62
|
+
amee.authenticate
|
63
|
+
amee.authenticated?.should be_true
|
64
|
+
amee.version.should == 2.0
|
55
65
|
end
|
56
|
-
amee = AMEE::Connection.new('server.example.com', 'username', 'password')
|
57
|
-
amee.authenticate
|
58
|
-
amee.authenticated?.should be_true
|
59
|
-
amee.version.should == 1.0
|
60
66
|
end
|
61
67
|
|
62
|
-
it "detects the API version (2 -
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
68
|
+
it "detects the API version (2 - JSON)" do
|
69
|
+
VCR.use_cassette('AMEE_Connection_with_authentication/using_a_v2_key/detects the API version for JSON') do
|
70
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
71
|
+
amee.authenticate
|
72
|
+
amee.authenticated?.should be_true
|
73
|
+
amee.version.should == 2.0
|
67
74
|
end
|
68
|
-
amee = AMEE::Connection.new('server.example.com', 'username', 'password')
|
69
|
-
amee.authenticate
|
70
|
-
amee.authenticated?.should be_true
|
71
|
-
amee.version.should == 2.0
|
72
75
|
end
|
73
76
|
|
74
|
-
it "detects the API version (2 - JSON)" do
|
75
|
-
flexmock(Net::HTTP).new_instances do |mock|
|
76
|
-
mock.should_receive(:start => nil)
|
77
|
-
mock.should_receive(:request).and_return(flexmock(:code => '200', :body => '{ "next" : "/auth","user" : { "apiVersion" : "2.0","groupNames" : [ "amee","Standard","All"],"status" : "ACTIVE","type" : "STANDARD","uid" : "DB2C6DA7EAA7"}}', :'[]' => 'dummy_auth_token_data'))
|
78
|
-
mock.should_receive(:finish => nil)
|
79
|
-
end
|
80
|
-
amee = AMEE::Connection.new('server.example.com', 'username', 'password')
|
81
|
-
amee.authenticate
|
82
|
-
amee.authenticated?.should be_true
|
83
|
-
amee.version.should == 2.0
|
84
77
|
end
|
85
78
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
flexmock(:code => '401', :body => '')
|
96
|
-
end
|
97
|
-
}.once
|
98
|
-
mock.should_receive(:finish => nil)
|
99
|
-
end
|
100
|
-
amee = AMEE::Connection.new('server.example.com', 'username', 'password')
|
101
|
-
amee.get('/data') do |response|
|
102
|
-
response.should_not be_empty
|
79
|
+
describe "hitting_private_urls" do
|
80
|
+
use_vcr_cassette
|
81
|
+
|
82
|
+
it "should be able to get private URLs" do
|
83
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
84
|
+
amee.get('/data') do |response|
|
85
|
+
response.should_not be_empty
|
86
|
+
end
|
87
|
+
amee.authenticated?.should be_true
|
103
88
|
end
|
104
|
-
amee.authenticated?.should be_true
|
105
89
|
end
|
106
90
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
91
|
+
describe "handling 404s" do
|
92
|
+
use_vcr_cassette
|
93
|
+
it "should handle 404s gracefully" do
|
94
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
95
|
+
lambda{amee.get('/missing_url')}.should raise_error(AMEE::NotFound, "The URL was not found on the server.\nRequest: GET /missing_url")
|
96
|
+
end
|
111
97
|
end
|
112
98
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
99
|
+
describe "raising errors if permission denied" do
|
100
|
+
use_vcr_cassette
|
101
|
+
|
102
|
+
it "should raise error if permission for operation is denied" do
|
103
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
104
|
+
lambda {
|
105
|
+
amee.get('/data/lca/ecoinvent')
|
106
|
+
}.should raise_error(AMEE::PermissionDenied)
|
118
107
|
end
|
119
|
-
amee = AMEE::Connection.new('server.example.com', 'username', 'password')
|
120
|
-
lambda {
|
121
|
-
amee.get('/data')
|
122
|
-
}.should raise_error(AMEE::PermissionDenied,"You do not have permission to perform the requested operation.
|
123
|
-
Request: GET /data
|
124
|
-
Response: {}")
|
125
108
|
end
|
126
109
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
110
|
+
describe "raising unhandled errors" do
|
111
|
+
it "should raise error if unhandled errors occur in connection" do
|
112
|
+
|
113
|
+
@error_response = {
|
114
|
+
:status => 500,
|
115
|
+
:body => ""
|
116
|
+
}
|
117
|
+
|
118
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
119
|
+
|
120
|
+
VCR.use_cassette("AMEE_Connection/v2/raising unhandled errors") do
|
121
|
+
amee.authenticate
|
122
|
+
end
|
123
|
+
stub_request(:any, "https://stage.amee.com/data").to_return(@error_response)
|
124
|
+
|
125
|
+
lambda {
|
126
|
+
amee.get('/data')
|
127
|
+
}.should raise_error(AMEE::UnknownError)
|
134
128
|
end
|
135
|
-
amee = AMEE::Connection.new('server.example.com', 'username', 'password')
|
136
|
-
lambda {
|
137
|
-
amee.get('/data')
|
138
|
-
}.should raise_error(AMEE::PermissionDenied,"You do not have permission to perform the requested operation.
|
139
|
-
Request: GET /data
|
140
|
-
Response: {}")
|
141
|
-
amee.authenticated?.should be_true
|
142
129
|
end
|
143
130
|
|
144
|
-
it "should
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
131
|
+
it "should re-authenticate and refresh authtoken when authtoken expires" do
|
132
|
+
VCR.use_cassette('AMEE_Connection_with_authentication/should re-authenticate and refresh authtoken when authtoken expires') do
|
133
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
134
|
+
amee.auth_token = 'old_token'
|
135
|
+
amee.get('/profiles')
|
136
|
+
amee.auth_token.should_not eql 'old_token'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should refresh authtoken when authtoken is changed" do
|
141
|
+
VCR.use_cassette('AMEE_Connection_with_authentication/should refresh authtoken when authtoken is changed') do
|
142
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
143
|
+
amee.get('/profiles')
|
144
|
+
old_token = amee.auth_token
|
145
|
+
#sleep(65) # Wait 65 seconds so platform changes auth token. This is only required when generating the cassette.
|
146
|
+
amee.get('/profiles')
|
147
|
+
amee.auth_token.should_not eql old_token
|
149
148
|
end
|
150
|
-
amee = AMEE::Connection.new('server.example.com', 'username', 'password')
|
151
|
-
lambda {
|
152
|
-
amee.get('/data')
|
153
|
-
}.should raise_error(AMEE::UnknownError,"An error occurred while talking to AMEE: HTTP response code 500.
|
154
|
-
Request: GET /data
|
155
|
-
Response: {}")
|
156
149
|
end
|
157
150
|
|
158
151
|
end
|
159
152
|
|
160
153
|
describe AMEE::Connection, "with retry enabled" do
|
161
|
-
|
154
|
+
use_vcr_cassette
|
162
155
|
[
|
163
|
-
|
164
|
-
Errno::EINVAL,
|
165
|
-
Errno::ECONNRESET,
|
166
|
-
EOFError,
|
167
|
-
Net::HTTPBadResponse,
|
168
|
-
Net::HTTPHeaderSyntaxError,
|
169
|
-
Net::ProtocolError
|
156
|
+
AMEE::TimeOut,
|
170
157
|
].each do |e|
|
171
158
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
159
|
+
before(:each) do
|
160
|
+
|
161
|
+
@amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD, :retries => 2)
|
162
|
+
|
163
|
+
VCR.use_cassette("AMEE_Connection/v2/raising unhandled errors") do
|
164
|
+
@amee.authenticate
|
178
165
|
end
|
179
|
-
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should retry after #{e.name} the correct number of times" do
|
170
|
+
|
171
|
+
@error_response = {
|
172
|
+
:status => 408,
|
173
|
+
:body => ""
|
174
|
+
}
|
175
|
+
|
176
|
+
|
177
|
+
stub_request(:any, "https://stage.amee.com/data").to_return(@error_response).times(2).
|
178
|
+
then.to_return(:status => 200, :body => {})
|
179
|
+
|
180
180
|
lambda {
|
181
|
-
amee.get('/data')
|
182
|
-
}.should_not raise_error
|
181
|
+
@amee.get('/data')
|
182
|
+
}.should_not raise_error
|
183
183
|
end
|
184
184
|
|
185
185
|
it "should retry #{e.name} the correct number of times and raise error on failure" do
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
186
|
+
|
187
|
+
@error_response = {
|
188
|
+
:status => 408,
|
189
|
+
:body => ""
|
190
|
+
}
|
191
|
+
stub_request(:any, "https://stage.amee.com/data").to_return(@error_response).times(3)
|
192
|
+
|
192
193
|
lambda {
|
193
|
-
amee.get('/data')
|
194
|
+
@amee.get('/data')
|
194
195
|
}.should raise_error(e)
|
195
196
|
end
|
196
197
|
end
|
197
|
-
|
198
|
+
|
198
199
|
[
|
199
|
-
|
200
|
-
|
201
|
-
|
200
|
+
502,
|
201
|
+
503,
|
202
|
+
504
|
202
203
|
].each do |e|
|
203
204
|
|
205
|
+
# binding.pry
|
206
|
+
|
207
|
+
before(:each) do
|
208
|
+
VCR.use_cassette("AMEE_Connection/v2/raising unhandled errors") do
|
209
|
+
@amee.authenticate
|
210
|
+
end
|
211
|
+
|
212
|
+
@error_response = {
|
213
|
+
:status => e,
|
214
|
+
:body => {}
|
215
|
+
}
|
216
|
+
@amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD, :retries => 2)
|
217
|
+
|
218
|
+
end
|
219
|
+
|
204
220
|
it "should retry after #{e} the correct number of times" do
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
mock.should_receive(:finish => nil)
|
210
|
-
end
|
211
|
-
amee = AMEE::Connection.new('server.example.com', 'username', 'password', :retries => 2)
|
221
|
+
|
222
|
+
stub_request(:any, "https://stage.amee.com/data").to_return(:status => e, :body => {}).times(2).
|
223
|
+
then.to_return(:status => 200, :body => {})
|
224
|
+
|
212
225
|
lambda {
|
213
|
-
amee.get('/data')
|
214
|
-
}.should_not raise_error
|
226
|
+
@amee.get('/data')
|
227
|
+
}.should_not raise_error
|
215
228
|
end
|
216
229
|
|
217
230
|
it "should retry #{e} the correct number of times and raise error on failure" do
|
218
|
-
|
219
|
-
|
220
|
-
mock.should_receive(:request).and_return(flexmock(:code => e, :body => '{}')).times(3)
|
221
|
-
mock.should_receive(:finish => nil)
|
222
|
-
end
|
223
|
-
amee = AMEE::Connection.new('server.example.com', 'username', 'password', :retries => 2)
|
231
|
+
|
232
|
+
stub_request(:any, "https://stage.amee.com/data").to_return(@error_response)
|
224
233
|
lambda {
|
225
|
-
amee.get('/data')
|
234
|
+
@amee.get('/data')
|
226
235
|
}.should raise_error(AMEE::ConnectionFailed)
|
227
236
|
end
|
228
|
-
end
|
229
|
-
|
237
|
+
end
|
238
|
+
|
230
239
|
end
|
231
240
|
|
232
241
|
describe AMEE::Connection, "with incorrect server name" do
|
233
242
|
|
243
|
+
use_vcr_cassette
|
234
244
|
it "should raise a useful error" do
|
235
|
-
|
236
|
-
amee = AMEE::Connection.new('badservername.example.com', 'username', 'password')
|
245
|
+
amee = AMEE::Connection.new('badservername.example.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
237
246
|
lambda{
|
238
247
|
amee.get('/')
|
239
248
|
}.should raise_error(AMEE::ConnectionFailed, "Connection failed. Check server name or network connection.")
|
@@ -243,56 +252,88 @@ end
|
|
243
252
|
|
244
253
|
describe AMEE::Connection, "with bad authentication information" do
|
245
254
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
255
|
+
describe "hitting a private url" do
|
256
|
+
use_vcr_cassette
|
257
|
+
it "should get an authentication failure" do
|
258
|
+
amee = AMEE::Connection.new('stage.amee.com', 'wrong', 'details')
|
259
|
+
lambda{
|
260
|
+
amee.get('/data')
|
261
|
+
}.should raise_error(AMEE::AuthFailed, "Authentication failed. Please check your username and password. (tried wrong,details)")
|
262
|
+
end
|
250
263
|
end
|
251
264
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
265
|
+
# according to the docs, public urls should not be accessible without
|
266
|
+
# an api key either
|
267
|
+
# http://www.amee.com/developer/docs/apc.php#auth-reference
|
268
|
+
describe "hitting a public url" do
|
269
|
+
use_vcr_cassette
|
270
|
+
it "should not be capable of making requests for public URLs" do
|
271
|
+
amee = AMEE::Connection.new('stage.amee.com', 'wrong', 'details')
|
272
|
+
lambda{
|
273
|
+
amee.get('/')
|
274
|
+
}.should raise_error
|
275
|
+
end
|
256
276
|
end
|
257
277
|
|
278
|
+
|
279
|
+
|
258
280
|
end
|
259
281
|
|
260
282
|
describe AMEE::Connection, "with authentication , doing write-requests" do
|
261
|
-
|
283
|
+
use_vcr_cassette
|
262
284
|
it "should be able to send post requests" do
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
mock.should_receive(:finish => nil)
|
267
|
-
end
|
268
|
-
amee = AMEE::Connection.new('server.example.com', 'username', 'password')
|
269
|
-
amee.post('/profiles', :test => 1, :test2 => 2) do |response|
|
270
|
-
response.should be_empty
|
285
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
286
|
+
amee.post('/profiles', {:profile => true}) do |response|
|
287
|
+
response.code.should be_200
|
271
288
|
end
|
272
289
|
end
|
273
290
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
end
|
280
|
-
amee = AMEE::Connection.new('server.example.com', 'username', 'password')
|
281
|
-
amee.put('/profiles/ABC123', :test => 1, :test2 => 2) do |response|
|
282
|
-
response.should be_empty
|
283
|
-
end
|
284
|
-
end
|
291
|
+
describe "working with an existing profile" do
|
292
|
+
|
293
|
+
describe "sending updates to existing items" do
|
294
|
+
use_vcr_cassette
|
295
|
+
it "should be possible" do
|
285
296
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
297
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
298
|
+
|
299
|
+
profile_creation_post = amee.post('/profiles', {:profile => true})
|
300
|
+
profile = JSON.parse(profile_creation_post.body)['profile']['uid']
|
301
|
+
|
302
|
+
# fetch the new_item type uid to create
|
303
|
+
new_item_drill = amee.get('/data/test/apitests/drill')
|
304
|
+
new_item_uid = JSON.parse(new_item_drill.body)['choices']['choices'].first['value']
|
305
|
+
# create a new item
|
306
|
+
new_profile = amee.post("/profiles/#{profile}/test/apitests", :dataItemUid => new_item_uid)
|
307
|
+
# update the new item
|
308
|
+
path = new_profile.headers_hash['location'].gsub('https://stage.amee.com', '')
|
309
|
+
amee.put(path, :dataItemUid => new_item_uid) do |response|
|
310
|
+
response.should be_empty
|
311
|
+
end
|
312
|
+
end
|
291
313
|
end
|
292
|
-
|
293
|
-
|
294
|
-
|
314
|
+
|
315
|
+
describe "deleting existing items" do
|
316
|
+
use_vcr_cassette
|
317
|
+
it "should also be possible" do
|
318
|
+
|
319
|
+
amee = AMEE::Connection.new('stage.amee.com', AMEE_V2_API_KEY, AMEE_V2_PASSWORD)
|
320
|
+
profile_creation_post = amee.post('/profiles', {:profile => true})
|
321
|
+
profile = JSON.parse(profile_creation_post.body)['profile']['uid']
|
322
|
+
|
323
|
+
# fetch the new_item type uid to create
|
324
|
+
new_item_drill = amee.get('/data/test/apitests/drill')
|
325
|
+
new_item_uid = JSON.parse(new_item_drill.body)['choices']['choices'].first['value']
|
326
|
+
# create a new item
|
327
|
+
new_profile = amee.post("/profiles/#{profile}/test/apitests", :dataItemUid => new_item_uid)
|
328
|
+
# delete the new item
|
329
|
+
path = new_profile.headers_hash['location'].gsub('https://stage.amee.com', '')
|
330
|
+
amee.delete(path) do |response|
|
331
|
+
response.should be_empty
|
332
|
+
end
|
333
|
+
end
|
295
334
|
end
|
335
|
+
|
336
|
+
|
296
337
|
end
|
297
338
|
|
298
339
|
end
|