class Rbvore::Link

Attributes

href[RW]
type[RW]

Public Class Methods

new(hash) click to toggle source
# File lib/rbvore/link.rb, line 9
def initialize(hash)
  self.href = hash["href"]
  self.type = hash["type"]
end

Public Instance Methods

api() click to toggle source
# File lib/rbvore/link.rb, line 26
def api
  @api ||= API.new
end
fetch(api_key: nil, params: {}) click to toggle source
# File lib/rbvore/link.rb, line 30
def fetch(api_key: nil, params: {})
  response = api.request(
    :get,
    href,
    params: params,
    api_key: api_key,
  )
  raise response.error unless response.success?

  parse_resources(response.json_body)
end
list?() click to toggle source
# File lib/rbvore/link.rb, line 22
def list?
  type_name.end_with? "list"
end
parse_resources(json_body) click to toggle source
# File lib/rbvore/link.rb, line 42
def parse_resources(json_body)
  if list?
    Resource.parse_collection(json_body, resource_class)
  else
    Resource.parse_object(json_body, resource_class)
  end
end
resource_class() click to toggle source
# File lib/rbvore/link.rb, line 18
def resource_class
  Rbvore.constantize(type_name)
end
type_name() click to toggle source
# File lib/rbvore/link.rb, line 14
def type_name
  @type_name ||= type.match(/name=(?<name>[a-z\_]+)/).named_captures["name"]
end