Skip to content

Commit 24baf1c

Browse files
committed
🚨 Linting
1 parent 5ef6285 commit 24baf1c

File tree

15 files changed

+102
-98
lines changed

15 files changed

+102
-98
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.
309309
## [0.0.5] - 2010-04-23 ([tag][0.0.5t])
310310

311311
## [0.0.4] - 2010-04-22 ([tag][0.0.4t])
312-
312+
313313
## [0.0.3] - 2010-04-22 ([tag][0.0.3t])
314314

315315
## [0.0.2] - 2010-04-22 ([tag][0.0.2t])

Dangerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
# e.g. github.pr_title.include? "#trivial"
66

77
# Make it more obvious that a PR is a work in progress and shouldn't be merged yet
8-
warn('PR is classed as Work in Progress') if github.pr_title.include? '[WIP]'
8+
warn("PR is classed as Work in Progress") if github.pr_title.include?("[WIP]")
99

1010
# Warn when there is a big PR
11-
warn('Big PR') if git.lines_of_code > 500
11+
warn("Big PR") if git.lines_of_code > 500
1212

1313
# Don't let testing shortcuts get into main by accident
14-
raise('fdescribe left in tests') if `grep -r fdescribe specs/ `.length > 1
15-
raise('fit left in tests') if `grep -r fit specs/ `.length > 1
14+
raise("fdescribe left in tests") if %x(grep -r fdescribe specs/).length > 1
15+
raise("fit left in tests") if %x(grep -r fit specs/).length > 1

lib/oauth2.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
# frozen_string_literal: true
22

33
# includes modules from stdlib
4-
require 'cgi'
5-
require 'time'
4+
require "cgi"
5+
require "time"
66

77
# third party gems
8-
require 'snaky_hash'
9-
require 'version_gem'
8+
require "snaky_hash"
9+
require "version_gem"
1010

1111
# includes gem files
12-
require 'oauth2/version'
13-
require 'oauth2/filtered_attributes'
14-
require 'oauth2/error'
15-
require 'oauth2/authenticator'
16-
require 'oauth2/client'
17-
require 'oauth2/strategy/base'
18-
require 'oauth2/strategy/auth_code'
19-
require 'oauth2/strategy/implicit'
20-
require 'oauth2/strategy/password'
21-
require 'oauth2/strategy/client_credentials'
22-
require 'oauth2/strategy/assertion'
23-
require 'oauth2/access_token'
24-
require 'oauth2/response'
12+
require "oauth2/version"
13+
require "oauth2/filtered_attributes"
14+
require "oauth2/error"
15+
require "oauth2/authenticator"
16+
require "oauth2/client"
17+
require "oauth2/strategy/base"
18+
require "oauth2/strategy/auth_code"
19+
require "oauth2/strategy/implicit"
20+
require "oauth2/strategy/password"
21+
require "oauth2/strategy/client_credentials"
22+
require "oauth2/strategy/assertion"
23+
require "oauth2/access_token"
24+
require "oauth2/response"
2525

2626
# The namespace of this library
2727
module OAuth2

lib/oauth2/access_token.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,21 @@ def initialize(client, token, opts = {})
7676
error = Error.new(opts)
7777
raise(error)
7878
else
79-
warn('OAuth2::AccessToken has no token')
79+
warn("OAuth2::AccessToken has no token")
8080
end
8181
end
8282
# @option opts [Fixnum, String] :expires is deprecated
83-
@expires_in ||= opts.delete('expires')
83+
@expires_in ||= opts.delete("expires")
8484
@expires_in &&= @expires_in.to_i
8585
@expires_at &&= convert_expires_at(@expires_at)
8686
@expires_latency &&= @expires_latency.to_i
8787
@expires_at ||= Time.now.to_i + @expires_in if @expires_in && !@expires_in.zero?
8888
@expires_at -= @expires_latency if @expires_latency
89-
@options = {mode: opts.delete(:mode) || :header,
90-
header_format: opts.delete(:header_format) || 'Bearer %s',
91-
param_name: opts.delete(:param_name) || 'access_token'}
89+
@options = {
90+
mode: opts.delete(:mode) || :header,
91+
header_format: opts.delete(:header_format) || "Bearer %s",
92+
param_name: opts.delete(:param_name) || "access_token",
93+
}
9294
@params = opts
9395
end
9496

