Class: Twilio::REST::NextGenListResource

Inherits:
ListResource show all
Defined in:
lib/twilio-ruby/rest/next_gen_list_resource.rb

Instance Method Summary collapse

Methods inherited from ListResource

#create, #get, #initialize, #inspect

Methods included from Utils

#detwilify, #twilify

Constructor Details

This class inherits a constructor from Twilio::REST::ListResource

Instance Method Details

#list(params = {}, full_path = false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/twilio-ruby/rest/next_gen_list_resource.rb', line 4

def list(params={}, full_path=false)
  raise "Can't get a resource list without a REST Client" unless @client
  response = @client.get @path, params, full_path
  list_key = response['meta']['key']
  raise "Couldn't find a list key in response meta" unless list_key
  resources = response[list_key]
  resource_list = resources.map do |resource|
    @instance_class.new "#{@path}/#{resource[@instance_id_key]}", @client,
                        resource
  end
  client, list_class = @client, self.class
  resource_list.instance_eval do
    eigenclass = class << self; self; end
    eigenclass.send :define_method, :next_page, &lambda {
      if response['meta']['next_page_url']
        list_class.new(response['meta']['next_page_url'], client).list({})
      else
        []
      end
    }
    eigenclass.send :define_method, :previous_page, &lambda {
      if response['meta']['previous_page_url']
        list_class.new(response['meta']['previous_page_url'], client).list({})
      else
        []
      end
    }
  end
  resource_list
end