Skip to content

Commit

Permalink
Consolidates (List|Instance)Resource#resource to the Utils module
Browse files Browse the repository at this point in the history
  • Loading branch information
philnash committed Sep 13, 2014
1 parent 5b45704 commit 9f6ccbd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
14 changes: 0 additions & 14 deletions lib/twilio-ruby/rest/instance_resource.rb
Expand Up @@ -82,20 +82,6 @@ def set_up_properties_from(hash)
end
@updated = !hash.keys.empty?
end

def resource(*resources)
custom_resource_names = {:sms => 'SMS', :sip => 'SIP'}
resources.each do |r|
resource = twilify r
relative_path = custom_resource_names.fetch(r, resource)
path = "#{@path}/#{relative_path}"
enclosing_module = @submodule == nil ? (Twilio::REST) : (Twilio::REST.const_get(@submodule))
resource_class = enclosing_module.const_get resource
instance_variable_set("@#{r}", resource_class.new(path, @client))
end
self.class.instance_eval {attr_reader *resources}
end

end
end
end
16 changes: 0 additions & 16 deletions lib/twilio-ruby/rest/list_resource.rb
Expand Up @@ -95,22 +95,6 @@ def create(params={})
@instance_class.new "#{@path}/#{response[@instance_id_key]}", @client,
response
end

def resource(*resources)
custom_resource_names = {
:sms => 'SMS',
:sip => 'SIP',
}
resources.each do |r|
resource = twilify r
relative_path = custom_resource_names.fetch(r, resource)
path = "#{@path}/#{relative_path}"
enclosing_module = @submodule == nil ? (Twilio::REST) : (Twilio::REST.const_get(@submodule))
resource_class = enclosing_module.const_get resource
instance_variable_set("@#{r}", resource_class.new(path, @client))
end
self.class.instance_eval {attr_reader *resources}
end
end
end
end
17 changes: 17 additions & 0 deletions lib/twilio-ruby/rest/utils.rb
Expand Up @@ -20,6 +20,23 @@ def detwilify(something)
end
end

protected

def resource(*resources)
custom_resource_names = {
:sms => 'SMS',
:sip => 'SIP'
}
resources.each do |r|
resource = twilify r
relative_path = custom_resource_names.fetch(r, resource)
path = "#{@path}/#{relative_path}"
enclosing_module = @submodule == nil ? (Twilio::REST) : (Twilio::REST.const_get(@submodule))
resource_class = enclosing_module.const_get resource
instance_variable_set("@#{r}", resource_class.new(path, @client))
end
self.class.instance_eval {attr_reader *resources}
end
end
end
end

0 comments on commit 9f6ccbd

Please sign in to comment.