Sha256: e44def487283036342444c883feab59e277cc3971e5a9a3ac521d237aa0d8592

Contents?: true

Size: 1.3 KB

Versions: 20

Compression:

Stored size: 1.3 KB

Contents

module Twilio
  module REST
    class NextGenListResource < Twilio::REST::ListResource
      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
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
twilio-ruby-4.13.0 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.12.1 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.11.1 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.11.0 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.10.0 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.9.1 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.9.0 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.8.0 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.7.0 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.6.2 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.6.1 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.6.0 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.5.0 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.4.0 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.3.0 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.2.1 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.2.0 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.1.0 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.0.1 lib/twilio-ruby/rest/next_gen_list_resource.rb
twilio-ruby-4.0.0 lib/twilio-ruby/rest/next_gen_list_resource.rb