Sha256: 6420327398208bc1704293690beaf6ed89b80c53908078a2dbdd6ef46f7e41f2

Contents?: true

Size: 782 Bytes

Versions: 4

Compression:

Stored size: 782 Bytes

Contents

require 'httparty'

module PapertrailRails
  class Request
    @@headers = {}
    @base_uri = "https://papertrailapp.com/api/v1"

    include HTTParty

    def self.get(path, query)
      response = HTTParty.get(append_query_string_to_url(path, query), @@headers)
      check_code(response.code)
      response.parsed_response
    end

    def self.append_query_string_to_url(path, query)
      @base_uri + path + query
    end

    def self.set_default_headers(api_key)
      @@headers = { headers: { 'X-Papertrail-Token' => api_key } } if @@headers.empty?
    end

    def self.check_code(code)
      case code
      when 401
        raise AuthenticationError.new('Api key is missing or invalid')
      end
    end

    class AuthenticationError < StandardError
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
papertrail_rails-0.0.4 lib/papertrail_rails/request.rb
papertrail_rails-0.0.3 lib/papertrail_rails/request.rb
papertrail_rails-0.0.2 lib/papertrail_rails/request.rb
papertrail_rails-0.0.1 lib/papertrail_rails/request.rb