class Bespokify::Client

Public Class Methods

new(login, password) click to toggle source
# File lib/bespokify/client.rb, line 23
def initialize(login, password)
  @login = login
  @password = password
  self.class.default_options.merge!(headers: { 'Authorization' => "Bearer #{auth_token}", 'content-type': 'application/json'})
end

Private Instance Methods

auth_token() click to toggle source
# File lib/bespokify/client.rb, line 31
def auth_token
  auth_url = 'https://auth.bespokify.com/auth/realms/platform/protocol/openid-connect/token'
  response = HTTParty.post(auth_url, body: { 'username': @login, 'password': @password, 'grant_type': 'password', 'client_id': 'public-api' }, headers: { 'content-type': 'application/x-www-form-urlencoded' })
  JSON.parse(response.body).dig('access_token')
end