class Coinbase::Wallet::APIObject
Response item abstract model
Public Class Methods
new(client, data)
click to toggle source
Calls superclass method
# File lib/coinbase/wallet/models/api_object.rb, line 5 def initialize(client, data) super() update(data) @client = client end
Public Instance Methods
format(key, val)
click to toggle source
# File lib/coinbase/wallet/models/api_object.rb, line 23 def format(key, val) return if val.nil? # Looks like a number or currency if val.class == Hash APIObject.new(@client, val) elsif key =~ /_at$/ && (Time.iso8601(val) rescue nil) Time.parse(val) elsif key == "amount" && val =~ /^.{0,1}\s*[0-9,]*\.{0,1}[0-9]*$/ BigDecimal(val.gsub(/[^0-9\.-]/, '')) else val end end
method_missing(method, *args, &blk)
click to toggle source
Calls superclass method
# File lib/coinbase/wallet/models/api_object.rb, line 37 def method_missing(method, *args, &blk) format(method.to_s, self[method.to_s]) || super end
refresh!(params = {}) { |data, resp| ... }
click to toggle source
# File lib/coinbase/wallet/models/api_object.rb, line 11 def refresh!(params = {}) @client.get(self['resource_path'], params) do |resp| update(resp.data) yield(resp.data, resp) if block_given? end end
respond_to_missing?(method, include_all = false)
click to toggle source
Calls superclass method
# File lib/coinbase/wallet/models/api_object.rb, line 41 def respond_to_missing?(method, include_all = false) self.key?(method.to_s) || super end
update(data)
click to toggle source
# File lib/coinbase/wallet/models/api_object.rb, line 18 def update(data) return if data.nil? data.each { |key, val| self[key] = val } if data.is_a?(Hash) end