module Geekbot::Connection

Public Instance Methods

connection() click to toggle source
# File lib/geekbot/connection.rb, line 5
def connection
  @connection ||= Faraday.new(faraday_options) do |conn|
    conn.request :json
    conn.response :json
    conn.adapter Faraday.default_adapter
  end
end

Private Instance Methods

access_token() click to toggle source
# File lib/geekbot/connection.rb, line 39
def access_token
  @access_token ||= ENV['GEEKBOT_ACCESS_TOKEN']
end
api_endpoint() click to toggle source
# File lib/geekbot/connection.rb, line 29
def api_endpoint
  @api_endpoint ||= ENV['GEEKBOT_API_ENDPOINT'] || 'https://api.geekbot.io'
end
default_headers() click to toggle source
# File lib/geekbot/connection.rb, line 22
def default_headers
  {
    'Accept' => 'application/json',
    'User-Agent' => "Geekbot Ruby Gem #{Geekbot::VERSION}"
  }
end
faraday_headers() click to toggle source
# File lib/geekbot/connection.rb, line 33
def faraday_headers
  return default_headers unless access_token

  default_headers.merge(Authorization: access_token.to_s)
end
faraday_options() click to toggle source
# File lib/geekbot/connection.rb, line 15
def faraday_options
  {
    url: api_endpoint,
    headers: faraday_headers
  }
end