Sha256: 3a1f0e60532669f8619a81c801d460aa810395bde18092a22399d6f1ff48937c
Contents?: true
Size: 1.05 KB
Versions: 2
Compression:
Stored size: 1.05 KB
Contents
module Twilio class ListResource include Utils def initialize(uri, client) @resource_name = self.class.name.split('::')[-1] @instance_class = Twilio.const_get @resource_name.chop @uri, @client = uri, client end # Grab a list of this kind of resource and return it as an array. def list(params={}) raise "Can't get a resource list without a Twilio::Client" unless @client response = @client.get @uri, params resources = response[detwilify(@resource_name)] resources.map do |resource| @instance_class.new "#{@uri}/#{resource['sid']}", @client, resource end end # Return an empty instance resource object with the proper URI. def get(sid) @instance_class.new "#{@uri}/#{sid}", @client end # Return a newly created resource. def create(params={}) raise "Can't create a resource without a Twilio::Client" unless @client response = @client.post @uri, params @instance_class.new "#{@uri}/#{response['sid']}", @client, response end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
twilio-ruby-0.0.4 | lib/twilio-ruby/list_resource.rb |
twilio-ruby-0.0.3 | lib/twilio-ruby/list_resource.rb |