class Harpy::EntryPoint

Attributes

url[RW]

Public Class Methods

new(url) click to toggle source
# File lib/harpy/entry_point.rb, line 7
def initialize(url)
  self.url = url
end

Public Instance Methods

resource_url(resource_type) click to toggle source
# File lib/harpy/entry_point.rb, line 11
def resource_url(resource_type)
  response = Harpy.client.get url
  case response.code
  when 200
    body = JSON.parse response.body
    link = (body["link"] || []).detect{|link| link["rel"] == resource_type}
    link["href"] if link
  else
    Harpy.client.invalid_code response
  end
end
urn(urn) click to toggle source
# File lib/harpy/entry_point.rb, line 23
def urn(urn)
  response = Harpy.client.get "#{url}/#{urn}"
  case response.code
  when 301
    response.headers_hash["Location"]
  when 404
    nil
  else
    Harpy.client.invalid_code response
  end
end