Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more "refactoring" - getting rid of last peachy leftovers
- Loading branch information
filip
committed
Jun 16, 2012
1 parent
ba9968b
commit 29edccf
Showing
56 changed files
with
408 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source 'http://rubygems.org' | ||
|
||
gem 'rspec' | ||
gem 'oauth' | ||
gem 'nokogiri' | ||
gem 'will_paginate' |
76 changes: 27 additions & 49 deletions
76
lib/sevendigital/digestion_tract/api_response_digestor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,49 @@ | ||
require 'nokogiri' | ||
|
||
module Sevendigital | ||
|
||
#@private | ||
class ApiResponseDigestor < Digestor # :nodoc: | ||
|
||
def default_element_name; :response end | ||
|
||
def from_xml_doc(xml_node) | ||
return from_invalid_xml unless xml_node | ||
|
||
status = get_optional_attribute(xml_node, "status") | ||
|
||
return from_ok_response(xml_node) if status == 'ok' | ||
|
||
return from_error_response(xml_node) if status == 'error' | ||
|
||
from_invalid_xml | ||
end | ||
|
||
def from_invalid_xml | ||
response = ApiResponse.new | ||
|
||
response.error_code = 10000 | ||
response.error_message = 'Invalid 7digital API response' | ||
|
||
response | ||
end | ||
|
||
def from_error_response(xml_node) | ||
|
||
error_node = get_required_node(xml_node, "error") | ||
|
||
def from_http_response(http_response) | ||
response = ApiResponse.new | ||
response.headers = http_response.header | ||
response.content = http_response.body.to_s | ||
|
||
response.error_code = get_required_attribute(error_node, "code").to_i | ||
response.error_message = get_required_value(error_node, "errorMessage") | ||
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.error_message= http_response.body.to_s | ||
end | ||
response | ||
end | ||
|
||
def from_ok_response(response_content) | ||
response = ApiResponse.new | ||
|
||
response.error_code = 0 | ||
response.content = response_content | ||
def parse_xml_doc(xml, response) | ||
|
||
response | ||
end | ||
xml_doc = Nokogiri::XML(xml) | ||
|
||
def from_http_response(http_response) | ||
if http_response.is_a?(Net::HTTPSuccess) then | ||
response = from_xml_nokogiri(http_response.body.to_s) | ||
response_node = xml_doc.at_xpath("./response") | ||
response_status = nil | ||
response_status = get_optional_attribute(response_node, "status") if response_node | ||
puts xml.inspect | ||
if response_status == 'ok' then | ||
response.error_code = 0 | ||
else | ||
response = from_invalid_http_response(http_response) | ||
if response_status == 'error' | ||
error_node = get_required_node(response_node, "error") | ||
response.error_code = get_required_attribute(error_node, "code").to_i | ||
response.error_message = get_required_value(error_node, "errorMessage") | ||
else | ||
response.error_code = 10001 | ||
response.error_message = 'Invalid 7digital API response' | ||
end | ||
end | ||
response.headers = http_response.header | ||
response | ||
end | ||
|
||
def from_invalid_http_response(http_response) | ||
response = ApiResponse.new | ||
|
||
response.error_code = Integer(http_response.code) | ||
response.error_message= http_response.body.to_s | ||
|
||
response | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.