Class: HypermediaAPI::Form
- Inherits:
-
Object
- Object
- HypermediaAPI::Form
- Defined in:
- lib/api/form.rb
Instance Method Summary collapse
-
#action ⇒ Object
Returns the action uri of this form.
-
#auth ⇒ Object
Returns the HTTP basic auth of this form.
-
#initialize(action_uri_str, http_method, http_basic_auth = nil) ⇒ Form
constructor
Sets the action uri, HTTP method, and HTTP basic auth of this form.
-
#method ⇒ Object
Returns the HTTP method of this form.
-
#submit(inputs, options = {}) ⇒ Object
Submits this form with the given inputs, then returns a Hypermedia::Document representing the response.
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
#action ⇒ Object
Returns the action uri of this form.
5 6 7 |
# File 'lib/api/form.rb', line 5 def action @action_uri_str end |
#auth ⇒ Object
Returns the HTTP basic auth of this form.
10 11 12 |
# File 'lib/api/form.rb', line 10 def auth @http_basic_auth end |
#method ⇒ Object
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, = {}) HypermediaAPI.send(self.method.downcase, self.action, { inputs: inputs, auth: self.auth }.merge()) rescue SocketError raise HypermediaAPI::BadURI, "The client was unable to interact with a resource at #{self.action}." end |