Skip to content

Commit

Permalink
s/oauth_access_token/access_token
Browse files Browse the repository at this point in the history
The access token can come from OAuth or a manual generation.
  • Loading branch information
weppos committed Dec 16, 2015
1 parent 75c6fe6 commit 3fb1b43
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
22 changes: 10 additions & 12 deletions lib/dnsimple/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Client

HEADER_2FA_STRICT = "X-DNSimple-2FA-Strict"
HEADER_DOMAIN_API_TOKEN = "X-DNSimple-Domain-Token"
HEADER_OAUTH_ACCESS_TOKEN = "Authorization"
HEADER_AUTHORIZATION = "Authorization"


# @return [String] The current API version.
Expand All @@ -30,25 +30,23 @@ def self.versioned(path)
# @!attribute api_endpoint
# @return [String] Base URL for API requests. (default: https://api.dnsimple.com/)
# @!attribute username
# @see https://developer.dnsimple.com/v2/#authentication
# @return [String] DNSimple username for Basic Authentication
# @!attribute password
# @see http://developer.dnsimple.com/authentication/
# @see https://developer.dnsimple.com/v2/#authentication
# @return [String] DNSimple password for Basic Authentication
# @!attribute domain_api_token
# @see http://developer.dnsimple.com/authentication/
# @see https://developer.dnsimple.com/v2/#authentication
# @return [String] Domain API access token for authentication
# @!attribute access_token
# @see https://developer.dnsimple.com/v2/#authentication
# @return [String] Domain API access token for authentication
# @!attribute oauth_client_id
# @see http://developer.dnsimple.com/authentication/
# @return [String] OAuth client id for authentication
# @!attribute oauth_client_secret
# @see http://developer.dnsimple.com/authentication/
# @return [String] OAuth client secret for authentication
# @!attribute user_agent
# @return [String] Configure User-Agent header for requests.
# @!attribute proxy
# @return [String,nil] Configure address:port values for proxy server

attr_accessor :api_endpoint, :username, :password, :domain_api_token, :oauth_access_token,
attr_accessor :api_endpoint, :username, :password, :domain_api_token, :access_token,
:oauth_client_id, :oauth_client_secret, :user_agent, :proxy


Expand Down Expand Up @@ -198,8 +196,8 @@ def base_options
options[:basic_auth] = { username: username, password: password }
elsif domain_api_token
options[:headers][HEADER_DOMAIN_API_TOKEN] = domain_api_token
elsif oauth_access_token
options[:headers][HEADER_OAUTH_ACCESS_TOKEN] = "Bearer #{oauth_access_token}"
elsif access_token
options[:headers][HEADER_AUTHORIZATION] = "Bearer #{access_token}"
else
raise Error, 'A password, domain API token or OAuth access token is required for all API requests.'
end
Expand Down
8 changes: 4 additions & 4 deletions lib/dnsimple/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def keys
:username,
:password,
:domain_api_token,
:oauth_access_token,
:access_token,
:oauth_client_id,
:oauth_client_secret,
:user_agent,
Expand Down Expand Up @@ -57,10 +57,10 @@ def domain_api_token
ENV['DNSIMPLE_API_DOMAIN_TOKEN']
end

# Default DNSimple OAuth access token for OAuth authentication from ENV
# Default DNSimple access token for OAuth authentication from ENV
# @return [String]
def oauth_access_token
ENV['DNSIMPLE_OAUTH_ACCESS_TOKEN']
def access_token
ENV['DNSIMPLE_ACCESS_TOKEN']
end

# Default DNSimple OAuth client ID for OAuth authentication from ENV
Expand Down
2 changes: 1 addition & 1 deletion spec/dnsimple/client/domains_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Dnsimple::Client, ".domains" do

subject { described_class.new(api_endpoint: "https://api.dnsimple.test", oauth_access_token: "a1b2c3").domains }
subject { described_class.new(api_endpoint: "https://api.dnsimple.test", access_token: "a1b2c3").domains }


describe "#domains" do
Expand Down
12 changes: 6 additions & 6 deletions spec/dnsimple/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
expect(subject.oauth_client_secret).to eq("secret")
end

it "access :oauth_access_token option" do
subject = described_class.new(oauth_access_token: "token")
expect(subject.oauth_access_token).to eq("token")
it "access :access_token option" do
subject = described_class.new(access_token: "token")
expect(subject.access_token).to eq("token")
end

it "normalizes :api_endpoint trailing slash" do
Expand Down Expand Up @@ -50,10 +50,10 @@
with { |req| req.headers["X-Dnsimple-Domain-Token"] == "domaintoken" }
end

it "uses OAuth access token if there's an access token provided" do
it "uses access token if there's an access token provided" do
stub_request(:any, %r[/test])

subject = described_class.new(oauth_access_token: "access-token")
subject = described_class.new(access_token: "access-token")
subject.execute(:get, "test", {})

expect(WebMock).to have_requested(:get, "https://api.dnsimple.com/test").
Expand Down Expand Up @@ -152,7 +152,7 @@
end

describe "#paginate" do
subject { described_class.new(api_endpoint: "https://api.example.com/", oauth_access_token: "a1b2c3") }
subject { described_class.new(api_endpoint: "https://api.example.com/", access_token: "a1b2c3") }

service_class = Class.new(Dnsimple::Client::ClientService) do
Item = Class.new(Dnsimple::Struct::Base) do
Expand Down

0 comments on commit 3fb1b43

Please sign in to comment.