Skip to content

Commit

Permalink
SDK-119 Replace NET-HTTP with Typhoeus
Browse files Browse the repository at this point in the history
Typhoeus uses libcurl, has a good API and
mocking library built into it.
  • Loading branch information
mrchrisadams committed Nov 25, 2011
1 parent 7ca1d16 commit 30128ba
Show file tree
Hide file tree
Showing 16 changed files with 1,104 additions and 244 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Expand Up @@ -16,3 +16,7 @@ gem 'memcache-client', :group => :development
gem 'rcov', :group => :development
gem 'rdoc', :group => :development
gem 'activerecord', ">= 2.3.11", :group => :development
gem 'vcr', :group => :development
gem 'fakeweb', :group => :development
gem 'pry', :group => :development
gem 'pry-doc', :group => :development
11 changes: 11 additions & 0 deletions amee_test_credentials.example.yml
@@ -0,0 +1,11 @@
# we use VCR to store the real responses and store them in source
# control, and test against those when developing
# you'll need to copy this file to run tests, in case you need to test
# against 'fresh' responses from the platform

v1:
api_key: amee_ruby_vcr_version_1
password: replace_me_with_a_real_password
v2:
api_key: amee_ruby_vcr_version_2
password: replace_me_with_a_real_password
30 changes: 30 additions & 0 deletions cassettes/AMEE_Connection_with_authentication/handling_404s.yml
@@ -0,0 +1,30 @@
---
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :get
uri: https://stage.amee.com:443/missing_url
body:
headers:
accept:
- application/json
cookie:
- authToken=
response: !ruby/struct:VCR::Response
status: !ruby/struct:VCR::ResponseStatus
code: 404
message: Not Found
headers:
via:
- 1.1 stage.amee.com
content-type:
- application/json; charset=UTF-8
server:
- Noelios-Restlet-Engine/1.1.10
date:
- Wed, 23 Nov 2011 10:28:28 GMT
content-length:
- "190"
set-cookie:
- authToken=; Path=/; Expires=Wednesday, 23-Nov-11 10:28:28 GMT
body: "{\"status\":{\"description\":\"The server has not found anything matching the request URI\",\"name\":\"Not Found\",\"code\":404,\"uri\":\"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5\"}}"
http_version: "1.1"
104 changes: 104 additions & 0 deletions cassettes/AMEE_Connection_with_authentication/hitting_private_urls.yml
@@ -0,0 +1,104 @@
---
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :get
uri: https://stage.amee.com:443/data
body:
headers:
accept:
- application/json
cookie:
- authToken=
response: !ruby/struct:VCR::Response
status: !ruby/struct:VCR::ResponseStatus
code: 401
message: Unauthorized
headers:
via:
- 1.1 stage.amee.com
content-type:
- application/json; charset=UTF-8
server:
- Noelios-Restlet-Engine/1.1.10
date:
- Wed, 23 Nov 2011 10:28:28 GMT
content-length:
- "175"
body: "{\"status\":{\"description\":\"The request requires user authentication\",\"name\":\"Unauthorized\",\"code\":401,\"uri\":\"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2\"}}"
http_version: "1.1"
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :post
uri: https://stage.amee.com:443/auth/signIn
body: username=<AMEE_V2_API_KEY>&password=<AMEE_V2_PASSWORD>
headers:
accept:
- application/xml
response: !ruby/struct:VCR::Response
status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
headers:
last-modified:
- Wed, 23 Nov 2011 10:28:28 GMT
expires:
- Tue, 22 Nov 2011 10:28:28 GMT
via:
- 1.1 stage.amee.com
content-type:
- application/xml; charset=UTF-8
server:
- Noelios-Restlet-Engine/1.1.10
date:
- Wed, 23 Nov 2011 10:28:28 GMT
set-cookie:
- authToken=xQrp8iVwmp6k1cNz816NOoqY7c3eHsR6KvQx4Wd7gqZ9MkecLSiqHgTeW2RXtwhF9IlBK/XY5Wd0hRylKqcy9vn0wGKV9Vh+cAdKVTNkYXM=; Path=/
authtoken:
- xQrp8iVwmp6k1cNz816NOoqY7c3eHsR6KvQx4Wd7gqZ9MkecLSiqHgTeW2RXtwhF9IlBK/XY5Wd0hRylKqcy9vn0wGKV9Vh+cAdKVTNkYXM=
vary:
- Accept-Charset,Accept-Encoding,Accept-Language,Accept
transfer-encoding:
- chunked
body: <?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources><SignInResource><Next>/auth</Next><User uid="58F26PHHLFEB"><Status>ACTIVE</Status><Type>STANDARD</Type><ApiVersion>2.0</ApiVersion><Locale>en_GB</Locale><TimeZone>UTC</TimeZone></User></SignInResource></Resources>
http_version: "1.1"
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :get
uri: https://stage.amee.com:443/data
body:
headers:
accept:
- application/json
cookie:
- authToken=xQrp8iVwmp6k1cNz816NOoqY7c3eHsR6KvQx4Wd7gqZ9MkecLSiqHgTeW2RXtwhF9IlBK/XY5Wd0hRylKqcy9vn0wGKV9Vh+cAdKVTNkYXM=
authtoken:
- xQrp8iVwmp6k1cNz816NOoqY7c3eHsR6KvQx4Wd7gqZ9MkecLSiqHgTeW2RXtwhF9IlBK/XY5Wd0hRylKqcy9vn0wGKV9Vh+cAdKVTNkYXM=
host:
- stage.amee.com
response: !ruby/struct:VCR::Response
status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
headers:
last-modified:
- Wed, 23 Nov 2011 10:28:28 GMT
expires:
- Tue, 22 Nov 2011 10:28:28 GMT
via:
- 1.1 stage.amee.com
content-type:
- application/json; charset=UTF-8
server:
- Noelios-Restlet-Engine/1.1.10
date:
- Wed, 23 Nov 2011 10:28:28 GMT
content-length:
- "1041"
set-cookie:
- authToken=xQrp8iVwmp6k1cNz816NOoqY7c3eHsR6KvQx4Wd7gqZ9MkecLSiqHgTeW2RXtwhF9IlBK/XY5Wd0hRylKqcy9vn0wGKV9Vh+cAdKVTNkYXM=; Path=/
authtoken:
- xQrp8iVwmp6k1cNz816NOoqY7c3eHsR6KvQx4Wd7gqZ9MkecLSiqHgTeW2RXtwhF9IlBK/XY5Wd0hRylKqcy9vn0wGKV9Vh+cAdKVTNkYXM=
vary:
- Accept-Charset,Accept-Encoding,Accept-Language,Accept
body: "{\"apiVersion\":\"2.0\",\"dataCategory\":{\"uid\":\"CD310BEBAC52\",\"deprecated\":false,\"environment\":{\"uid\":\"5F5887BCF726\",\"itemsPerFeed\":10,\"description\":\"\",\"name\":\"AMEE\",\"owner\":\"\",\"path\":\"\",\"itemsPerPage\":10},\"created\":\"2007-07-27 07:30:44.0\",\"name\":\"Root\",\"path\":\"\",\"modified\":\"2007-07-27 07:30:44.0\"},\"path\":\"\",\"children\":{\"pager\":{},\"dataItems\":{},\"dataCategories\":[{\"uid\":\"99B121BB416C\",\"name\":\"Business\",\"path\":\"business\"},{\"uid\":\"Q9G5P7ZIZXYX\",\"name\":\"Documentation\",\"path\":\"documentation\"},{\"uid\":\"15AC6CF74915\",\"name\":\"Embodied\",\"path\":\"embodied\"},{\"uid\":\"BBA3AC3E795E\",\"name\":\"Home\",\"path\":\"home\"},{\"uid\":\"85A9172C31AF\",\"name\":\"Import\",\"path\":\"import\"},{\"uid\":\"U1X3EBU9QQ2K\",\"name\":\"LCA\",\"path\":\"lca\"},{\"uid\":\"9E5362EAB0E7\",\"name\":\"Metadata\",\"path\":\"metadata\"},{\"uid\":\"A0CF90F6C0B9\",\"name\":\"Personal\",\"path\":\"personal\"},{\"uid\":\"6FF29F7DACDA\",\"name\":\"Planet\",\"path\":\"planet\"},{\"uid\":\"6153F468BE05\",\"name\":\"Test\",\"path\":\"test\"},{\"uid\":\"263FC0186834\",\"name\":\"Transport\",\"path\":\"transport\"},{\"uid\":\"2957AE9B6E6B\",\"name\":\"User\",\"path\":\"user\"}]}}"
http_version: "1.1"
@@ -0,0 +1,98 @@
---
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :get
uri: https://stage.amee.com:443/data/lca/ecoinvent
body:
headers:
accept:
- application/json
cookie:
- authToken=
response: !ruby/struct:VCR::Response
status: !ruby/struct:VCR::ResponseStatus
code: 401
message: Unauthorized
headers:
via:
- 1.1 stage.amee.com
content-type:
- application/json; charset=UTF-8
server:
- Noelios-Restlet-Engine/1.1.10
date:
- Wed, 23 Nov 2011 10:28:28 GMT
content-length:
- "175"
body: "{\"status\":{\"description\":\"The request requires user authentication\",\"name\":\"Unauthorized\",\"code\":401,\"uri\":\"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2\"}}"
http_version: "1.1"
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :post
uri: https://stage.amee.com:443/auth/signIn
body: username=<AMEE_V2_API_KEY>&password=<AMEE_V2_PASSWORD>
headers:
accept:
- application/xml
response: !ruby/struct:VCR::Response
status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
headers:
last-modified:
- Wed, 23 Nov 2011 10:28:29 GMT
expires:
- Tue, 22 Nov 2011 10:28:29 GMT
via:
- 1.1 stage.amee.com
content-type:
- application/xml; charset=UTF-8
server:
- Noelios-Restlet-Engine/1.1.10
date:
- Wed, 23 Nov 2011 10:28:29 GMT
set-cookie:
- authToken=5o7xNfwD7LmfT3jSK0T1LOakYU1P5OXnZclw/a/g5JfKkwbnVgcxcxHfNs2XauLc2WvCRxXjfHgjxpDuQGMkTQ24kdCb72sha4tYetGoGNA=; Path=/
authtoken:
- 5o7xNfwD7LmfT3jSK0T1LOakYU1P5OXnZclw/a/g5JfKkwbnVgcxcxHfNs2XauLc2WvCRxXjfHgjxpDuQGMkTQ24kdCb72sha4tYetGoGNA=
vary:
- Accept-Charset,Accept-Encoding,Accept-Language,Accept
transfer-encoding:
- chunked
body: <?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources><SignInResource><Next>/auth</Next><User uid="58F26PHHLFEB"><Status>ACTIVE</Status><Type>STANDARD</Type><ApiVersion>2.0</ApiVersion><Locale>en_GB</Locale><TimeZone>UTC</TimeZone></User></SignInResource></Resources>
http_version: "1.1"
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :get
uri: https://stage.amee.com:443/data/lca/ecoinvent
body:
headers:
accept:
- application/json
cookie:
- authToken=5o7xNfwD7LmfT3jSK0T1LOakYU1P5OXnZclw/a/g5JfKkwbnVgcxcxHfNs2XauLc2WvCRxXjfHgjxpDuQGMkTQ24kdCb72sha4tYetGoGNA=
authtoken:
- 5o7xNfwD7LmfT3jSK0T1LOakYU1P5OXnZclw/a/g5JfKkwbnVgcxcxHfNs2XauLc2WvCRxXjfHgjxpDuQGMkTQ24kdCb72sha4tYetGoGNA=
host:
- stage.amee.com
response: !ruby/struct:VCR::Response
status: !ruby/struct:VCR::ResponseStatus
code: 403
message: Forbidden
headers:
via:
- 1.1 stage.amee.com
content-type:
- application/json; charset=UTF-8
server:
- Noelios-Restlet-Engine/1.1.10
date:
- Wed, 23 Nov 2011 10:28:29 GMT
content-length:
- "132"
set-cookie:
- authToken=5o7xNfwD7LmfT3jSK0T1LOakYU1P5OXnZclw/a/g5JfKkwbnVgcxcxHfNs2XauLc2WvCRxXjfHgjxpDuQGMkTQ24kdCb72sha4tYetGoGNA=; Path=/
authtoken:
- 5o7xNfwD7LmfT3jSK0T1LOakYU1P5OXnZclw/a/g5JfKkwbnVgcxcxHfNs2XauLc2WvCRxXjfHgjxpDuQGMkTQ24kdCb72sha4tYetGoGNA=
body: "{\"status\":{\"description\":\"\",\"name\":\"Forbidden\",\"code\":403,\"uri\":\"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4\"}}"
http_version: "1.1"
@@ -0,0 +1,36 @@
---
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :post
uri: https://stage.amee.com:443/auth/signIn
body: username=<AMEE_V2_API_KEY>&password=<AMEE_V2_PASSWORD>
headers:
accept:
- application/xml
response: !ruby/struct:VCR::Response
status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
headers:
last-modified:
- Wed, 23 Nov 2011 10:28:28 GMT
expires:
- Tue, 22 Nov 2011 10:28:28 GMT
via:
- 1.1 stage.amee.com
content-type:
- application/xml; charset=UTF-8
server:
- Noelios-Restlet-Engine/1.1.10
date:
- Wed, 23 Nov 2011 10:28:28 GMT
set-cookie:
- authToken=8ciHISUw9AUe74YY0Q3ptsWlTWNR9588lKj9tHSPzRF3ir0iQFRG6qdqLkqEsigHpMPB1647bQFXZ9AD9qCy+lLkMMz8BOxVnfnahYX3ntg=; Path=/
authtoken:
- 8ciHISUw9AUe74YY0Q3ptsWlTWNR9588lKj9tHSPzRF3ir0iQFRG6qdqLkqEsigHpMPB1647bQFXZ9AD9qCy+lLkMMz8BOxVnfnahYX3ntg=
vary:
- Accept-Charset,Accept-Encoding,Accept-Language,Accept
transfer-encoding:
- chunked
body: <?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources><SignInResource><Next>/auth</Next><User uid="58F26PHHLFEB"><Status>ACTIVE</Status><Type>STANDARD</Type><ApiVersion>2.0</ApiVersion><Locale>en_GB</Locale><TimeZone>UTC</TimeZone></User></SignInResource></Resources>
http_version: "1.1"

0 comments on commit 30128ba

Please sign in to comment.