Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 57 lines (42 sloc) 1.146 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#!/usr/bin/env ruby

STDOUT.sync = true

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])

require 'rubygems'
require 'prowly'
require 'optparse'

options = {}

ORIGINAL_ARGV = ARGV.dup

opts = OptionParser.new do |opts|
  opts.banner = <<-EOF
Usage:
prowly_retrieve -p providerkey

Options:
EOF

  opts.on("-pPROVIDERKEY", "--provider PRIORITY", "Provider Key") do |priority|
    options[:provider] = priority
  end
  
  opts.on("-v", "--version", "Print the version number and exit") do
    options[:version] = true
  end
end

opts.parse!

if options[:version]
  abort("Version " + Prowly.version)
end

token_result = Prowly.retrieve_token(options[:provider])

if token_result.succeeded?
  puts "go to this #{token_result.url} to approve this request"
  puts "then press <ENTER> to continue "
  dummy = STDIN.gets

  apikey_result = Prowly.retrieve_apikey(options[:provider], token_result.token)

  if apikey_result.succeeded?
    puts "The user apikey is #{apikey_result.apikey}"
    exit(0)
  else
    puts "Error: #{apikey_result.message}"
    exit(1)
  end
else
  puts "Error: #{token_result.message}"
  exit(1)
end
Something went wrong with that request. Please try again.