Class: Horoshop::Authorization

Inherits:
Base
  • Object
show all
Defined in:
lib/horoshop/authorization.rb

Overview

Class for user authorization

Constant Summary collapse

AUTH_URL =
'/api/auth/'
EXPIRATION_TIME =
600

Constants included from Connection

Connection::ERROR

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Connection

#connection, #mixin_token!, #post

Constructor Details

This class inherits a constructor from Horoshop::Base

Instance Method Details

#authorizeObject



11
12
13
14
15
16
17
18
# File 'lib/horoshop/authorization.rb', line 11

def authorize
  response = post(horoshop: horoshop, url: AUTH_URL, body: body)
  return response unless response['status'] == 'OK'

  horoshop.token = response.dig('response', 'token')
  horoshop.expiration_timestamp = Time.now + EXPIRATION_TIME
  response
end