Class: Neb::Client::Request
- Inherits:
-
Object
- Object
- Neb::Client::Request
- Defined in:
- lib/neb/client/request.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(action, url, payload = {}, block = nil) ⇒ Request
constructor
A new instance of Request.
- #request_args ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(action, url, payload = {}, block = nil) ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 14 |
# File 'lib/neb/client/request.rb', line 9 def initialize(action, url, payload = {}, block = nil) @action = action @url = url @payload = payload @block = custom_block(block) end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
7 8 9 |
# File 'lib/neb/client/request.rb', line 7 def action @action end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
7 8 9 |
# File 'lib/neb/client/request.rb', line 7 def block @block end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
7 8 9 |
# File 'lib/neb/client/request.rb', line 7 def payload @payload end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/neb/client/request.rb', line 7 def url @url end |
Instance Method Details
#execute ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/neb/client/request.rb', line 32 def execute Neb.logger.debug(self.to_s) if block.present? ::RestClient::Request.execute(request_args) else ::RestClient::Request.execute(request_args, &default_block) end end |
#request_args ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/neb/client/request.rb', line 20 def request_args args = { method: action, url: url, payload: payload.deep_camelize_keys(:lower).to_json, headers: { content_type: :json, accept: :json }, timeout: CONFIG[:timeout] } args.merge!(block_response: block) if block.present? args end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/neb/client/request.rb', line 16 def to_s "#{self.class}{action=#{action}, url=#{url}, payload=#{payload}}" end |