Module: PacerApi::Translation

Included in:
Session
Defined in:
lib/pacer_api/translation.rb

Instance Method Summary collapse

Instance Method Details

#decode_response(body) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/pacer_api/translation.rb', line 22

def decode_response(body)
  result = ResponseTranslator.translate(JSON.parse(body))
  if ENV.key?("DEBUG")
    puts "<<<<"
    pp result
  end
  result
rescue JSON::ParserError => e
  raise PacerApi::DecodeError, "#{e.class} #{e.message}", e.backtrace
end

#encode_request(obj) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/pacer_api/translation.rb', line 12

def encode_request(obj)
  if ENV.key?("DEBUG")
    puts ">>>>"
    pp obj
  end
  JSON.generate(RequestTranslator.translate(obj))
rescue JSON::ParserError => e
  raise PacerApi::EncodeError, "#{e.class} #{e.message}", e.backtrace
end