Class: ForestLiana::AuthorizationGetter

Inherits:
Object
  • Object
show all
Defined in:
app/services/forest_liana/authorization_getter.rb

Class Method Summary collapse

Class Method Details

.authenticate(rendering_id, auth_data) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/forest_liana/authorization_getter.rb', line 3

def self.authenticate(rendering_id, auth_data)
  begin
    route = "/liana/v2/renderings/#{rendering_id.to_s}/authorization"
    headers = { 'forest-token' => auth_data[:forest_token] }

    response = ForestLiana::ForestApiRequester
      .get(route, query: {}, headers: headers)

    if response.code.to_i == 200
      body = JSON.parse(response.body, :symbolize_names => false)
      user = body['data']['attributes']
      user['id'] = body['data']['id']
      user
    else
      raise generate_authentication_error response
    end
  end
end