Class: Pupil::Keygen
- Inherits:
-
Object
- Object
- Pupil::Keygen
- Defined in:
- lib/pupil/keygen/base.rb
Defined Under Namespace
Classes: MissingRequiredTokens
Instance Attribute Summary (collapse)
-
- (Object) access_token
readonly
Returns the value of attribute access_token.
-
- (Object) access_token_secret
readonly
Returns the value of attribute access_token_secret.
-
- (Object) consumer_key
readonly
Returns the value of attribute consumer_key.
-
- (Object) consumer_secret
readonly
Returns the value of attribute consumer_secret.
Instance Method Summary (collapse)
- - (Object) auth_url
-
- (Keygen) initialize(opts = {})
constructor
A new instance of Keygen.
- - (Object) interactive
- - (Object) issue_token(verifier)
- - (Object) pupilkey
Constructor Details
- (Keygen) initialize(opts = {})
A new instance of Keygen
9 10 11 12 13 14 |
# File 'lib/pupil/keygen/base.rb', line 9 def initialize opts={} @consumer_key = opts[:consumer_key] rescue nil @consumer_secret = opts[:consumer_secret] rescue nil @access_token = opts[:access_token] rescue nil @access_token_secret = opts[:access_token_secret] rescue nil end |
Instance Attribute Details
- (Object) access_token (readonly)
Returns the value of attribute access_token
5 6 7 |
# File 'lib/pupil/keygen/base.rb', line 5 def access_token @access_token end |
- (Object) access_token_secret (readonly)
Returns the value of attribute access_token_secret
6 7 8 |
# File 'lib/pupil/keygen/base.rb', line 6 def access_token_secret @access_token_secret end |
- (Object) consumer_key (readonly)
Returns the value of attribute consumer_key
3 4 5 |
# File 'lib/pupil/keygen/base.rb', line 3 def consumer_key @consumer_key end |
- (Object) consumer_secret (readonly)
Returns the value of attribute consumer_secret
4 5 6 |
# File 'lib/pupil/keygen/base.rb', line 4 def consumer_secret @consumer_secret end |
Instance Method Details
- (Object) auth_url
16 17 18 19 20 21 |
# File 'lib/pupil/keygen/base.rb', line 16 def auth_url raise MissingRequiredTokens, "Pupil::Keygen#auth_url require consumer_key and consumer_secret" unless @consumer_key || @consumer_secret consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, :site => 'http://twitter.com') request_token = consumer.get_request_token return request_token. end |
- (Object) interactive
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pupil/keygen/base.rb', line 43 def interactive print "Enter OAuth Consumer Key: " unless @consumer_key @consumer_key = gets.chomp.strip unless @consumer_key print "Enter OAuth Consumer Secret: " unless @consumer_secret @consumer_secret = gets.chomp.strip unless @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.}" print "Enter OAuth Verifier: " oauth_verifier = gets.chomp.strip access_token = request_token.get_access_token(:oauth_verifier => oauth_verifier) @access_token = access_token.token @access_token_secret = access_token.secret puts "Process complete!" puts "Access token: #{access_token.token}" puts "Access token secret: #{access_token.secret}" return {:consumer_key => @consumer_key, :consumer_secret => @consumer_secret, :access_token => access_token.token, :access_token_secret => access_token.secret} end |
- (Object) issue_token(verifier)
23 24 25 26 27 28 29 30 31 |
# File 'lib/pupil/keygen/base.rb', line 23 def issue_token verifier raise MissingRequiredTokens, "Pupil::Keygen#issue_token require consumer_key and consumer_secret" unless @consumer_key || @consumer_secret consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, :site => 'http://twitter.com') request_token = consumer.get_request_token access_token = request_token.get_access_token(:oauth_verifier => verifier) @access_token = access_token.token @access_token_secret = access_token.secret return {:access_token => access_token.token, :access_token_secret => access_token.secret} end |
- (Object) pupilkey
33 34 35 36 37 38 39 40 41 |
# File 'lib/pupil/keygen/base.rb', line 33 def pupilkey raise MissingRequiredTokens, "Pupil::Keygen#pupilkey require consumer_key, consumer_secret, access_token and access_token_secret" unless @consumer_key || @consumer_secret || @access_token || @access_token_secret return { :consumer_key => @consumer_key, :consumer_secret => @consumer_secret, :access_token => @access_token, :access_token_secret => @access_token_secret } end |