Class: QuestBack::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/quest_back/response.rb

Overview

Public: Simple proxy object decorating Savon’s response.

Main motication for class is to have #result and #results as a common interface to get to respons’ result(s), with all outer response nesting removed.

At the moment you are still getting back simple hashes from both methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(savon_response, options = {}) ⇒ Response

Returns a new instance of Response.



14
15
16
17
18
# File 'lib/quest_back/response.rb', line 14

def initialize(savon_response, options = {})
  @savon_response = savon_response
  @operation_name = options[:operation_name] or fail ArgumentError.new('Missing operation_name')
  @result_key_nestings = options[:result_key_nestings] or fail ArgumentError.new('Missing result key nestings')
end

Instance Attribute Details

#operation_nameObject (readonly)

Returns the value of attribute operation_name.



10
11
12
# File 'lib/quest_back/response.rb', line 10

def operation_name
  @operation_name
end

#result_key_nestingsObject (readonly)

Returns the value of attribute result_key_nestings.



10
11
12
# File 'lib/quest_back/response.rb', line 10

def result_key_nestings
  @result_key_nestings
end

#savon_responseObject (readonly)

Returns the value of attribute savon_response.



10
11
12
# File 'lib/quest_back/response.rb', line 10

def savon_response
  @savon_response
end

Instance Method Details

#resultObject



20
21
22
23
24
# File 'lib/quest_back/response.rb', line 20

def result
  extract_result.tap do |result|
    fail QuestBack::Error::MultipleResultsFound if result.is_a? Array
  end
end

#resultsObject



26
27
28
# File 'lib/quest_back/response.rb', line 26

def results
  Array.wrap extract_result
end