class Mkmapi::Agent

Attributes

last[R]

Public Instance Methods

delete(path) click to toggle source
# File lib/mkmapi/agent.rb, line 20
def delete(path)
  raise NotImplementedError
end
get(path, query_params = {}) click to toggle source
# File lib/mkmapi/agent.rb, line 8
def get(path, query_params = {})
  process(:get, path, query_params)
end
post(path, body) click to toggle source
# File lib/mkmapi/agent.rb, line 16
def post(path, body)
  raise NotImplementedError
end
put(path, body) click to toggle source
# File lib/mkmapi/agent.rb, line 12
def put(path, body)
  raise NotImplementedError
end

Private Instance Methods

oauth(method, url, options = {}, query = {}) click to toggle source
# File lib/mkmapi/agent.rb, line 34
def oauth(method, url, options = {}, query = {})
  url_with_params = url
  if (query.present?)
    url_with_params = url + "?" + query.to_query
  end
  header = SimpleOAuth::Header.new(method, url_with_params, options, auth)

  signed_attributes = { realm: url }.update(header.signed_attributes)
  attributes = signed_attributes.map { |(k, v)| %(#{k}="#{v}") }

  "OAuth #{attributes * ", "}"
end
process(method, path, query_params = {}) click to toggle source
# File lib/mkmapi/agent.rb, line 26
def process(method, path, query_params = {})
  json_path = "output.json/#{path}"
  endpoint = connection.url_prefix.to_s + "/" + json_path

  @last = connection.send(method, json_path, query_params, authorization: oauth(method, endpoint, {}, query_params))
  Oj.load(@last.body)
end