Skip to content

Commit

Permalink
use httprb
Browse files Browse the repository at this point in the history
  • Loading branch information
phoet committed Jun 13, 2018
1 parent baa4a78 commit d30f368
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 81 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.0

* use the http.rb gem instead of HTTPI adapter

## 2.0.2

* changes from Hashie::Rash to Hashie::SCHash, because Hashie added its own Rash class that conflicted with the Rash gem.
Expand Down
96 changes: 54 additions & 42 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,64 @@ PATH
confiture (>= 0.1)
crack (>= 0.3)
hashie (>= 1.1)
httpi (>= 0.9)
http (>= 3.0)
snake_case_hash (>= 1.0.2)

GEM
remote: http://rubygems.org/
specs:
addressable (2.3.2)
byebug (3.5.1)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
slop (~> 3.6)
codeclimate-test-reporter (0.3.0)
simplecov (>= 0.7.1, < 1.0.0)
columnize (0.8.9)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
byebug (10.0.2)
codeclimate-test-reporter (1.0.8)
simplecov (<= 0.13)
confiture (0.1.4)
crack (0.3.1)
debugger-linecache (1.2.0)
diff-lcs (1.2.5)
docile (1.1.3)
hashie (3.4.3)
httpclient (2.3.0.1)
httpi (2.4.1)
rack
multi_json (1.10.0)
rack (1.6.4)
rake (0.9.2.2)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
docile (1.1.5)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)
hashdiff (0.3.7)
hashie (3.5.7)
http (3.3.0)
addressable (~> 2.3)
http-cookie (~> 1.0)
http-form_data (~> 2.0)
http_parser.rb (~> 0.6.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
http-form_data (2.1.1)
http_parser.rb (0.6.0)
json (2.1.0)
public_suffix (3.0.2)
rake (0.9.6)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-collection_matchers (1.1.3)
rspec-expectations (>= 2.99.0.beta1)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
simplecov (0.8.2)
rspec-mocks (2.99.4)
safe_yaml (1.0.4)
simplecov (0.13.0)
docile (~> 1.1.0)
multi_json
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
slop (3.6.0)
snake_case_hash (1.0.2)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
snake_case_hash (1.0.4)
hashie (~> 3.0)
vcr (2.2.5)
webmock (1.8.11)
addressable (>= 2.2.7)
crack (>= 0.1.7)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
vcr (4.0.0)
webmock (3.4.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff

PLATFORMS
java
Expand All @@ -60,11 +72,11 @@ DEPENDENCIES
asin!
byebug
codeclimate-test-reporter
httpclient (>= 2.2.3)
rake (~> 0.9.2)
rake (~> 0.9)
rspec (~> 2.11)
vcr (~> 2.2)
webmock (~> 1.8)
rspec-collection_matchers (~> 1.1)
vcr (~> 4.0)
webmock (~> 3.4)

BUNDLED WITH
1.11.2
1.16.1
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ It's also a good starting point for looking into writing your own asin-adapter.

```bash
gem install asin
gem install curb # optional, see HTTPI
```

or in your Gemfile:

```ruby
gem 'asin'
gem 'curb' # optional, see HTTPI
```

## Configuration
Expand Down Expand Up @@ -138,16 +136,6 @@ node.first.name
# => 'Literature & Fiction'
```

## HTTPI

ASIN uses [HTTPI](https://github.com/rubiii/httpi) as a HTTP-Client adapter.
See the HTTPI documentation for how to configure different clients or the logger.
As a default HTTPI uses _httpclient_ so you should add that dependency to your project:

```ruby
gem 'httpclient'
```

## Confiture

ASIN uses [Confiture](https://github.com/phoet/confiture) as a Configuration gem.
Expand Down
15 changes: 6 additions & 9 deletions asin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ Gem::Specification.new do |s|
s.add_dependency('crack', '>= 0.3')
s.add_dependency('hashie', '>= 1.1')
s.add_dependency('snake_case_hash', '>= 1.0.2')
s.add_dependency('httpi', '>= 0.9')
s.add_dependency('http', '>= 3.0')
s.add_dependency('confiture', '>= 0.1')

s.add_runtime_dependency('jruby-openssl') if RUBY_PLATFORM == 'java'

s.add_development_dependency('httpclient', '>= 2.2.3')

s.add_development_dependency('rake', '~> 0.9.2')
s.add_development_dependency('vcr', '~> 2.2')
s.add_development_dependency('webmock', '~> 1.8')
s.add_development_dependency('rspec', '~> 2.11')
s.add_development_dependency('rake', '~> 0.9')
s.add_development_dependency('vcr', '~> 4.0')
s.add_development_dependency('webmock', '~> 3.4')
s.add_development_dependency('rspec', '~> 2.11')
s.add_development_dependency('rspec-collection_matchers', '~> 1.1')
end
2 changes: 1 addition & 1 deletion lib/asin/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def label
end

def language
item_attributes!.languages.language.first.name
item_attributes!.languages.language.first['Name']
end

def formatted_price
Expand Down
4 changes: 2 additions & 2 deletions lib/asin/client.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'httpi'
require 'http'
require 'rexml/document' # https://github.com/phoet/asin/pull/23
require 'crack/xml'
require 'cgi'
Expand Down Expand Up @@ -252,7 +252,7 @@ def call(params)
url = "http://#{Configuration.host}#{PATH}?#{signed}"
log(:info, "performing rest call to url='#{url}'")

response = HTTPI.get(url)
response = HTTP.get(url)
if response.code == 200
# force utf-8 chars, works only on 1.9 string
resp = response.body
Expand Down
18 changes: 9 additions & 9 deletions spec/lib/cart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module ASIN

it "should create a cart", :vcr do
cart = @helper.create_cart({:asin => ANY_ASIN, :quantity => 1}, {:asin => ANY_OTHER_ASIN, :quantity => 2})
expect(cart.valid?).to be_true
expect(cart.empty?).to be_false
expect(cart.valid?).to be_truthy
expect(cart.empty?).to be_falsey
end

it "should handle item paramters" do
Expand All @@ -25,22 +25,22 @@ module ASIN
it "should clear a cart", :vcr do
@cart = @helper.create_cart({:asin => ANY_ASIN, :quantity => 1})
cart = @helper.clear_cart(@cart)
expect(cart.valid?).to be_true
expect(cart.empty?).to be_true
expect(cart.valid?).to be_truthy
expect(cart.empty?).to be_truthy
end

it "should get a cart", :vcr do
@cart = @helper.create_cart({:asin => ANY_ASIN, :quantity => 1})
cart = @helper.get_cart(@cart.cart_id, @cart.hmac)
expect(cart.valid?).to be_true
expect(cart.empty?).to be_false
expect(cart.valid?).to be_truthy
expect(cart.empty?).to be_falsey
end

it "should add items to a cart", :vcr do
@cart = @helper.create_cart({:asin => ANY_ASIN, :quantity => 1})
cart = @helper.add_items(@cart, {:asin => ANY_OTHER_ASIN, :quantity => 2})
expect(cart.valid?).to be_true
expect(cart.empty?).to be_false
expect(cart.valid?).to be_truthy
expect(cart.empty?).to be_falsey
expect(cart).to have(2).items
end

Expand All @@ -49,7 +49,7 @@ module ASIN
item_id = @cart.items.first.cart_item_id
cart = @helper.update_items(@cart, {:cart_item_id => item_id, :action => 'SaveForLater'}, {:cart_item_id => item_id, :quantity => 7})
expect(cart).to have(1).saved_items
expect(cart.valid?).to be_true
expect(cart.valid?).to be_truthy
end

end
Expand Down
8 changes: 2 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ class Net::HTTPSession < Net::HTTP::HTTPSession; end
end

require 'rspec'
require 'rspec/collection_matchers'
require 'asin'
require 'asin/client' # is somehow needed for jruby
require 'asin/adapter'
require 'httpclient'
require 'vcr'
require 'httpi'

require 'byebug'

VCR.configure do |config|
config.cassette_library_dir = 'spec/cassettes'
Expand All @@ -43,8 +41,6 @@ class Net::HTTPSession < Net::HTTP::HTTPSession; end
end

config.before :each do
HTTPI.log = false

ASIN::Configuration.reset!
@helper = ASIN::Client.instance
@helper.configure :logger => nil
Expand Down

0 comments on commit d30f368

Please sign in to comment.