Class: HTTParty::Request
- Inherits:
-
Object
- Object
- HTTParty::Request
- Defined in:
- lib/httparty/patch.rb
Overview
In order to parse the HTML encoded documents returned by the YourMembership API we need to HTML decode the <![CDATA[ tags. This is a bug workaround.
Instance Method Summary collapse
-
#encode_body(body) ⇒ Object
This is the encode_body method from HTTParty’s Request Class adding an additional method call to fix the CDATA elements that are improperly formatted in the YourMembership API’s XML.
-
#fix_cdata(body) ⇒ String
Bug Fix for HTML encoded < and > in XML body.
Instance Method Details
#encode_body(body) ⇒ Object
This is the encode_body method from HTTParty’s Request Class adding an additional method call to fix the CDATA elements that are improperly formatted in the YourMembership API’s XML. This is done here to ensure that the fix is in place before the data is parsed.
11 12 13 14 15 16 17 18 |
# File 'lib/httparty/patch.rb', line 11 def encode_body(body) body = fix_cdata body if ''.respond_to?(:encoding) _encode_body(body) else body end end |
#fix_cdata(body) ⇒ String
Bug Fix for HTML encoded < and > in XML body.
23 24 25 26 27 28 29 30 31 |
# File 'lib/httparty/patch.rb', line 23 def fix_cdata(body) # <![CDATA[ = <![CDATA[ # ]]> = ]]> if body.include? '<![CDATA[' body.gsub! '<![CDATA[', '<![CDATA[' body.gsub! ']]>', ']]>' end body end |