Class: BraintreeHttp::Encoder

Inherits:
Object
  • Object
show all
Defined in:
lib/braintreehttp/encoder.rb

Instance Method Summary collapse

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_decodingsObject



29
30
31
# File 'lib/braintreehttp/encoder.rb', line 29

def supported_decodings
  ['application/json']
end

#supported_encodingsObject



25
26
27
# File 'lib/braintreehttp/encoder.rb', line 25

def supported_encodings
  ['application/json']
end