class MarkusRESTfulAPI

Public Class Methods

configure(api_url, auth_key) click to toggle source

Stores the api_url and auth_key for later use

# File lib/tools/api_wrapper/api_wrapper.rb, line 8
def MarkusRESTfulAPI.configure(api_url, auth_key)
  @@auth_key = auth_key
  api_url = "#{api_url}/" if api_url[-1, 1] != '/'
  @@api_url = api_url
end
delete(url) click to toggle source

Makes a DELETE request to the provided URL while supplying the authorization header, and raising an exception on failure

# File lib/tools/api_wrapper/api_wrapper.rb, line 48
def MarkusRESTfulAPI.delete(url)
  response = HTTParty.delete(@@api_url + url, :headers =>
    { 'Authorization' => "MarkUsAuth #{@@auth_key}", 'Accept' => 'application/json' })
  puts response
  raise "#{response['code']}: #{response['description']}" unless response.success?

  response
end
get(url) click to toggle source

Makes a GET request to the provided URL while supplying the authorization header, and raising an exception on failure

# File lib/tools/api_wrapper/api_wrapper.rb, line 16
def MarkusRESTfulAPI.get(url)
  response = HTTParty.get(@@api_url + url, :headers =>
    { 'Authorization' => "MarkUsAuth #{@@auth_key}", 'Accept' => 'application/json' })
  raise "#{response['code']}: #{response['description']}" unless response.success?

  response
end
post(url, query) click to toggle source

Makes a POST request to the provided URL, along with the supplied POST data. Also uses the authorization header, and raises an exception on failure

# File lib/tools/api_wrapper/api_wrapper.rb, line 26
def MarkusRESTfulAPI.post(url, query)
  options = { :headers => { 'Authorization' => "MarkUsAuth #{@@auth_key}",
              'Accept' => 'application/json' }, :body => query }
  response = HTTParty.post(@@api_url + url, options)
  raise "#{response['code']}: #{response['description']}" unless response.success?

  response
end
put(url, query) click to toggle source

Makes a PUT request to the provided URL, along with the supplied data. Also uses the authorization header, and raises an exception on failure

# File lib/tools/api_wrapper/api_wrapper.rb, line 37
def MarkusRESTfulAPI.put(url, query)
  options = { :headers => { 'Authorization' => "MarkUsAuth #{@@auth_key}",
              'Accept' => 'application/json' }, :body => query }
  response = HTTParty.put(@@api_url + url, options)
  raise "#{response['code']}: #{response['description']}" unless response.success?

  response
end