class Okapi::Client

Public Class Methods

new(url = nil, tenant = nil, token = nil) click to toggle source
# File lib/okapi.rb, line 11
def initialize(url = nil, tenant = nil, token = nil)
  @url, @tenant, @token = url, tenant, token
end

Public Instance Methods

delete(path) click to toggle source
# File lib/okapi.rb, line 45
def delete(path)
  request(:delete, path, nil, 'Accept' => 'text/plain')
end
get(path) { |json, response| ... } click to toggle source
# File lib/okapi.rb, line 23
def get(path)
  request(:get, path) do |response|
    json = JSON.parse(response.body)
    if block_given?
      yield json, response
    else
      json
    end
  end
end
headers() click to toggle source
# File lib/okapi.rb, line 66
def headers
  {'Content-Type' => 'application/json', 'Accept' => 'application/json'}
end
post(path, body) { |json, response| ... } click to toggle source
# File lib/okapi.rb, line 34
def post(path, body)
  request(:post, path, JSON.generate(body)) do |response|
    json = JSON.parse(response.body)
    if block_given?
      yield json, response
    else
      json
    end
  end
end
request(verb, path, body = nil, header_overrides = {}) { |response| ... } click to toggle source
# File lib/okapi.rb, line 49
def request(verb, path, body = nil, header_overrides = {})
  http = Net::HTTP.new(url.host, url.port)
  if url.scheme == "https"
    http.use_ssl = true
  end
  http.start do
    args = [body].compact
    response = http.send(verb, path, *args, headers.merge(header_overrides))
    RequestError.maybe_fail! response
    if block_given?
      yield response
    else
      response
    end
  end
end
settings() click to toggle source
# File lib/okapi.rb, line 15
def settings
  Settings.new(@url, @tenant, @token)
end
tenant() click to toggle source
# File lib/okapi.rb, line 70
def tenant
  Tenant.new(@url, @tenant, @token)
end
url() click to toggle source
# File lib/okapi.rb, line 19
def url
  settings.url
end
user() click to toggle source
# File lib/okapi.rb, line 74
def user
  User.new(@url, @tenant, @token)
end