class Snowshoe::Client

Constants

API_VERSION

Attributes

api_key[R]
consumer[R]
response[R]
url[R]

Public Class Methods

new(key, options={}) click to toggle source
# File lib/snowshoe/client.rb, line 5
def initialize(key, options={})
  # Flexiblity for future endpoint uri changes
  api_version = options[:api_version] || API_VERSION
  @url = URI(api_version)

  @consumer = Net::HTTP.new(url.host, url.port);
  consumer.use_ssl = true
  @api_key = key

end

Public Instance Methods

log_error(message) click to toggle source
# File lib/snowshoe/client.rb, line 30
def log_error(message)
  puts "ERROR: #{self.class}: #{message}"
  puts "RESPONSE: #{response.inspect}"
end
post(body) click to toggle source
# File lib/snowshoe/client.rb, line 16
def post(body)
  request = Net::HTTP::Post.new(url)
  request["SnowShoe-Api-Key"] = api_key
  request["Content-Type"] = "application/json"
  request.body = body

  @response = consumer.request(request)
  return JSON.parse(response.read_body)
  
rescue => exception
  log_error(exception.message)
  []
end