Class: InceApi::CreateAccessToken
- Inherits:
-
Object
- Object
- InceApi::CreateAccessToken
- Defined in:
- lib/ince_api/create_access_token.rb
Constant Summary collapse
- URL =
URI("https://api.1nce.com/management-api/oauth/token")
Instance Method Summary collapse
- #connection ⇒ Object
- #create_token ⇒ Object
- #encoded_credentials ⇒ Object
-
#initialize(username:, password:) ⇒ CreateAccessToken
constructor
A new instance of CreateAccessToken.
- #request ⇒ Object
Constructor Details
#initialize(username:, password:) ⇒ CreateAccessToken
Returns a new instance of CreateAccessToken.
5 6 7 8 |
# File 'lib/ince_api/create_access_token.rb', line 5 def initialize(username:, password:) @username = username @password = password end |
Instance Method Details
#connection ⇒ Object
26 27 28 29 30 |
# File 'lib/ince_api/create_access_token.rb', line 26 def connection @connection ||= Net::HTTP.new(URL.host, URL.port).tap do |http| http.use_ssl = true end end |
#create_token ⇒ Object
12 13 14 15 |
# File 'lib/ince_api/create_access_token.rb', line 12 def create_token response = connection.request(request) JSON.parse(response.body) end |
#encoded_credentials ⇒ Object
32 33 34 |
# File 'lib/ince_api/create_access_token.rb', line 32 def encoded_credentials Base64.encode64("#{@username}:#{@password}").strip end |
#request ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/ince_api/create_access_token.rb', line 17 def request Net::HTTP::Post.new(URL).tap do |request| request["Accept"] = 'application/json' request["Content-Type"] = 'application/x-www-form-urlencoded' request["Authorization"] = "Basic #{encoded_credentials}" request.body = "grant_type=client_credentials" end end |