class BeautydateApi::APIConsumer
Public Instance Methods
authenticate(token)
click to toggle source
# File lib/beautydate_api/api_consumer.rb, line 4 def authenticate token request = { method: 'POST', url: "#{BeautydateApi.base_uri}/consumers/auth", timeout: 30, headers: { user_agent: "BeautyDate/#{BeautydateApi::VERSION}; Ruby Client", content_type: 'application/vnd.api+json' }, payload: { data: { type: 'consumers', attributes: { uuid: token } } }.to_json } result = JSON.parse(RestClient::Request.execute request) @bearer_key = result.dig('data', 'attributes', 'token') @expires_at = result.dig('data', 'attributes', 'token_expires_at') true rescue raise AuthenticationException end
authenticated?()
click to toggle source
# File lib/beautydate_api/api_consumer.rb, line 30 def authenticated? @bearer_key.present? end
bearer()
click to toggle source
# File lib/beautydate_api/api_consumer.rb, line 38 def bearer "Bearer #{@bearer_key}" end
valid?()
click to toggle source
# File lib/beautydate_api/api_consumer.rb, line 34 def valid? authenticated? and Time.now <= Time.at(@expires_at) end