@@ -118,9 +120,9 @@ def expired?
118120
# @return [AccessToken] a new AccessToken
119121
# @note options should be carried over to the new AccessToken
120122
def refresh(params = {}, access_token_opts = {})
121-
raise('A refresh_token is not available') unless refresh_token
123+
raise("A refresh_token is not available") unless refresh_token
122124

123-
params[:grant_type] = 'refresh_token'
125+
params[:grant_type] = "refresh_token"
124126
params[:refresh_token] = refresh_token
125127
new_token = @client.get_token(params, access_token_opts)
126128
new_token.options = options
@@ -133,7 +135,7 @@ def refresh(params = {}, access_token_opts = {})
133135
end
134136
# A compatibility alias
135137
# @note does not modify the receiver, so bang is not the default method
136-
alias refresh! refresh
138+
alias_method :refresh!, :refresh
137139

138140
# Convert AccessToken to a hash which can be used to rebuild itself with AccessToken.from_hash
139141
#
@@ -190,7 +192,7 @@ def delete(path, opts = {}, &block)
190192

191193
# Get the headers hash (includes Authorization token)
192194
def headers
193-
{'Authorization' => options[:header_format] % token}
195+
{"Authorization" => options[:header_format] % token}
194196
end
195197

196198
private

lib/oauth2/authenticator.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'base64'
3+
require "base64"
44

55
module OAuth2
66
class Authenticator
@@ -49,16 +49,16 @@ def self.encode_basic_auth(user, password)
4949
# already set.
5050
def apply_params_auth(params)
5151
result = {}
52-
result['client_id'] = id unless id.nil?
53-
result['client_secret'] = secret unless secret.nil?
52+
result["client_id"] = id unless id.nil?
53+
result["client_secret"] = secret unless secret.nil?
5454
result.merge(params)
5555
end
5656

5757
# When using schemes that don't require the client_secret to be passed i.e TLS Client Auth,
5858
# we don't want to send the secret
5959
def apply_client_id(params)
6060
result = {}
61-
result['client_id'] = id unless id.nil?
61+
result["client_id"] = id unless id.nil?
6262
result.merge(params)
6363
end
6464

@@ -72,7 +72,7 @@ def apply_basic_auth(params)
7272

7373
# @see https://datatracker.ietf.org/doc/html/rfc2617#section-2
7474
def basic_auth_header
75-
{'Authorization' => self.class.encode_basic_auth(id, secret)}
75+
{"Authorization" => self.class.encode_basic_auth(id, secret)}
7676
end
7777
end
7878
end

lib/oauth2/client.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# frozen_string_literal: true
22

3-
require 'faraday'
4-
require 'logger'
3+
require "faraday"
4+
require "logger"
55

66
if Faraday::Utils.respond_to?(:default_space_encoding)
77
# This setting doesn't exist in faraday 0.x
8-
Faraday::Utils.default_space_encoding = '%20'
8+
Faraday::Utils.default_space_encoding = "%20"
99
end
1010

