Sha256: 07dc5e71d846c2b6d582c22fb7895ee55fa767bbcd0fed643608c64b3f5198da

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

# -*- coding: utf-8 -*-

class Pupil
  class Keygen
    class MissingRequiedTokens < StandardError; end
    
    def initialize opts={}
      @con_key = opts[:consumer_key] rescue nil
      @con_sec = opts[:consumer_secret] rescue nil
      @act_key = opts[:access_token] rescue nil
      @act_sec = opts[:access_token_secret] rescue nil
    end
    
    def access_token
      raise MissingRequiedTokens, "Keygen#access_token require consumer_key and consumer_secret" unless @con_key && @con_sec
    end
    
    def interactive
      print "Enter OAuth Consumer_Key: "
      oauth_consumer_key = gets.chomp.strip
      print "Enter OAuth Consumer_Secret: "
      oauth_consumer_secret = gets.chomp.strip

      CONSUMER_KEY = oauth_consumer_key
      CONSUMER_SECRET = oauth_consumer_secret

      consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site => 'http://twitter.com')

      request_token = consumer.get_request_token

      puts "Access to this URL and approve: #{request_token.authorize_url}"

      print "Enter OAuth Verifier: "
      oauth_verifier = gets.chomp.strip

      access_token = request_token.get_access_token(:oauth_verifier => oauth_verifier)

      puts "Process complete!"
      puts "Access token: #{access_token.token}"
      puts "Access token secret: #{access_token.secret}"
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pupil-0.0.4 lib/pupil/keygen.rb