Sha256: 52cf0a64804d14bd5885b20df3a165d96bf0f75527639518d7a7253ffe1f0976

Contents?: true

Size: 1.11 KB

Versions: 30

Compression:

Stored size: 1.11 KB

Contents

module ForestLiana
  class UsersGetter
    def initialize(endpoint, rendering_id)
      @uri = URI.parse("#{forest_url}/forest/renderings/#{rendering_id}/#{endpoint}")
    end

    def perform
      http = Net::HTTP.new(@uri.host, @uri.port)
      http.use_ssl = true if forest_url.start_with?('https')

      begin
        http.start do |client|
          request = Net::HTTP::Get.new(@uri.path)
          request['Content-Type'] = 'application/json'
          request['forest-secret-key'] = ForestLiana.env_secret
          request['forest-token'] = @forest_token if @forest_token
          response = client.request(request)

          handle_service_response(response)
        end
      rescue => exception
        puts exception
        FOREST_LOGGER.error "Cannot retrieve any users for the project " \
          "you\'re trying to unlock. Forest API seems to be down right now."
        nil
      end
    end

    private

    def forest_url
      ENV['FOREST_URL'] || 'https://api.forestadmin.com';
    end

    def handle_service_response
      raise 'Abstract class method, this method must be implemented.'
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
forest_liana-2.7.0 app/services/forest_liana/users_getter.rb
forest_liana-2.6.1 app/services/forest_liana/users_getter.rb
forest_liana-2.6.0 app/services/forest_liana/users_getter.rb
forest_liana-2.5.5 app/services/forest_liana/users_getter.rb
forest_liana-2.5.4 app/services/forest_liana/users_getter.rb
forest_liana-2.5.3 app/services/forest_liana/users_getter.rb
forest_liana-2.5.2 app/services/forest_liana/users_getter.rb
forest_liana-2.5.1 app/services/forest_liana/users_getter.rb
forest_liana-2.5.0 app/services/forest_liana/users_getter.rb
forest_liana-2.4.9 app/services/forest_liana/users_getter.rb
forest_liana-2.4.8 app/services/forest_liana/users_getter.rb
forest_liana-2.4.7 app/services/forest_liana/users_getter.rb
forest_liana-2.4.6 app/services/forest_liana/users_getter.rb
forest_liana-2.4.5 app/services/forest_liana/users_getter.rb
forest_liana-2.4.4 app/services/forest_liana/users_getter.rb
forest_liana-2.4.3 app/services/forest_liana/users_getter.rb
forest_liana-2.4.2 app/services/forest_liana/users_getter.rb
forest_liana-2.4.1 app/services/forest_liana/users_getter.rb
forest_liana-2.4.0 app/services/forest_liana/users_getter.rb
forest_liana-2.3.5 app/services/forest_liana/users_getter.rb