Class: ShortcutRuby::Request
- Inherits:
-
Object
- Object
- ShortcutRuby::Request
- Defined in:
- lib/shortcut_ruby/request.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#params ⇒ Object
Returns the value of attribute params.
-
#response_format ⇒ Object
Returns the value of attribute response_format.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#fetch ⇒ Object
Executes the http(s) request and provides the response with some additional decoration in a Hash.
-
#initialize(shortcut, action:, params: {}) ⇒ Request
constructor
Prepares a fancy request object and ensures the inputs make as much sense as possible.
Constructor Details
#initialize(shortcut, action:, params: {}) ⇒ Request
Prepares a fancy request object and ensures the inputs make as much sense as possible. It’s still totally possible to just provide a path that doesn’t match a real url though.
11 12 13 14 15 16 17 18 |
# File 'lib/shortcut_ruby/request.rb', line 11 def initialize(shortcut, action:, params: {}) raise ArgumentError unless validate_input(shortcut, action, params) self.params = params || {} self.uri = construct_uri(shortcut) self.action = action self.response_format = shortcut.response_format end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
5 6 7 |
# File 'lib/shortcut_ruby/request.rb', line 5 def action @action end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/shortcut_ruby/request.rb', line 5 def params @params end |
#response_format ⇒ Object
Returns the value of attribute response_format.
5 6 7 |
# File 'lib/shortcut_ruby/request.rb', line 5 def response_format @response_format end |
#uri ⇒ Object
Returns the value of attribute uri.
5 6 7 |
# File 'lib/shortcut_ruby/request.rb', line 5 def uri @uri end |
Instance Method Details
#fetch ⇒ Object
Executes the http(s) request and provides the response with some additional decoration in a Hash.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/shortcut_ruby/request.rb', line 23 def fetch Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |https| req = Net::HTTP.const_get(action).new(uri) set_body(req) set_format_header(req) wrap_response(https.request(req)) end end |