Skip to content

Instantly share code, notes, and snippets.

@andrewarrow
Last active October 23, 2015 20:14
Show Gist options
  • Save andrewarrow/25722f5dadccba0025bb to your computer and use it in GitHub Desktop.
Save andrewarrow/25722f5dadccba0025bb to your computer and use it in GitHub Desktop.
require 'net/https'
require 'uri'
require 'json'
require 'csv'
if ARGV.size < 5
puts 'usage: ruby events.rb org_id token device_id email event'
exit 1
end
org_id = ARGV.shift
token = ARGV.shift
device_id = ARGV.shift
email = ARGV.shift
event = ARGV.shift
uri = URI("https://www.bitium.com/api/v2/public/valid")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri)
req.set_form_data(organization_id: org_id, email: email, password: 'TestPassword')
response = http.request(req)
if response.code != '201'
puts 'Login invalid'
exit 1
end
uri = URI("https://www.bitium.com/api/v2/organizations/#{org_id}/admin/installations/#{event}/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 name of event.'
exit 1
end
data = JSON.parse(response.body)
data.each do |item|
sub = item['subscriber']
if sub['email'] == email
puts 'User has access to event.'
exit 0
end
end
puts 'User does NOT have access to event.'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment