require 'rubygems'
require '3scale_client'

# $ THREESCALE_HOST=localhost:3001 kensa run ruby script/heroku_demo.rb

provider_key = ENV['THREESCALE_PROVIDER_KEY']
app_id = ENV['THREESCALE_APP_ID']
app_key = ENV['THREESCALE_APP_KEY']
host = ENV['THREESCALE_HOST']

puts "> Connecting with 3scale"
puts "> HOST: #{host}" if host

client = ThreeScale::Client.new(provider_key: provider_key, host: host)
response = client.authrep(user_key: app_key)

begin
  if response.success?
    puts "> Success"
  else
    puts "> Error: #{response.error_message}"
  end
rescue => e
  puts "> Exception: #{e.message}"
end
