class TenThousandFeet::Client

Attributes

api_url[R]
auth[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/ten_thousand_feet/client.rb, line 28
def initialize(options = {})
  @auth = options[:auth]
  @api_url = options[:api_url] || 'https://api.10000ft.com/api/v1'
end

Public Instance Methods

default_options() click to toggle source
# File lib/ten_thousand_feet/client.rb, line 33
def default_options
  { auth: @auth }
end
delete(path, options = {}) click to toggle source
# File lib/ten_thousand_feet/client.rb, line 78
def delete(path, options = {})
  RestClient.delete(full_url(path, default_options), options)
end
full_url(path, options = {}) click to toggle source
# File lib/ten_thousand_feet/client.rb, line 52
def full_url(path, options = {})
  if options.empty?
    api_url + path
  else
    api_url + path + query_string(options)
  end
end
get(path, options = {}) click to toggle source
# File lib/ten_thousand_feet/client.rb, line 60
def get(path, options = {})
  response = RestClient.get(full_url(path), params: default_options.merge(options))

  JSON.parse(response)
end
post(path, options = {}) click to toggle source
# File lib/ten_thousand_feet/client.rb, line 66
def post(path, options = {})
  response = RestClient.post(full_url(path, default_options), options)

  JSON.parse(response)
end
put(path, options = {}) click to toggle source
# File lib/ten_thousand_feet/client.rb, line 72
def put(path, options = {})
  response = RestClient.put(full_url(path, default_options), options)

  JSON.parse(response)
end
query_string(options) click to toggle source
# File lib/ten_thousand_feet/client.rb, line 37
def query_string(options)
  nodes  = (options.count - 1)
  params = '?'

  options.each_with_index do |(key, value), index|
    if index == nodes
      params += "#{key}=#{URI.encode(value)}"
    else
      params += "#{key}=#{URI.encode(value)}&"
    end
  end

  params
end