Module: Twilio::Resource

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args, &blk) ⇒ Object (private)

:nodoc:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/twilio/resource.rb', line 62

def method_missing(id, *args, &blk) #:nodoc:
  meth = id.to_s
  if meth =~ /\=$/
    add_attr_writer meth
    send meth, args.first
  elsif meth =~ /^#{meth}\?$/i
    add_predicate meth
    send meth
  elsif attributes.keys.include? meth
    add_attr_reader meth
    send meth
  else
    super
  end
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/twilio/resource.rb', line 16

def [](key)
  attributes[key]
end

#[]=(key, value) ⇒ Object

:nodoc:



20
21
22
# File 'lib/twilio/resource.rb', line 20

def []=(key,value) # :nodoc:
  attributes[key] = value
end

#initialize(attrs = {}) ⇒ Object

:nodoc:



8
9
10
# File 'lib/twilio/resource.rb', line 8

def initialize(attrs={})  #:nodoc:
  @attributes  = attrs.with_indifferent_access
end

#inspectObject



12
13
14
# File 'lib/twilio/resource.rb', line 12

def inspect
  "#<#{self.class} #{@attributes.map { |k,v| "#{k}: #{v.inspect}" }.join ', '}>"
end

#update_attributes(attrs = {}) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/twilio/resource.rb', line 24

def update_attributes(attrs={})
  state_guard do
    # state account sid if this is a resource created with a connect subaccount
     = self[:account_sid] if self[:connect_app_sid]
    handle_response klass.post path, :body => Hash[attrs.map { |k,v| [k.to_s.camelize, v]}], :account_sid => 
  end
end