1111
module OAuth2
@@ -49,10 +49,10 @@ def initialize(client_id, client_secret, options = {}, &block)
4949
@secret = client_secret
5050
@site = opts.delete(:site)
5151
ssl = opts.delete(:ssl)
52-
warn('OAuth2::Client#initialize argument `extract_access_token` will be removed in oauth2 v3. Refactor to use `access_token_class`.') if opts[:extract_access_token]
52+
warn("OAuth2::Client#initialize argument `extract_access_token` will be removed in oauth2 v3. Refactor to use `access_token_class`.") if opts[:extract_access_token]
5353
@options = {
54-
authorize_url: 'oauth/authorize',
55-
token_url: 'oauth/token',
54+
authorize_url: "oauth/authorize",
55+
token_url: "oauth/token",
5656
token_method: :post,
5757
auth_scheme: :basic_auth,
5858
connection_opts: {},
@@ -81,8 +81,8 @@ def connection
8181
if options[:connection_build]
8282
options[:connection_build].call(builder)
8383
else
84-
builder.request :url_encoded # form-encode POST params
85-
builder.adapter Faraday.default_adapter # make requests with Net::HTTP
84+
builder.request(:url_encoded) # form-encode POST params
85+
builder.adapter(Faraday.default_adapter) # make requests with Net::HTTP
8686
end
8787
end
8888
end
@@ -131,7 +131,7 @@ def request(verb, url, opts = {}, &block)
131131
verb = :get
132132
opts.delete(:body)
133133
end
134-
location = response.headers['location']
134+
location = response.headers["location"]
135135
if location
136136
full_location = response.response.env.url.merge(location)
137137
request(verb, full_location, opts)
@@ -165,7 +165,7 @@ def request(verb, url, opts = {}, &block)
165165
# @yield [req] @see Faraday::Connection#run_request
166166
# @return [AccessToken] the initialized AccessToken
167167
def get_token(params, access_token_opts = {}, extract_access_token = nil, &block)
168-
warn('OAuth2::Client#get_token argument `extract_access_token` will be removed in oauth2 v3. Refactor to use `access_token_class` on #initialize.') if extract_access_token
168+
warn("OAuth2::Client#get_token argument `extract_access_token` will be removed in oauth2 v3. Refactor to use `access_token_class` on #initialize.") if extract_access_token
169169
extract_access_token ||= options[:extract_access_token]
170170
parse, snaky, params, headers = parse_snaky_params_headers(params)
171171

@@ -178,13 +178,13 @@ def get_token(params, access_token_opts = {}, extract_access_token = nil, &block
178178

179179
# NOTE: If proliferation of request types continues we should implement a parser solution for Request,
180180
# just like we have with Response.
181-
request_opts[:body] = if headers['Content-Type'] == 'application/json'
182-
params.to_json
183-
else
184-
params
185-
end
181+
request_opts[:body] = if headers["Content-Type"] == "application/json"
182+
params.to_json
183+
else
184+
params
185+
end
186186

187-
request_opts[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
187+
request_opts[:headers] = {"Content-Type" => "application/x-www-form-urlencoded"}
188188
else
189189
request_opts[:params] = params
190190
request_opts[:headers] = {}
@@ -261,7 +261,7 @@ def assertion
261261
# @return [Hash] the params to add to a request or URL
262262
def redirection_params
263263
if options[:redirect_uri]
264-
{'redirect_uri' => options[:redirect_uri]}
264+
{"redirect_uri" => options[:redirect_uri]}
265265
else
266266
{}
267267
end
@@ -358,7 +358,7 @@ def build_access_token_legacy(response, access_token_opts, extract_access_token)
358358
end
359359

360360
def oauth_debug_logging(builder)
361-
builder.response :logger, options[:logger], bodies: true if ENV['OAUTH_DEBUG'] == 'true'
361+
builder.response(:logger, options[:logger], bodies: true) if ENV["OAUTH_DEBUG"] == "true"
362362
end
363363
end
364364
end

lib/oauth2/error.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ def initialize(response)
1111
@response = response
1212
if response.respond_to?(:parsed)
1313
if response.parsed.is_a?(Hash)
14-
@code = response.parsed['error']
15-
@description = response.parsed['error_description']
14+
@code = response.parsed["error"]
15+
@description = response.parsed["error_description"]
1616
end
1717
elsif response.is_a?(Hash)
18-
@code = response['error']
19-
@description = response['error_description']
18+
@code = response["error"]
19+
@description = response["error_description"]
2020
end
2121
@body = if response.respond_to?(:body)
22-
response.body
23-
else
24-
@response
25-
end
22+
response.body
23+
else
24+
@response
25+
end
2626
message_opts = parse_error_description(@code, @description)
2727
super(error_message(@body, message_opts))
2828
end
@@ -35,11 +35,11 @@ def error_message(response_body, opts = {})
3535
lines << opts[:error_description] if opts[:error_description]
3636

3737
error_string = if response_body.respond_to?(:encode) && opts[:error_description].respond_to?(:encoding)
38-
script_encoding = opts[:error_description].encoding
39-
response_body.encode(script_encoding, invalid: :replace, undef: :replace)
40-
else
41-
response_body
42-
end
38+
script_encoding = opts[:error_description].encoding
39+
response_body.encode(script_encoding, invalid: :replace, undef: :replace)
40+
else
41+
response_body
42+
end
4343

4444
lines << error_string
4545

@@ -49,7 +49,7 @@ def error_message(response_body, opts = {})
4949
def parse_error_description(code, description)
5050
return {} unless code || description
5151

52-
error_description = ''
52+
error_description = ""
5353
error_description += "#{code}: " if code
5454
error_description += description if description
5555

lib/oauth2/filtered_attributes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def inspect
2525
"#{var}=#{instance_variable_get(var).inspect}"
2626
end
2727
end
28-
"#<#{self.class}:#{object_id} #{inspected_vars.join(', ')}>"
28+
"#<#{self.class}:#{object_id} #{inspected_vars.join(", ")}>"
2929
end
3030
end
3131
end

lib/oauth2/response.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

3-
require 'json'
4-
require 'multi_xml'
5-
require 'rack'
3+
require "json"
4+
require "multi_xml"
5+
require "rack"
66

77
module OAuth2
88
# OAuth2::Response class
@@ -23,8 +23,8 @@ class Response
2323

2424
# Content type assignments for various potential HTTP content types.
2525
@@content_types = {
26-
'application/x-www-form-urlencoded' => :query,
27-
'text/plain' => :text,
26+
"application/x-www-form-urlencoded" => :query,
27+
"text/plain" => :text,
2828
}
2929

3030
# Adds a new content type parser.
@@ -68,7 +68,7 @@ def status
6868

6969
# The HTTP response body
7070
def body
71-
response.body || ''
71+
response.body || ""
7272
end
7373

7474
# The {#response} {#body} as parsed by {#parser}.
@@ -97,9 +97,9 @@ def parsed
9797

9898
# Attempts to determine the content type of the response.
9999
def content_type
100-
return nil unless response.headers
100+
return unless response.headers
101101

102-
((response.headers.values_at('content-type', 'Content-Type').compact.first || '').split(';').first || '').strip.downcase
102+
((response.headers.values_at("content-type", "Content-Type").compact.first || "").split(";").first || "").strip.downcase
103103
end
104104

105105
# Determines the parser (a Proc or other Object which responds to #call)
@@ -133,16 +133,16 @@ def parser
133133
end
134134
end
135135

136-
OAuth2::Response.register_parser(:xml, ['text/xml', 'application/rss+xml', 'application/rdf+xml', 'application/atom+xml', 'application/xml']) do |body|
136+
OAuth2::Response.register_parser(:xml, ["text/xml", "application/rss+xml", "application/rdf+xml", "application/atom+xml", "application/xml"]) do |body|
137137
next body unless body.respond_to?(:to_str)
138138

139139
MultiXml.parse(body)
140140
end
141141

142-
OAuth2::Response.register_parser(:json, ['application/json', 'text/javascript', 'application/hal+json', 'application/vnd.collection+json', 'application/vnd.api+json', 'application/problem+json']) do |body|
142+
OAuth2::Response.register_parser(:json, ["application/json", "text/javascript", "application/hal+json", "application/vnd.collection+json", "application/vnd.api+json", "application/problem+json"]) do |body|
143143
next body unless body.respond_to?(:to_str)
144144

145-
body = body.dup.force_encoding(::Encoding::ASCII_8BIT) if body.respond_to?(:force_encoding)
145+
body = body.dup.force_encoding(Encoding::ASCII_8BIT) if body.respond_to?(:force_encoding)
146146

147-
::JSON.parse(body)
147+
JSON.parse(body)
148148
end

0 commit comments

Comments
 (0)