Skip to content

Commit 20a5f2b

Browse files
committed
📝 Documentation updates
1 parent f204c7b commit 20a5f2b

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

.rubocop_gradual.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"lib/oauth2.rb:4176768025": [
77
[38, 11, 7, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 651502127]
88
],
9-
"lib/oauth2/access_token.rb:569882683": [
9+
"lib/oauth2/access_token.rb:3471244990": [
1010
[49, 13, 5, "Style/IdenticalConditionalBranches: Move `t_key` out of the conditional.", 183811513],
1111
[55, 13, 5, "Style/IdenticalConditionalBranches: Move `t_key` out of the conditional.", 183811513]
1212
],

lib/oauth2/access_token.rb

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,24 @@ def expires?
164164
!!@expires_at
165165
end
166166

167-
# Whether the token is expired
167+
# Check if token is expired
168168
#
169-
# @return [Boolean]
169+
# @return [Boolean] true if the token is expired, false otherwise
170170
def expired?
171171
expires? && (expires_at <= Time.now.to_i)
172172
end
173173

174174
# Refreshes the current Access Token
175175
#
176-
# @return [AccessToken] a new AccessToken
177-
# @note options should be carried over to the new AccessToken
176+
# @param [Hash] params additional params to pass to the refresh token request
177+
# @param [Hash] access_token_opts options that will be passed to the AccessToken initialization
178+
#
179+
# @yield [opts] The block to modify the refresh token request options
180+
# @yieldparam [Hash] opts The options hash that can be modified
181+
#
182+
# @return [OAuth2::AccessToken] a new AccessToken instance
183+
#
184+
# @note current token's options are carried over to the new AccessToken
178185
def refresh(params = {}, access_token_opts = {}, &block)
179186
raise OAuth2::Error.new({error: "A refresh_token is not available"}) unless refresh_token
180187

@@ -282,7 +289,16 @@ def to_hash
282289
# @param [Symbol] verb the HTTP request method
283290
# @param [String] path the HTTP URL path of the request
284291
# @param [Hash] opts the options to make the request with
285-
# @see Client#request
292+
# @option opts [Hash] :params additional URL parameters
293+
# @option opts [Hash, String] :body the request body
294+
# @option opts [Hash] :headers request headers
295+
#
296+
# @yield [req] The block to modify the request
297+
# @yieldparam [Faraday::Request] req The request object that can be modified
298+
#
299+
# @return [OAuth2::Response] the response from the request
300+
#
301+
# @see OAuth2::Client#request
286302
def request(verb, path, opts = {}, &block)
287303
configure_authentication!(opts)
288304
@client.request(verb, path, opts, &block)

lib/oauth2/client.rb

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,16 @@ def initialize(client_id, client_secret, options = {}, &block)
7272

7373
# Set the site host
7474
#
75-
# @param value [String] the OAuth2 provider site host
75+
# @param [String] value the OAuth2 provider site host
76+
# @return [String] the site host value
7677
def site=(value)
7778
@connection = nil
7879
@site = value
7980
end
8081

8182
# The Faraday connection object
83+
#
84+
# @return [Faraday::Connection] the initialized Faraday connection
8285
def connection
8386
@connection ||=
8487
Faraday.new(site, options[:connection_opts]) do |builder|
@@ -95,32 +98,36 @@ def connection
9598
# The authorize endpoint URL of the OAuth2 provider
9699
#
97100
# @param [Hash] params additional query parameters
101+
# @return [String] the constructed authorize URL
98102
def authorize_url(params = {})
99103
params = (params || {}).merge(redirection_params)
100104
connection.build_url(options[:authorize_url], params).to_s
101105
end
102106

103107
# The token endpoint URL of the OAuth2 provider
104108
#
105-
# @param [Hash] params additional query parameters
109+
# @param [Hash, nil] params additional query parameters
110+
# @return [String] the constructed token URL
106111
def token_url(params = nil)
107112
connection.build_url(options[:token_url], params).to_s
108113
end
109114

110115
# The revoke endpoint URL of the OAuth2 provider
111116
#
112-
# @param [Hash] params additional query parameters
117+
# @param [Hash, nil] params additional query parameters
118+
# @return [String] the constructed revoke URL
113119
def revoke_url(params = nil)
114120
connection.build_url(options[:revoke_url], params).to_s
115121
end
116122

117123
# Makes a request relative to the specified site root.
124+
#
118125
# Updated HTTP 1.1 specification (IETF RFC 7231) relaxed the original constraint (IETF RFC 2616),
119126
# allowing the use of relative URLs in Location headers.
120127
#
121128
# @see https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.2
122129
#
123-
# @param [Symbol] verb one of :get, :post, :put, :delete
130+
# @param [Symbol] verb one of [:get, :post, :put, :delete]
124131
# @param [String] url URL path of request
125132
# @param [Hash] opts the options to make the request with
126133
# @option req_opts [Hash] :params additional query parameters for the URL of the request
@@ -129,9 +136,13 @@ def revoke_url(params = nil)
129136
# @option req_opts [Boolean] :raise_errors whether to raise an OAuth2::Error on 400+ status
130137
# code response for this request. Overrides the client instance setting.
131138
# @option req_opts [Symbol] :parse @see Response::initialize
132-
# @option req_opts [true, false] :snaky (true) @see Response::initialize
139+
# @option req_opts [Boolean] :snaky (true) @see Response::initialize
133140
#
134-
# @yield [req] @see Faraday::Connection#run_request
141+
# @yield [req] The block is passed the request being made, allowing customization
142+
# @yieldparam [Faraday::Request] req The request object that can be modified
143+
# @see Faraday::Connection#run_request
144+
#
145+
# @return [OAuth2::Response] the response from the request
135146
def request(verb, url, req_opts = {}, &block)
136147
response = execute_request(verb, url, req_opts, &block)
137148
status = response.status
@@ -532,4 +543,4 @@ def oauth_debug_logging(builder)
532543
builder.response(:logger, options[:logger], bodies: true) if OAuth2::OAUTH_DEBUG
533544
end
534545
end
535-
end
546+
end

0 commit comments

Comments
 (0)