lib/pupil/keygen/base.rb in pupil-0.6.3 vs lib/pupil/keygen/base.rb in pupil-0.7
- old
+ new
@@ -2,29 +2,32 @@
class Keygen
attr_reader :consumer_key
attr_reader :consumer_secret
attr_reader :access_token
attr_reader :access_token_secret
+ TWITTER_API_URL = "https://api.twitter.com"
class MissingRequiredTokens < StandardError; end
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
+ def consumer
+ OAuth::Consumer.new(@consumer_key, @consumer_secret, :site => TWITTER_API_URL)
+ end
+
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.authorize_url
end
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}
@@ -43,12 +46,10 @@
def interactive
@consumer_key = Readline.readline("Enter OAuth Consumer Key: ", true) unless @consumer_key
print unless @consumer_secret
@consumer_secret = Readline.readline("Enter OAuth Consumer Secret: ", true) 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.authorize_url}"
oauth_verifier = Readline.readline("Enter OAuth Verifier: ", true)
@@ -58,6 +59,6 @@
@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, :screen_name => access_token.params[:screen_name]}
end
end
-end
\ No newline at end of file
+end