Sha256: 0b060d317fb7050a2a89fd78d06c5039de28cac489155b25563b82b380d8ed78

Contents?: true

Size: 1.31 KB

Versions: 148

Compression:

Stored size: 1.31 KB

Contents

require 'httparty'

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

    def self.post(route, body: nil, query: nil, headers: {})
      begin
        if route.start_with?('https://')
          post_route = route
        else
          post_route = "#{forest_api_url}#{route}"
        end

        HTTParty.post(post_route, {
          :verify => Rails.env.production?,
          headers: base_headers.merge(headers),
          query: query,
          body: body.to_json,
        }).response
      rescue
        raise "Cannot reach Forest API at #{post_route}, it seems to be down right now."
      end
    end

    private

    def self.base_headers
      base_headers = {
        'Content-Type' => 'application/json',
      }
      base_headers['forest-secret-key'] = ForestLiana.env_secret if !ForestLiana.env_secret.nil?
      return base_headers
    end

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

Version data entries

148 entries across 148 versions & 1 rubygems

Version Path
forest_liana-9.6.0 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.5.7 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.5.6 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.5.5 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.5.4 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.5.3 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.5.2 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.5.1 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.5.0 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.4.3 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.4.2 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.4.1 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.4.0 app/services/forest_liana/forest_api_requester.rb
forest_liana-8.3.3 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.3.16 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.3.15 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.3.14 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.3.13 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.3.12 app/services/forest_liana/forest_api_requester.rb
forest_liana-9.3.11 app/services/forest_liana/forest_api_requester.rb