Class: HypermediaAPI::Form

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

Instance Method Summary collapse

Constructor Details

#initialize(action_uri_str, http_method, http_basic_auth = nil) ⇒ Form

Sets the action uri, HTTP method, and HTTP basic auth of this form.



15
16
17
18
19
# File 'lib/api/form.rb', line 15

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

Instance Method Details

#actionObject

Returns the action uri of this form.



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

def action
  @action_uri_str
end

#authObject

Returns the HTTP basic auth of this form.



10
11
12
# File 'lib/api/form.rb', line 10

def auth
  @http_basic_auth
end

#methodObject

Returns the HTTP method of this form.



22
23
24
# File 'lib/api/form.rb', line 22

def method
  @http_method
end

#submit(inputs, options = {}) ⇒ Object

Submits this form with the given inputs, then returns a Hypermedia::Document representing the response.



28
29
30
31
32
# File 'lib/api/form.rb', line 28

def submit (inputs, options = {})
  HypermediaAPI.send(self.method.downcase, self.action, { inputs: inputs, auth: self.auth }.merge(options))
rescue SocketError
  raise HypermediaAPI::BadURI, "The client was unable to interact with a resource at #{self.action}."
end