Skip to content

Instantly share code, notes, and snippets.

@jkotchoff
Created December 23, 2014 22:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkotchoff/75ea264f80e58665ee24 to your computer and use it in GitHub Desktop.
Save jkotchoff/75ea264f80e58665ee24 to your computer and use it in GitHub Desktop.
Export device tokens from Urban Airship
require 'rubygems'
require 'urbanairship'
require 'httparty'
Urbanairship.application_key = '...'
Urbanairship.application_secret = '...'
Urbanairship.master_secret = '...'
response = Urbanairship.device_tokens
results = []
begin
next_url = response['next_page']
tokens = response['device_tokens']
puts "found #{tokens.length} tokens"
results << tokens
puts "Fetching #{next_url}"
response = Urbanairship.send(:do_request, :get, next_url, :authenticate_with => :master_secret)
end while not response["next_page"].nil?
results.flatten!
unless results.empty?
File.new("urban_airship_devices.csv", 'w').tap do |f|
results.each_with_index do |device, index|
if index == 0
f.puts device.keys.slice(2, 4).join(',')
end
f.puts device.values.slice(2, 4).join(",")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment