Skip to content

Commit 1c77b47

Browse files
author
Unai Abrisketa
authored
Release v0.18.0.pre
* features * Add new token retrieval/refresh methods * `Token#authorization_code` * `Token#refresh_token` * `Token#client_credentials` * Add alias methods for avoiding deprecation * `refresh` -> `refresh_token` * `create` -> `authorization_code`
1 parent c7ad7f8 commit 1c77b47

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
### v0.18.0.pre
2+
3+
* features
4+
* Add new token retrieval/refresh methods
5+
* `Token#authorization_code`
6+
* `Token#refresh_token`
7+
* `Token#client_credentials`
8+
* Add alias methods for avoiding deprecation
9+
* `refresh` -> `refresh_token`
10+
* `create` -> `authorization_code`
11+
112
### v0.17.0.pre
213

314
* enhancements

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
beyond_api (0.17.0.pre)
4+
beyond_api (0.18.0.pre)
55
faraday (~> 0.15)
66

77
GEM
@@ -52,4 +52,4 @@ DEPENDENCIES
5252
yard (~> 0.9)
5353

5454
BUNDLED WITH
55-
2.1.4
55+
2.2.26

lib/beyond_api/resources/token.rb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,32 @@ def initialize(session)
1717
raise InvalidSessionError.new("Session api_url cannot be nil") if session.api_url.nil?
1818
end
1919

20-
def create(code)
21-
response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
22-
grant_type: "authorization_code",
23-
code: code)
24-
25-
handle_response(response, status)
20+
def authorization_code(code)
21+
handle_token_call("authorization_code", code: code)
2622
end
2723

28-
def refresh
29-
response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
30-
grant_type: "refresh_token",
31-
refresh_token: @session.refresh_token)
32-
33-
handle_response(response, status)
24+
def refresh_token
25+
handle_token_call("refresh_token", refresh_token: @session.refresh_token)
3426
end
3527

3628
def client_credentials
29+
handle_token_call("client_credentials")
30+
end
31+
32+
alias_method :refresh, :refresh_token
33+
alias_method :create, :authorization_code
34+
35+
private
36+
37+
def handle_token_call(grant_type, params = {})
38+
params.merge!(grant_type: grant_type)
39+
3740
response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
38-
grant_type: "client_credentials")
41+
params)
3942

4043
handle_response(response, status)
4144
end
4245

43-
private
44-
4546
def handle_response(response, status)
4647
if status.between?(200, 299)
4748
@session.access_token = response["access_token"]

lib/beyond_api/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module BeyondApi
2-
VERSION = "0.17.0.pre".freeze
2+
VERSION = "0.18.0.pre".freeze
33
end

0 commit comments

Comments
 (0)