Class: ForestLiana::PermissionsGetter

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

Instance Method Summary collapse

Constructor Details

#initialize(rendering_id) ⇒ PermissionsGetter

Returns a new instance of PermissionsGetter.



3
4
5
6
# File 'app/services/forest_liana/permissions_getter.rb', line 3

def initialize(rendering_id)
  @route = "/liana/v2/permissions"
  @rendering_id = rendering_id
end

Instance Method Details

#performObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/forest_liana/permissions_getter.rb', line 8

def perform
  begin
    query_parameters = { 'renderingId' => @rendering_id }
    response = ForestLiana::ForestApiRequester.get(@route, query: query_parameters)

    if response.is_a?(Net::HTTPOK)
      JSON.parse(response.body)
    else
      raise "Forest API returned an #{ForestLiana::Errors::HTTPErrorHelper.format(response)}"
    end
  rescue => exception
    FOREST_LOGGER.error 'Cannot retrieve the permissions from the Forest server.'
    FOREST_LOGGER.error 'Which was caused by:'
    ForestLiana::Errors::ExceptionHelper.recursively_print(exception, margin: ' ', is_error: true)
    nil
  end
end