lib/dirigible/device_information.rb in dirigible-1.0.4 vs lib/dirigible/device_information.rb in dirigible-1.1.0

- old
+ new

@@ -35,35 +35,47 @@ # and associated metadata. # # @example Example request: # Dirigible::DeviceInformation.list_device_tokens # + # @example Request next page: + # device_tokens = Dirigible::DeviceInformation.list_device_tokens + # more_device_tokens = device_tokens.next_page + # # @see http://docs.urbanairship.com/reference/api/v3/device_information.html#device-listing - def self.list_device_tokens - Dirigible.get('/device_tokens') + def self.list_device_tokens(options = {}) + List.new(Dirigible.get('/device_tokens', params)) end # Fetch Android APIDs registered to this application and # associated metadata. # # @example Example request: # Dirigible::DeviceInformation.list_apids # + # @example Request next page: + # apids = Dirigible::DeviceInformation.list_apids + # more_apids = apids.next_page + # # @see http://docs.urbanairship.com/reference/api/v3/device_information.html#device-listing - def self.list_apids - Dirigible.get('/apids') + def self.list_apids(options = {}) + List.new(Dirigible.get('/apids', params)) end # Fetch BlackBerry PINs registered to this application and # associated metadata. # # @example Example request: # Dirigible::DeviceInformation.list_device_pins # + # @example Request next page: + # device_pins = Dirigible::DeviceInformation.list_device_pins + # more_device_pins = device_pins.next_page + # # @see http://docs.urbanairship.com/reference/api/v3/device_information.html#device-listing - def self.list_device_pins - Dirigible.get('/device_pins') + def self.list_device_pins(options = {}) + List.new(Dirigible.get('/device_pins', params)) end # Fetch device tokens that can't recieve messages because # the app has been uninstalled. # @@ -71,7 +83,28 @@ # Dirigible::DeviceInformation.device_token_feedback('2009-06-15') # # @see http://docs.urbanairship.com/reference/api/v3/device_information.html#feedback def self.device_token_feedback(since) Dirigible.get("/device_tokens/feedback", { since: since }) + end + + class List + def initialize(response) + @response = response + end + + def [](value) + @response[value] + end + + # Fetch the next page for this device listing. Returns + # nil if next_page is nil. + def next_page(params = {}) + return nil if @response[:next_page].nil? + uri = URI.parse(@response[:next_page]) + path = "/#{uri.path.gsub(/\/api|\//, '')}" + # Shew! Need to simplify this! + params = (CGI.parse(uri.query).map{ |k,v| { k => v[0] } }.reduce({}) { |h,pairs| pairs.each { |k,v| (h[k.to_sym] = v) }; h }).merge!(params) + List.new(Dirigible.get(path, params)) + end end end