Created
October 22, 2015 21:44
-
-
Save andrewarrow/36109c87a6fb9273958d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/https' | |
require 'uri' | |
require 'json' | |
require 'csv' | |
if ARGV.size < 4 | |
puts 'usage: ruby bitium_list_subscribers.rb slug org_id token device_id' | |
exit 1 | |
end | |
slug = ARGV.shift | |
org_id = ARGV.shift | |
token = ARGV.shift | |
device_id = ARGV.shift | |
uri = URI("https://www.bitium.com/api/v2/organizations/#{org_id}/admin/installations/#{slug}/subscriptions") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
req = Net::HTTP::Get.new(uri.request_uri) | |
req.add_field('Authorization', "token #{token}") | |
req.add_field('X-Device-Id', device_id) | |
response = http.request(req) | |
if response.code != '200' | |
puts 'Please check input params.' | |
exit 1 | |
end | |
data = JSON.parse(response.body) | |
CSV.open("subscribers.csv", "wb") do |csv| | |
data.each do |item| | |
sub = item['subscriber'] | |
csv << [ sub['name'], sub['email'], sub['status'], sub['created_at'], sub['last_activity'], sub['average_password_score']['grade'] ] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment