Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ orbs:
defaults: &defaults
notify_failure: false

ruby_2_7_defaults: &ruby_2_7_defaults
<<: *defaults
e:
name: ruby/ruby
ruby-version: '2.7'

ruby_3_0_defaults: &ruby_3_0_defaults
<<: *defaults
e:
Expand All @@ -31,21 +25,14 @@ ruby_3_2_defaults: &ruby_3_2_defaults
name: ruby/ruby
ruby-version: '3.2'

ruby_3_4_defaults: &ruby_3_4_defaults
<<: *defaults
e:
name: ruby/ruby
ruby-version: '3.4'

workflows:
version: 2
ruby_2_7:
jobs:
- ruby/bundle-audit:
<<: *ruby_2_7_defaults
name: ruby-2_7-bundle_audit
- ruby/rubocop:
<<: *ruby_2_7_defaults
name: ruby-2_7-rubocop
- ruby/rspec-unit:
<<: *ruby_2_7_defaults
name: ruby-2_7-rspec_unit
db: false
code-climate: false
ruby_3_0:
jobs:
- ruby/bundle-audit:
Expand Down Expand Up @@ -84,3 +71,16 @@ workflows:
name: ruby-3_2-rspec_unit
db: false
code-climate: false
ruby_3_4:
jobs:
- ruby/bundle-audit:
<<: *ruby_3_4_defaults
name: ruby-3_4-bundle_audit
- ruby/rubocop:
<<: *ruby_3_4_defaults
name: ruby-3_4-rubocop
- ruby/rspec-unit:
<<: *ruby_3_4_defaults
name: ruby-3_4-rspec_unit
db: false
code-climate: false
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Your contribution here.

