lib/espago/response.rb in espago-0.0.6 vs lib/espago/response.rb in espago-0.0.7

- old
+ new

@@ -1,55 +1,35 @@ require "json" require "time" module Espago class Response + attr_reader :status attr_reader :body - + def initialize(response) - @body = parse(response) + @body = parse(response.body) + @status = response.status end - - def response_id - body["id"] - end - - def description - body["description"] - end - - def amount - body["amount"] - end - - def currency - body["currency"] - end - - def state - body["state"] - end - - def client - body["client"] - end - def created_at - body["client"] + def method_missing(attribute_name) + body[attribute_name.to_s] end def card body["card"] || {} end def created_at - Time.parse body["created_at"] + Time.at(body["created_at"]) rescue nil end - + private - + def parse(body) JSON.parse body + rescue + body end - end + end end - \ No newline at end of file +