Class: Textmagic::REST::InstanceResource
- Inherits:
-
Object
- Object
- Textmagic::REST::InstanceResource
- Includes:
- Utils
- Defined in:
- lib/textmagic-ruby/rest/instance_resource.rb
Direct Known Subclasses
AvailableNumber, Bulk, Chat, ChatMessage, Contact, CustomField, Invoice, List, Message, Number, Reply, Schedule, Senderid, Session, Source, SpendingStat, Subaccount, Template, Unsubscriber, User
Instance Method Summary collapse
-
#initialize(path, client, params = {}) ⇒ InstanceResource
constructor
A new instance of InstanceResource.
-
#inspect ⇒ Object
:nodoc:.
- #load_attributes(hash) ⇒ Object
- #refresh ⇒ Object
Methods included from Utils
#key_map, #resource, #to_camel_case, #to_underscore_case
Constructor Details
#initialize(path, client, params = {}) ⇒ InstanceResource
Returns a new instance of InstanceResource.
6 7 8 9 10 |
# File 'lib/textmagic-ruby/rest/instance_resource.rb', line 6 def initialize(path, client, params={}) @path = path @client = client load_attributes params end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
12 13 14 |
# File 'lib/textmagic-ruby/rest/instance_resource.rb', line 12 def inspect # :nodoc: "<#{self.class} @path=#{@path}>" end |
#load_attributes(hash) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/textmagic-ruby/rest/instance_resource.rb', line 16 def load_attributes(hash) = class << self; self; end hash.each do |k,v| attr = to_underscore_case k unless ['client', 'updated'].include? attr .send :define_method, attr.to_sym, &lambda {v} end end @updated = !hash.keys.empty? end |
#refresh ⇒ Object
27 28 29 30 |
# File 'lib/textmagic-ruby/rest/instance_resource.rb', line 27 def refresh load_attributes(@client.get("#{@path}/#{self.id}", {})) self end |