Class: BraintreeHttp::Encoder
- Inherits:
-
Object
- Object
- BraintreeHttp::Encoder
- Defined in:
- lib/braintreehttp/encoder.rb
Instance Method Summary collapse
- #deserialize_response(resp, headers) ⇒ Object
- #serialize_request(req) ⇒ Object
- #supported_decodings ⇒ Object
- #supported_encodings ⇒ Object
Instance Method Details
#deserialize_response(resp, headers) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/braintreehttp/encoder.rb', line 16 def deserialize_response(resp, headers) raise UnsupportedEncodingError.new('HttpResponse did not have Content-Type header set') unless headers && (headers['content-type'] || headers['Content-Type']) content_type = headers['content-type'] || headers['Content-Type'] raise UnsupportedEncodingError.new("Unable to deserialize response with Content-Type #{content_type}. Supported decodings are #{supported_decodings}") unless content_type.include? 'application/json' JSON.parse(resp) end |
#serialize_request(req) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/braintreehttp/encoder.rb', line 7 def serialize_request(req) raise UnsupportedEncodingError.new('HttpRequest did not have Content-Type header set') unless req.headers && (req.headers['content-type'] || req.headers['Content-Type']) content_type = req.headers['content-type'] || req.headers['Content-Type'] raise UnsupportedEncodingError.new("Unable to serialize request with Content-Type #{content_type}. Supported encodings are #{supported_encodings}") unless content_type == 'application/json' JSON.generate(req.body) end |
#supported_decodings ⇒ Object
29 30 31 |
# File 'lib/braintreehttp/encoder.rb', line 29 def supported_decodings ['application/json'] end |
#supported_encodings ⇒ Object
25 26 27 |
# File 'lib/braintreehttp/encoder.rb', line 25 def supported_encodings ['application/json'] end |