class Textmagic::REST::InstanceResource

Public Class Methods

new(path, client, params={}) click to toggle source
   # File lib/textmagic-ruby/rest/instance_resource.rb
 6 def initialize(path, client, params={})
 7   @path = path
 8   @client = client
 9   load_attributes params
10 end

Public Instance Methods

load_attributes(hash) click to toggle source
   # File lib/textmagic-ruby/rest/instance_resource.rb
16 def load_attributes(hash)
17   metaclass = class << self; self; end
18   hash.each do |k,v|
19     attr = to_underscore_case k
20     unless ['client', 'updated'].include? attr
21       metaclass.send :define_method, attr.to_sym, &lambda {v}
22     end
23   end
24   @updated = !hash.keys.empty?
25 end
refresh() click to toggle source
   # File lib/textmagic-ruby/rest/instance_resource.rb
27 def refresh
28   load_attributes(@client.get("#{@path}/#{self.id}", {}))
29   self
30 end