Sha256: 5be9867ac7efcd66bf84f7bb62735b194d3e6ac349c9157119026d8a68041efd

Contents?: true

Size: 995 Bytes

Versions: 86

Compression:

Stored size: 995 Bytes

Contents

require 'httparty'

module ForestLiana
  class ForestApiRequester
    def self.get(route, query: nil, headers: {})
      begin
        HTTParty.get("#{forest_api_url}#{route}", {
          headers: base_headers.merge(headers),
          query: query,
        }).response
      rescue
        raise 'Cannot reach Forest API, it seems to be down right now.'
      end
    end

    def self.post(route, body: nil, query: nil, headers: {})
      begin
        HTTParty.post("#{forest_api_url}#{route}", {
          headers: base_headers.merge(headers),
          query: query,
          body: body.to_json,
        }).response
      rescue
        raise 'Cannot reach Forest API, it seems to be down right now.'
      end
    end

    private

    def self.base_headers
      {
        'Content-Type' => 'application/json',
        'forest-secret-key' => ForestLiana.env_secret,
      }
    end

    def self.forest_api_url
      ENV['FOREST_URL'] || 'https://api.forestadmin.com'
    end
  end
end

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
forest_liana-5.4.4 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.4.3 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.4.2 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.4.1 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.4.0 app/services/forest_liana/forest_api_requester.rb
forest_liana-6.0.0.pre.beta.1 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.3.3 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.3.2 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.3.1 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.3.0 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.2.3 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.2.2 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.2.1 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.2.0 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.1.3 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.1.2 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.1.1 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.1.0 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.0.0 app/services/forest_liana/forest_api_requester.rb
forest_liana-5.0.0.pre.beta.0 app/services/forest_liana/forest_api_requester.rb