Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change how Faraday does auth #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion ecwid_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"

spec.add_dependency "faraday", "~> 2.7.4"
spec.add_dependency "faraday", ">= 2.7.4"
end
2 changes: 1 addition & 1 deletion lib/ecwid_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# the default client.
#
module EcwidApi
# require_relative "ecwid_api/o_auth"
require_relative "ecwid_api/authentication"
require_relative "ecwid_api/client"
require_relative "ecwid_api/error"
require_relative "ecwid_api/api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module EcwidApi
# token.access_token
# token.store_id # these are what you need to access the API
#
class OAuth
class Authentication
CONFIG = %w(client_id client_secret scope redirect_uri)
attr_accessor *CONFIG

Expand Down
4 changes: 2 additions & 2 deletions lib/ecwid_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Client
extend Forwardable

# The default base URL for the Ecwid API
DEFAULT_URL = "https://app.ecwid.com/"
DEFAULT_URL = "https://app.ecwid.com"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trailing slash in the DEFAULT_URL is causing a double slash to be in the url, which faraday does not like.


# Public: Returns the Ecwid Store ID
attr_reader :store_id
Expand All @@ -32,7 +32,7 @@ def initialize(store_id, token, options={})
options[:adapter] ||= Faraday.default_adapter
@store_id, @token, @adapter = store_id, token, options[:adapter]

@connection = Faraday.new(url: store_url(uri_base: options[:uri_base]), params: { token: @token }) do |conn|
@connection = Faraday.new(url: store_url(uri_base: options[:uri_base]), headers: { 'Authorization' => "Bearer #{@token}" }) do |conn|
# conn.request :oauth2, token, param_name: :token, token_type: :param
conn.request :json
conn.response :json
Expand Down
1 change: 0 additions & 1 deletion lib/ecwid_api/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def initialize(response)

def get_response_info(response)
url = response.env.url
url.query = url.query.sub(/token=[^&]*/, 'token=**SECRET**')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer have the token, aka query, set as we put token in the headers now.

message = "url: #{url}, response (#{response.status})\n#{response.body}"
if response.respond_to?(:reason_phrase)
message = "#{response.reason_phrase} #{message}"
Expand Down
6 changes: 3 additions & 3 deletions spec/oauth_spec.rb → spec/authentication_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'

describe EcwidApi::OAuth do
describe EcwidApi::Authentication do
subject do
EcwidApi::OAuth.new do |config|
EcwidApi::Authentication.new do |config|
config.client_id = "client_id"
config.client_secret = "client_secret"
config.scope = "scope"
Expand Down Expand Up @@ -37,4 +37,4 @@
subject.access_token("code").store_id.should == "12345"
end
end
end
end