class Bidsketch::API

Constants

BASE_URL

Public Class Methods

get(path, options = {}) click to toggle source
# File lib/bidsketch/api.rb, line 9
def get(path, options = {})
  url = api_url(path)
  if options[:params]
    url += "&#{querify(options[:params])}"
  end

  headers = { authorization: "Token token=#{Bidsketch.api_key}" }
  normalize_response RestClient.get(url, headers)
end

Private Class Methods

api_url(path) click to toggle source
# File lib/bidsketch/api.rb, line 26
def api_url(path)
  "#{BASE_URL}#{tokenize(path)}"
end
normalize_response(response) click to toggle source
# File lib/bidsketch/api.rb, line 22
def normalize_response(response)
  JSON.parse(response)
end
querify(hash) click to toggle source
# File lib/bidsketch/api.rb, line 30
def querify(hash)
  hash.map { |k, v| "#{k}=#{v}".to_s }.join('&')
end
tokenize(path) click to toggle source
# File lib/bidsketch/api.rb, line 34
def tokenize(path)
  param_separator = path.include?('?') ? '&' : '?'
  path += "#{param_separator}token=#{Bidsketch.api_key}"
end