Class: Sevendigital::ApiResponseDigestor
- Defined in:
- lib/sevendigital/digestion_tract/api_response_digestor.rb
Instance Method Summary collapse
-
#default_element_name ⇒ Object
:nodoc:.
- #from_http_response(http_response) ⇒ Object
- #parse_xml_doc(xml, response) ⇒ Object
Methods inherited from Digestor
#content_present?, #from_xml_string, #get_optional_attribute, #get_optional_node, #get_optional_value, #get_required_attribute, #get_required_node, #get_required_value, #initialize, #list_from_xml_doc, #list_from_xml_string, #make_sure_eating_nokogiri_node, #nested_list_from_xml_doc, #nested_list_from_xml_string, #paginate_results, #value_present?
Constructor Details
This class inherits a constructor from Sevendigital::Digestor
Instance Method Details
#default_element_name ⇒ Object
:nodoc:
8 |
# File 'lib/sevendigital/digestion_tract/api_response_digestor.rb', line 8 def default_element_name; :response end |
#from_http_response(http_response) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sevendigital/digestion_tract/api_response_digestor.rb', line 10 def from_http_response(http_response) response = ApiResponse.new response.headers = http_response.header response.content = http_response.body.to_s parse_xml_doc(response.content, response) if response.error_code >= 10000 && !http_response.is_a?(Net::HTTPSuccess) response.error_code = Integer(http_response.code) response.= http_response.body.to_s end response end |
#parse_xml_doc(xml, response) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sevendigital/digestion_tract/api_response_digestor.rb', line 24 def parse_xml_doc(xml, response) xml_doc = Nokogiri::XML(xml) response_node = xml_doc.at_xpath("./response") response_status = nil response_status = get_optional_attribute(response_node, "status") if response_node if response_status == 'ok' then response.error_code = 0 else if response_status == 'error' error_node = get_required_node(response_node, "error") response.error_code = get_required_attribute(error_node, "code").to_i response. = get_required_value(error_node, "errorMessage") else response.error_code = 10001 response. = 'Invalid 7digital API response' end end end |