Class: HypermediaAPI::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/api/link.rb

Instance Method Summary collapse

Constructor Details

#initialize(href_uri_str, http_basic_auth = nil) ⇒ Link

Sets the href uri and HTTP basic auth of this link.



23
24
25
26
# File 'lib/api/link.rb', line 23

def initialize (href_uri_str, http_basic_auth = nil)
  @href_uri_str = href_uri_str.to_s
  @http_basic_auth = http_basic_auth || { username: '', password: '' }
end

Instance Method Details

#authObject

Returns the HTTP basic auth of this link.



5
6
7
# File 'lib/api/link.rb', line 5

def auth
  @http_basic_auth
end

#click(options = {}) ⇒ Object

Sends a GET request to the href uri of this link, then returns a HypermediaAPI::Document representing the response.



11
12
13
14
15
# File 'lib/api/link.rb', line 11

def click (options = {})
  document = HypermediaAPI.get(self.href, { auth: self.auth }.merge(options))
rescue SocketError
  raise HypermediaAPI::BadURI, "The client was unable to interact with a resource at #{self.href}."
end

#hrefObject

Returns the href uri of this link.



18
19
20
# File 'lib/api/link.rb', line 18

def href
  @href_uri_str
end