Class: Response
- Inherits:
-
Object
- Object
- Response
- Defined in:
- lib/response.rb
Instance Method Summary collapse
- #add_detail(detail) ⇒ Object
- #add_var(hash) ⇒ Object
- #details? ⇒ Boolean
- #error_state(_error) ⇒ Object
- #get ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
- #set_state(state) ⇒ Object
- #set_url(url) ⇒ Object
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
3 4 5 6 7 8 |
# File 'lib/response.rb', line 3 def initialize @details = [] @url = nil @state = 'bad' @additional_vars = [] end |
Instance Method Details
#add_detail(detail) ⇒ Object
14 15 16 |
# File 'lib/response.rb', line 14 def add_detail detail @details << detail end |
#add_var(hash) ⇒ Object
10 11 12 |
# File 'lib/response.rb', line 10 def add_var hash @additional_vars << hash end |
#details? ⇒ Boolean
22 23 24 |
# File 'lib/response.rb', line 22 def details? @details.any? end |
#error_state(_error) ⇒ Object
30 31 32 33 |
# File 'lib/response.rb', line 30 def error_state _error set_state 'shit' add_detail _error. end |
#get ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/response.rb', line 35 def get if @state == 'bad' set_state 'ok' unless details? end result = {state: @state, details: @details, url: @url} @additional_vars.each do |h| result.merge! h end result end |
#set_state(state) ⇒ Object
26 27 28 |
# File 'lib/response.rb', line 26 def set_state state @state = state end |
#set_url(url) ⇒ Object
18 19 20 |
# File 'lib/response.rb', line 18 def set_url url @url = url end |