Class: Harpy::EntryPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/harpy/entry_point.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ EntryPoint

Returns a new instance of EntryPoint.



7
8
9
# File 'lib/harpy/entry_point.rb', line 7

def initialize(url)
  self.url = url
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/harpy/entry_point.rb', line 5

def url
  @url
end

Instance Method Details

#resource_url(resource_type) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/harpy/entry_point.rb', line 11

def resource_url(resource_type)
  response = Harpy.client.get url
  case response.code
  when 200
    body = Yajl::Parser.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) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# 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