Skip to content

Commit

Permalink
treating instance sid key as a property
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmbenton committed Aug 7, 2011
1 parent 796fc16 commit 142562e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/twilio-ruby/rest/conferences/participants.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Twilio
module REST
class Participants < ListResource; end
class Participants < ListResource
def sid_key # :nodoc:
'call_sid'
end
end

class Participant < InstanceResource
def mute
Expand Down
10 changes: 7 additions & 3 deletions lib/twilio-ruby/rest/list_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ def initialize(uri, client)
@uri, @client = uri, client
end

def inspect
def sid_key # :nodoc:
'sid'
end

def inspect # :nodoc:
"<#{self.class} @uri=#{@uri}>"
end

# Grab a list of this kind of resource and return it as an array. The
# array includes a special property called +total+ which will return the
# array includes a special attribute named +total+ which will return the
# total number of items in the list on Twilio's server.
def list(params = {})
raise "Can't get a resource list without a REST Client" unless @client
response = @client.get @uri, params
resources = response[detwilify(@resource_name)]
resource_list = resources.map do |resource|
@instance_class.new "#{@uri}/#{resource['sid']}", @client, resource
@instance_class.new "#{@uri}/#{resource[sid_key]}", @client, resource
end
# set the +total+ property on the array
resource_list.instance_eval {
Expand Down

0 comments on commit 142562e

Please sign in to comment.