* [#000](https://github.com/bigcommerce/bigcommerce-api-ruby/pull/000): Brief description here. - [@username](https://github.com/username).

## 2.0.0

* [#186](https://github.com/bigcommerce/bigcommerce-api-ruby/pull/186): Update to Faraday 2.14 and add support for Ruby 3.4 - [@markcmurphy](https://github.com/markcmurphy).

## 1.1.0
* [#174](https://github.com/bigcommerce/bigcommerce-api-ruby/pull/174): Drop support for ruby 2.6; Add support for Ruby 3.2 - [@j05h](https://github.com/j05h).

Expand Down
2 changes: 1 addition & 1 deletion DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
Many thanks to the contributors and authors of the following libraries!

- [Faraday](https://github.com/lostisland/faraday) Simple, but flexible HTTP client library, with support for multiple backends. - [MIT](https://github.com/lostisland/faraday/blob/master/LICENSE.md)
- [Faraday Middleware](https://github.com/lostisland/faraday_middleware) Various Faraday middlewares for Faraday-based API wrappers. - [MIT](https://github.com/lostisland/faraday_middleware/blob/master/LICENSE.md)
- [Faraday Gzip](https://github.com/bodrovis/faraday-gzip) Gzip request and response compression middleware for Faraday. - [MIT](https://github.com/bodrovis/faraday-gzip/blob/main/LICENSE.txt)
- [Hashie](https://github.com/intridea/hashie) Hashie is a collection of classes and mixins that make hashes more powerful. - [MIT](https://github.com/intridea/hashie/blob/master/LICENSE)
- [JWT](https://github.com/jwt/ruby-jwt) Used to encode and sign JWT tokens for the Customer Login API. - [MIT](https://github.com/jwt/ruby-jwt/blob/master/LICENSE)
4 changes: 2 additions & 2 deletions bigcommerce.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Gem::Specification.new do |s|
s.require_paths = ['lib']
s.files = Dir['README.md', 'lib/**/*', 'bigcommerce.gemspec']

s.add_dependency 'faraday', '~> 1.1.0'
s.add_dependency 'faraday_middleware', '~> 1.0'
s.add_dependency 'faraday', '>= 2.14', '< 3.0'
s.add_dependency 'faraday-gzip', '~> 3.0'
s.add_dependency 'hashie', '>= 3.4', '~> 4'
s.add_dependency 'jwt', '>= 1.5.4', '~> 2'
end
3 changes: 2 additions & 1 deletion lib/bigcommerce.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

require 'hashie'
require 'faraday_middleware'
require 'faraday'
require 'faraday/gzip'
require_relative 'bigcommerce/version'
require_relative 'bigcommerce/config'
require_relative 'bigcommerce/connection'
Expand Down
4 changes: 2 additions & 2 deletions lib/bigcommerce/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def self.build(config)
conn.request :json
conn.headers = HEADERS
if config.auth == LEGACY_AUTH_MODE
conn.use Faraday::Request::BasicAuthentication, config.username, config.api_key
conn.request :authorization, :basic, config.username, config.api_key
else
conn.use Bigcommerce::Middleware::Auth, config
end
conn.request :gzip
conn.use Bigcommerce::Middleware::HttpException
conn.use FaradayMiddleware::Gzip
conn.adapter Faraday.default_adapter
end
end
Expand Down
18 changes: 10 additions & 8 deletions lib/bigcommerce/middleware/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ class Auth < Faraday::Middleware
X_AUTH_CLIENT_HEADER = 'X-Auth-Client'
X_AUTH_TOKEN_HEADER = 'X-Auth-Token'

def initialize(app, options = {})
@app = app
@options = options
super(app)
end

def call(env)
env[:request_headers][X_AUTH_CLIENT_HEADER] = @options[:client_id]
env[:request_headers][X_AUTH_TOKEN_HEADER] = @options[:access_token]
env[:request_headers][X_AUTH_CLIENT_HEADER] = option_value(:client_id)
env[:request_headers][X_AUTH_TOKEN_HEADER] = option_value(:access_token)
@app.call env
end

private

def option_value(key)
return @options[key] if @options.key?(key)

@options[key.to_s]
end
end
end
end
8 changes: 7 additions & 1 deletion lib/bigcommerce/middleware/http_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@

module Bigcommerce
module Middleware
class HttpException < Faraday::Response::Middleware
class HttpException < Faraday::Middleware
include Bigcommerce::HttpErrors

def call(env)
@app.call(env).on_complete do |response_env|
on_complete(response_env)
end
end

def on_complete(env)
throw_http_exception! env[:status].to_i, env
env
Expand Down
2 changes: 1 addition & 1 deletion lib/bigcommerce/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def raw_request(method, path, params = {})
private

def build_response_object(response)
json = parse response.body
json = parse(response.body)
if json.is_a? Array
json.map { |obj| new obj }
else
Expand Down
2 changes: 1 addition & 1 deletion lib/bigcommerce/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Bigcommerce
VERSION = '1.1.0'
VERSION = '2.0.0'
end
12 changes: 10 additions & 2 deletions spec/bigcommerce/bigcommerce_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
end

it 'should have the correct auth middleware' do
expect(middleware).to include(Faraday::Request::BasicAuthentication)
expect(middleware).to include(Faraday::Request::Authorization)
end

it 'should include gzip middleware' do
expect(middleware.map(&:klass)).to include(Faraday::Gzip::Middleware)
end
end

Expand All @@ -42,6 +46,10 @@
it 'should have the correct auth middleware' do
expect(middleware).to include(Bigcommerce::Middleware::Auth)
end

it 'should include gzip middleware' do
expect(middleware.map(&:klass)).to include(Faraday::Gzip::Middleware)
end
end
end

Expand All @@ -61,7 +69,7 @@

expect(Bigcommerce.api.instance_variable_get('@builder')
.instance_variable_get('@handlers'))
.to include(Faraday::Request::BasicAuthentication)
.to include(Faraday::Request::Authorization)

Bigcommerce.configure do |config|
config.access_token = 'jksdgkjbhksjdb'
Expand Down
20 changes: 20 additions & 0 deletions spec/bigcommerce/unit/middleware/auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,25 @@
expect(app).to receive(:call).with(expected_hash)
subject
end

context 'when options use string keys' do
let(:options) do
{
'client_id' => client_id,
'access_token' => client_token
}
end

it 'sets the correct headers' do
expected_hash = {
request_headers: {
'X-Auth-Client' => client_id,
'X-Auth-Token' => client_token
}
}
expect(app).to receive(:call).with(expected_hash)
subject
end
end
end
end