4 require("irb/completion")
8 gem('twitter4r', '>0.3.0')
10 require("twitter/console")
14 gem("mbbx6spp-twitter4r", '>=0.3.1')
16 require("twitter/console")
19 abort("Error: You must install either twitter4r gem from Rubyforge with version 0.3.1 or greater or the mbbx6spp-twitter4r gem from GitHub's servers with version 0.3.1 or greater (and make sure it is a recent version of the gem).")
26 @
@OPTIONS = { :key => "", :secret => "" }
28 OptionParser
.new
do |opt
|
29 opt
.banner
= "Usage: t4r-oauth-access [environment] [options]"
30 opt
.on("--key=[<YOUR KEY>]", 'Use this OAuth consumer key.') { |v
| @
@OPTIONS[:key] = v
}
31 opt
.on("--secret=[<YOUR SECRET>]", 'Use this OAuth consumer secret.') { |v
| @
@OPTIONS[:secret] = v
}
37 result
= ENV["T4R_CONFIG"]
38 file_name
= File
.expand_path('twitter.yml')
39 result
||= file_name
if File
.exists
?(file_name
)
40 file_name
= File
.expand_path('twitter.yml', 'config')
41 result
||= file_name
if File
.exists
?(file_name
)
42 file_name
= File
.expand_path('~/.twitter.yml')
43 result
||= file_name
if File
.exists
?(file_name
)
48 ENV["T4R_ENV"] || ENV["MERB_ENV"] || ENV["RAILS_ENV"]
53 consumer
= OAuth
::Consumer.new(@
@OPTIONS[:key], @
@OPTIONS[:secret],
54 :site => "https://twitter.com")
55 rtoken
= consumer
.get_request_token
56 puts
"1. Visit this URL to grant your application authorization:"
57 puts
" >> #{rtoken.authorize_url}"
58 puts
"2. When you have authorized your application to access your account, Twitter.com will display a PIN to you."
59 print
"3. Enter the PIN here: "
60 pin
= STDIN.readline
.chomp
61 atoken
= rtoken
.get_access_token(:oauth_verifier => pin
)
62 puts
"4. Your access token details are:"
63 puts
" >> key: #{atoken.token}"
64 puts
" >> secret: #{atoken.secret}"
65 resp
= atoken
.get("/account/verify_credentials.json")
66 data = JSON
.parse(resp
.body
)
68 puts
"Your account details are:"
77 Twitter
::OAuthAccess.parse_options
!
78 config_file
= Twitter
::OAuthAccess.config_file
79 account
= Twitter
::OAuthAccess.account
81 if config_file
&& account
82 @twitter = Twitter
::Client.from_config(config_file
, account
)
83 puts
"Used #{config_file} to create client for #{account} account."
84 puts
"Follow instructions below to grant authorization to your application and determine access token details."
85 Twitter
::OAuthAccess.run()
87 abort("Please make sure #{config_file} exists and contains your Twitter credentials (separated by account/environment) and that you specify the account/environment to use, e.g. if you have a 'test' section in your configuration file that you want to use set/export T4R_ENV=test as an environment variable or RAILS_ENV=test or MERB_ENV=test")