Skip to content

Commit 7f7b8f6

Browse files
committed
style(tokenManager): remove underscores before method definitions
1 parent f439002 commit 7f7b8f6

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

lib/ibm_watson/iam_token_manager.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ def token
5959
return @user_access_token unless @user_access_token.nil? || (@user_access_token.respond_to?(:empty?) && @user_access_token.empty?)
6060

6161
if @token_info.all? { |_k, v| v.nil? }
62-
token_info = _request_token
63-
_save_token_info(
62+
token_info = request_token
63+
save_token_info(
6464
token_info: token_info
6565
)
6666
return @token_info["access_token"]
67-
elsif _is_token_expired?
68-
token_info = _is_refresh_token_expired? ? _request_token : _refresh_token
69-
_save_token_info(
67+
elsif token_expired?
68+
token_info = refresh_token_expired? ? request_token : refresh_token
69+
save_token_info(
7070
token_info: token_info
7171
)
7272
return @token_info["access_token"]
@@ -78,7 +78,7 @@ def token
7878
private
7979

8080
# Request an IAM token using an API key
81-
def _request_token
81+
def request_token
8282
headers = {
8383
"Content-Type" => CONTENT_TYPE,
8484
"Authorization" => DEFAULT_AUTHORIZATION,
@@ -99,7 +99,7 @@ def _request_token
9999
end
100100

101101
# Refresh an IAM token using a refresh token
102-
def _refresh_token
102+
def refresh_token
103103
headers = {
104104
"Content-Type" => CONTENT_TYPE,
105105
"Authorization" => DEFAULT_AUTHORIZATION,
@@ -122,7 +122,7 @@ def _refresh_token
122122
# Using a buffer to prevent the edge case of the
123123
# token expiring before the request could be made.
124124
# The buffer will be a fraction of the total TTL. Using 80%.
125-
def _is_token_expired?
125+
def token_expired?
126126
return true if @token_info["expiration"].nil? || @token_info["expires_in"].nil?
127127

128128
fraction_of_ttl = 0.8
@@ -136,7 +136,7 @@ def _is_token_expired?
136136
# Used as a fail-safe to prevent the condition of a refresh token expiring,
137137
# which could happen after around 30 days. This function will return true
138138
# if it has been at least 7 days and 1 hour since the last token was set
139-
def _is_refresh_token_expired?
139+
def refresh_token_expired?
140140
return true if @token_info["expiration"].nil?
141141

142142
seven_days = 7 * 24 * 3600
@@ -146,7 +146,7 @@ def _is_refresh_token_expired?
146146
end
147147

148148
# Save the response from the IAM service request to the object's state
149-
def _save_token_info(token_info:)
149+
def save_token_info(token_info:)
150150
@token_info = token_info
151151
end
152152
end

lib/ibm_watson/watson_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def initialize(vars)
6161
end
6262

6363
if !vars[:iam_access_token].nil? || !vars[:iam_apikey].nil?
64-
_token_manager(iam_apikey: vars[:iam_apikey], iam_access_token: vars[:iam_access_token], iam_url: vars[:iam_url])
64+
set_token_manager(iam_apikey: vars[:iam_apikey], iam_access_token: vars[:iam_access_token], iam_url: vars[:iam_url])
6565
elsif !vars[:username].nil? && !vars[:password].nil?
6666
if vars[:username] == "apikey" && !@icp_prefix
6767
iam_apikey(iam_apikey: vars[:password])
@@ -188,7 +188,7 @@ def configure_http_client(proxy: {}, timeout: {})
188188

189189
private
190190

191-
def _token_manager(iam_apikey: nil, iam_access_token: nil, iam_url: nil)
191+
def set_token_manager(iam_apikey: nil, iam_access_token: nil, iam_url: nil)
192192
@iam_apikey = iam_apikey
193193
@iam_access_token = iam_access_token
194194
@iam_url = iam_url

test/unit/test_iam_token_manager.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_request_token
3333
"Host" => "iam.bluemix.net"
3434
}
3535
).to_return(status: 200, body: response.to_json, headers: {})
36-
token_response = token_manager.send(:_request_token)
36+
token_response = token_manager.send(:request_token)
3737
assert_equal(response, token_response)
3838
end
3939

@@ -61,7 +61,7 @@ def test_refresh_token
6161
"Host" => "iam.bluemix.net"
6262
}
6363
).to_return(status: 200, body: response.to_json, headers: {})
64-
token_response = token_manager.send(:_refresh_token)
64+
token_response = token_manager.send(:refresh_token)
6565
assert_equal(response, token_response)
6666
end
6767

@@ -79,9 +79,9 @@ def test_is_token_expired
7979
"refresh_token" => "jy4gl91BQ"
8080
}
8181

82-
refute(token_manager.send(:_is_token_expired?))
82+
refute(token_manager.send(:token_expired?))
8383
token_manager.token_info["expiration"] = Time.now.to_i - 3600
84-
assert(token_manager.send(:_is_token_expired?))
84+
assert(token_manager.send(:token_expired?))
8585
end
8686

8787
def test_is_refresh_token_expired
@@ -98,9 +98,9 @@ def test_is_refresh_token_expired
9898
"refresh_token" => "jy4gl91BQ"
9999
}
100100

101-
refute(token_manager.send(:_is_refresh_token_expired?))
101+
refute(token_manager.send(:refresh_token_expired?))
102102
token_manager.token_info["expiration"] = Time.now.to_i - (8 * 24 * 3600)
103-
assert(token_manager.send(:_is_token_expired?))
103+
assert(token_manager.send(:token_expired?))
104104
end
105105

106106
def test_get_token

0 commit comments

Comments
 (0)