Skip to content

Instantly share code, notes, and snippets.

@onetwopunch
Last active October 16, 2018 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onetwopunch/f44c274a0ece2c1dbd13e58f58d2044c to your computer and use it in GitHub Desktop.
Save onetwopunch/f44c274a0ece2c1dbd13e58f58d2044c to your computer and use it in GitHub Desktop.
Pull alerts from RedLock given a JWT
#!/usr/bin/env ruby
require 'httparty'
require 'json'
class Redlock
include HTTParty
base_uri 'https://app.redlock.com'
def initiailize(jwt)
@jwt = jwt
@default_options = { headers: auth }
end
def alerts(opts = {})
JSON.parse(self.class.get('/alerts', opts.merge(@default_options)).body)
end
def auth
{'x-redlock-auth' => @jwt}
end
end
def store_json(page, json)
filename = "#{page}.json"
puts "Storing page #{page} into #{filename}"
File.open(filename, 'w') do |f|
f.write(JSON.dump(json)
end
end
page = 1
redlock = Redlock.new(ARGV.first)
resp = redlock.alerts
loop do
if resp['nextPageToken']
resp = redlock.alerts({'pageToken' => resp['nextPageToken']})
store_json(page, resp)
else
# Last page
resp = redlock.alerts
store_json(page, resp)
break
end
page += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment