oauth-cli-twitter 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 tily
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,98 @@
1
+ OAuth::CLI::Twitter
2
+ ===================
3
+
4
+ Description
5
+ -----------
6
+
7
+ Twitter OAuth interface for CLI applications.
8
+
9
+ Usage
10
+ -----
11
+
12
+ ### Interface
13
+
14
+ * simple
15
+
16
+ require 'oauth/cli/twitter'
17
+
18
+ access_token = OAuth::CLI::Twitter.get_access_token(:pit => 'oauth-cli-twitter-simple')
19
+ access_token.post(
20
+ 'http://twitter.com/statuses/update.json',
21
+ 'status'=> 'hello from ruby-oauth-cli-twitter simple example'
22
+ )
23
+
24
+ * define constants
25
+
26
+ require 'rubygems'
27
+ require 'rubytter'
28
+ require 'oauth/cli/twitter'
29
+
30
+ CONSUMER_TOKEN = '358RyJ77o4BYJUViVRQ'
31
+ CONSUMER_SECRET = 'aOHsTInoyOjNewpvC9c5uwBqF3XOd5xSGlHFtaB8A'
32
+
33
+ access_token = OAuth::CLI::Twitter.get_access_token(:pit => 'oauth-cli-twitter-dc')
34
+ rubytter = OAuthRubytter.new(access_token)
35
+ rubytter.update('hello from ruby-oauth-cli-twitter define constant example')
36
+
37
+ * include
38
+
39
+ require 'rubygems'
40
+ require 'twitter'
41
+ require 'oauth/cli/twitter'
42
+
43
+ class MyApplication
44
+ include OAuth::CLI::Twitter
45
+
46
+ CONSUMER_TOKEN = '358RyJ77o4BYJUViVRQ'
47
+ CONSUMER_SECRET = 'aOHsTInoyOjNewpvC9c5uwBqF3XOd5xSGlHFtaB8A'
48
+
49
+ def initialize
50
+ access_token = get_access_token(:pit => 'oauth-cli-twitter-inclusion')
51
+ oauth = Twitter::OAuth.new(CONSUMER_TOKEN, CONSUMER_SECRET)
52
+ oauth.authorize_from_access(access_token.token, access_token.secret)
53
+ @twitter = Twitter::Base.new(oauth)
54
+ end
55
+
56
+ def update(status)
57
+ @twitter.update(status)
58
+ end
59
+ end
60
+
61
+ app = MyApplication.new
62
+ app.update('hello from ruby-oauth-cli-twitter inclusion example')
63
+
64
+ ### Save Config
65
+
66
+ * save config to file
67
+
68
+ include OAuth::CLI::Twitter
69
+ p get_acccess_token(:file => ENV['HOME'] + '/.my_app')
70
+
71
+ * save config to pit
72
+
73
+ include OAuth::CLI::Twitter
74
+ p get_acccess_token(:pit => 'my_app')
75
+
76
+ Requirement
77
+ -----------
78
+
79
+ * oauth
80
+ * readline
81
+ * termtter
82
+ * pit
83
+
84
+ Install
85
+ -------
86
+
87
+ ### Archive Installation
88
+
89
+ rake install
90
+
91
+ ### Gem Installation
92
+
93
+ gem install oauth-cli-twitter
94
+
95
+ Copyright
96
+ ---------
97
+
98
+ Copyright (c) 2010 tily. See LICENSE for details.
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "oauth-cli-twitter"
8
+ gem.summary = %Q{Twitter OAuth Interface for CLI Applications}
9
+ gem.description = %Q{Twitter OAuth Interface for CLI Applications}
10
+ gem.email = "tily05@gmail.com"
11
+ gem.homepage = "http://github.com/tily/ruby-oauth-cli-twitter"
12
+ gem.authors = ["tily"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency "oauth"
15
+ gem.add_dependency "termtter"
16
+ gem.add_dependency "pit"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ spec.rcov_opts = ["--gcc"]
35
+ end
36
+
37
+ task :spec => :check_dependencies
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "ruby-oauth-cli-twitter #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'rubytter'
6
+ require 'oauth/cli/twitter'
7
+
8
+ CONSUMER_TOKEN = '358RyJ77o4BYJUViVRQ'
9
+ CONSUMER_SECRET = 'aOHsTInoyOjNewpvC9c5uwBqF3XOd5xSGlHFtaB8A'
10
+
11
+ access_token = OAuth::CLI::Twitter.get_access_token(:pit => 'oauth-cli-twitter-dc')
12
+ rubytter = OAuthRubytter.new(access_token)
13
+ rubytter.update('hello from ruby-oauth-cli-twitter define constant example')
14
+
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'twitter'
6
+ require 'oauth/cli/twitter'
7
+
8
+ class MyApplication
9
+ include OAuth::CLI::Twitter
10
+
11
+ CONSUMER_TOKEN = '358RyJ77o4BYJUViVRQ'
12
+ CONSUMER_SECRET = 'aOHsTInoyOjNewpvC9c5uwBqF3XOd5xSGlHFtaB8A'
13
+
14
+ def initialize
15
+ access_token = get_access_token(:pit => 'oauth-cli-twitter-inclusion')
16
+ oauth = Twitter::OAuth.new(CONSUMER_TOKEN, CONSUMER_SECRET)
17
+ oauth.authorize_from_access(access_token.token, access_token.secret)
18
+ @twitter = Twitter::Base.new(oauth)
19
+ end
20
+
21
+ def update(status)
22
+ @twitter.update(status)
23
+ end
24
+ end
25
+
26
+ app = MyApplication.new
27
+ app.update('hello from ruby-oauth-cli-twitter inclusion example')
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'oauth/cli/twitter'
5
+
6
+ access_token = OAuth::CLI::Twitter.get_access_token(:pit => 'oauth-cli-twitter-simple')
7
+ access_token.post(
8
+ 'http://twitter.com/statuses/update.json',
9
+ 'status'=> 'hello from ruby-oauth-cli-twitter simple example'
10
+ )
@@ -0,0 +1,114 @@
1
+
2
+ require 'rubygems'
3
+ require 'oauth'
4
+ require 'readline'
5
+ require 'termtter/system_extensions'
6
+ require 'pit'
7
+
8
+ module OAuth
9
+ class CLI
10
+ module Twitter
11
+ extend self
12
+
13
+ CONSUMER_TOKEN = 'UWhf189fDdtCZz6rq8Q5gA'
14
+ CONSUMER_SECRET = 'QQHee9yFJqWeztLvGRj5A552gCGIJ7N0yLtpsJPZeU'
15
+
16
+ def self.included(includer)
17
+ @includer = includer
18
+ end
19
+ attr_accessor :includer
20
+
21
+ def get_access_token(*args)
22
+ case args.size
23
+ when 1
24
+ @options = args[0]
25
+ # TODO: add extender ?
26
+ if Twitter.includer &&
27
+ Twitter.includer.const_defined?(:CONSUMER_TOKEN) &&
28
+ Twitter.includer.const_defined?(:CONSUMER_SECRET)
29
+ @consumer_token = Twitter.includer::CONSUMER_TOKEN
30
+ @consumer_secret = Twitter.includer::CONSUMER_SECRET
31
+ elsif Object.const_defined?(:CONSUMER_TOKEN) &&
32
+ Object.const_defined?(:CONSUMER_SECRET)
33
+ @consumer_token = Object::CONSUMER_TOKEN
34
+ @consumer_secret = Object::CONSUMER_SECRET
35
+ else
36
+ @consumer_token = CONSUMER_TOKEN
37
+ @consumer_secret = CONSUMER_SECRET
38
+ end
39
+ when 2, 3
40
+ @consumer_token, @consumer_secret, @options = args
41
+ else
42
+ raise ArgumentError
43
+ end
44
+ execute
45
+ end
46
+
47
+ def execute
48
+ config = load_config
49
+ if config && config['oauth_token'] && config['oauth_token_secret']
50
+ @access_token = OAuth::AccessToken.new(
51
+ consumer,
52
+ config['oauth_token'],
53
+ config['oauth_token_secret']
54
+ )
55
+ @access_token.params = config
56
+ else
57
+ @access_token = authorize
58
+ save_config(config)
59
+ end
60
+ @access_token
61
+ end
62
+
63
+ def load_config
64
+ if @options[:pit]
65
+ Pit.get(@options[:pit])
66
+ elsif @options[:file] && File.exist?(@options[:file])
67
+ YAML.load(File.read(@options[:file]))
68
+ end
69
+ end
70
+
71
+ def save_config(config)
72
+ config = {} if !config
73
+ config.update(@access_token.params)
74
+ if @options[:pit]
75
+ Pit.set(@options[:pit], :data => config)
76
+ elsif @options[:file]
77
+ File.open(@options[:file], 'w') do |f|
78
+ f.write(config.to_yaml)
79
+ end
80
+ end
81
+ end
82
+
83
+ def authorize
84
+ if @options[:browser]
85
+ Kernel.send(:open_browser, request_token.authorize_url)
86
+ else
87
+ STDOUT.puts 'Visit URL below to allow this application.'
88
+ STDOUT.puts request_token.authorize_url
89
+ end
90
+ request_token.get_access_token(:oauth_verifier => prompt_pin)
91
+ end
92
+
93
+ def request_token
94
+ @request_token ||= consumer.get_request_token
95
+ end
96
+
97
+ def consumer
98
+ @consumer ||= OAuth::Consumer.new(
99
+ @consumer_token,
100
+ @consumer_secret,
101
+ :site => 'http://api.twitter.com',
102
+ :proxy => ENV['http_proxy']
103
+ )
104
+ end
105
+
106
+ def prompt_pin
107
+ while pin = Readline.readline('Enter pin > ')
108
+ break pin if pin =~ /^\d+$/
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{oauth-cli-twitter}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["tily"]
12
+ s.date = %q{2010-10-31}
13
+ s.description = %q{Twitter OAuth Interface for CLI Applications}
14
+ s.email = %q{tily05@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "example/define_constant.rb",
27
+ "example/inclusion.rb",
28
+ "example/simple.rb",
29
+ "lib/oauth/cli/twitter.rb",
30
+ "oauth-cli-twitter.gemspec",
31
+ "spec/oauth_cli_twitter_spec.rb",
32
+ "spec/spec.opts",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/tily/ruby-oauth-cli-twitter}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Twitter OAuth Interface for CLI Applications}
40
+ s.test_files = [
41
+ "spec/oauth_cli_twitter_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
51
+ s.add_runtime_dependency(%q<oauth>, [">= 0"])
52
+ s.add_runtime_dependency(%q<termtter>, [">= 0"])
53
+ s.add_runtime_dependency(%q<pit>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
+ s.add_dependency(%q<oauth>, [">= 0"])
57
+ s.add_dependency(%q<termtter>, [">= 0"])
58
+ s.add_dependency(%q<pit>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
62
+ s.add_dependency(%q<oauth>, [">= 0"])
63
+ s.add_dependency(%q<termtter>, [">= 0"])
64
+ s.add_dependency(%q<pit>, [">= 0"])
65
+ end
66
+ end
67
+
@@ -0,0 +1,212 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe OAuth::CLI::Twitter do
4
+ before do
5
+ @twitter = Object.new.extend(OAuth::CLI::Twitter)
6
+ end
7
+
8
+ describe 'taking arguments' do
9
+ before do
10
+ @consumer_token = 'dummy consumer token'
11
+ @consumer_secret = 'dummy consumer secret'
12
+ @options = {}
13
+ @access_token = 'dummy access token'
14
+ end
15
+
16
+ it '#get_access_token with 1 arg' do
17
+ @twitter.should_receive(:execute).and_return(@access_token)
18
+ @twitter.get_access_token(@options).should == @access_token
19
+ end
20
+
21
+ it '#get_access_token with 2 arg' do
22
+ @twitter.should_receive(:execute).and_return(@access_token)
23
+ @twitter.get_access_token(@consumer_token, @consumer_secret).should == @access_token
24
+ end
25
+
26
+ it '#get_access_token with 3 arg' do
27
+ @twitter.should_receive(:execute).and_return(@access_token)
28
+ @twitter.get_access_token(@consumer_token, @consumer_secret, @options).should == @access_token
29
+ end
30
+
31
+ it '#get_access_token with no arg (raise error)' do
32
+ lambda { @twitter.get_access_token }.should raise_error ArgumentError
33
+ end
34
+
35
+ it '#get_access_token with 4 (raise error)' do
36
+ lambda {
37
+ @twitter.get_access_token(@consumer_token, @consumer_secret, @options, 'extra arg')
38
+ }.should raise_error ArgumentError
39
+ end
40
+ end
41
+
42
+ describe 'getting constants' do
43
+ it '#get_access_token gets constants of itself' do
44
+ @twitter.should_receive(:execute).and_return(@access_token)
45
+ @twitter.get_access_token(@options)
46
+ @twitter.instance_variable_get('@consumer_token').should == OAuth::CLI::Twitter::CONSUMER_TOKEN
47
+ @twitter.instance_variable_get('@consumer_secret').should == OAuth::CLI::Twitter::CONSUMER_SECRET
48
+ end
49
+
50
+ it '#get_access_token gets constants of Object' do
51
+ @twitter.should_receive(:execute).and_return(@access_token)
52
+ Object::CONSUMER_TOKEN = 'object consumer token'
53
+ Object::CONSUMER_SECRET = 'object consumer secret'
54
+ @twitter.get_access_token(@options)
55
+ @twitter.instance_variable_get('@consumer_token').should == Object::CONSUMER_TOKEN
56
+ @twitter.instance_variable_get('@consumer_secret').should == Object::CONSUMER_SECRET
57
+ end
58
+
59
+ it '#get_access_token gets constants of includer' do
60
+ @twitter.should_receive(:execute).and_return(@access_token)
61
+ @klass = Class.new
62
+ @klass::CONSUMER_TOKEN = 'includer consumer token'
63
+ @klass::CONSUMER_SECRET = 'includer consumer secret'
64
+ @klass.send(:include, OAuth::CLI::Twitter)
65
+ @twitter.get_access_token(@options)
66
+ @twitter.instance_variable_get('@consumer_token').should == @klass::CONSUMER_TOKEN
67
+ @twitter.instance_variable_get('@consumer_secret').should == @klass::CONSUMER_SECRET
68
+ end
69
+ end
70
+
71
+ describe 'execution' do
72
+ before do
73
+ @access_token = 'dummy access token'
74
+ end
75
+
76
+ it '#execute and config loaded' do
77
+ config = {'oauth_token' => 'dummy oauth token', 'oauth_token_secret' => 'dummy oauth token secret'}
78
+ consumer = 'dummy consumer'
79
+ @twitter.should_receive(:load_config).and_return(config)
80
+ @twitter.should_receive(:consumer).and_return(consumer)
81
+ OAuth::AccessToken.should_receive(:new).with(consumer, config['oauth_token'], config['oauth_token_secret']).and_return(@access_token)
82
+ @twitter.execute.should == @access_token
83
+ end
84
+
85
+ it '#execute and config not loaded' do
86
+ config = {}
87
+ @twitter.should_receive(:load_config).and_return(config)
88
+ @twitter.should_receive(:authorize).and_return(@access_token)
89
+ @twitter.should_receive(:save_config).with(config)
90
+ @twitter.execute.should == @access_token
91
+ end
92
+ end
93
+
94
+ describe 'loading config' do
95
+ before do
96
+ @config = 'dummy config'
97
+ end
98
+
99
+ it '#load_config from pit' do
100
+ pit = 'pit key'
101
+
102
+ Pit.should_receive(:get).with(pit).and_return(@config)
103
+
104
+ @twitter.instance_variable_set('@options', {:pit => pit})
105
+ @twitter.load_config.should == @config
106
+ end
107
+
108
+ it '#load_config from file' do
109
+ file = '/path/to/.conf'
110
+ yaml = '- dummy yaml'
111
+
112
+ File.should_receive(:read).with(file).and_return(yaml)
113
+ YAML.should_receive(:load).with(yaml).and_return(@config)
114
+
115
+ @twitter.instance_variable_set('@options', {:file => file})
116
+ @twitter.load_config.should == @config
117
+ end
118
+ end
119
+
120
+ describe 'saving config' do
121
+ before do
122
+ @twitter.instance_variable_set('@access_token', mock.tap {|m|
123
+ m.should_receive(:params).and_return('dummy access token params')
124
+ })
125
+ @config = mock.tap {|m| m.should_receive(:update).with('dummy access token params') }
126
+ end
127
+
128
+ it '#save_config to pit' do
129
+ pit = 'pit key'
130
+
131
+ Pit.should_receive(:set).with(pit, :data => @config)
132
+
133
+ @twitter.instance_variable_set('@options', {:pit => pit})
134
+ end
135
+
136
+ it '#save_config to file' do
137
+ file = '/path/to/.conf'
138
+ yaml = '- dummy yaml'
139
+
140
+ File.should_receive(:open).with(file, 'w').and_yield(
141
+ mock.tap {|m| m.should_receive(:write).with(yaml) }
142
+ )
143
+ @config.should_receive(:to_yaml).and_return(yaml)
144
+
145
+ @twitter.instance_variable_set('@options', {:file => file})
146
+ end
147
+
148
+ after do
149
+ @twitter.save_config(@config)
150
+ end
151
+ end
152
+
153
+ describe 'authorization' do
154
+ before do
155
+ @url, @pin = 'dummy url', '123456'
156
+ @twitter.should_receive(:prompt_pin).and_return(@pin)
157
+ @request_token = mock()
158
+ @request_token.should_receive(:authorize_url).and_return(@url)
159
+ @request_token.should_receive(:get_access_token).with(:oauth_verifier => @pin).and_return(@url)
160
+ @twitter.should_receive(:request_token).twice.and_return(@request_token)
161
+ end
162
+
163
+ it '#authorize without browser' do
164
+ STDOUT.should_receive(:puts).with('Visit URL below to allow this application.')
165
+ STDOUT.should_receive(:puts).with(@url)
166
+
167
+ @twitter.instance_variable_set('@options', {})
168
+ end
169
+
170
+ it '#authorize with browser' do
171
+ Kernel.should_receive(:open_browser).with(@url)
172
+
173
+ @twitter.instance_variable_set('@options', {:browser => true})
174
+ end
175
+
176
+ after do
177
+ @twitter.authorize
178
+ end
179
+ end
180
+
181
+ describe 'prompting' do
182
+ it '#prompt_pin' do
183
+ expect = '1234567'
184
+ Readline.should_receive(:readline).once.with('Enter pin > ').and_return("not number")
185
+ Readline.should_receive(:readline).once.with('Enter pin > ').and_return("#{expect}")
186
+ @twitter.prompt_pin.should == expect
187
+ end
188
+ end
189
+
190
+ describe 'OAuth wrapper methods' do
191
+ it '#request_token' do
192
+ expect = 'dummy request token'
193
+ @twitter.should_receive(:consumer).once.and_return(
194
+ mock.tap {|m| m.should_receive(:get_request_token).once.and_return(expect) }
195
+ )
196
+ 2.times { @twitter.request_token.should == expect }
197
+ end
198
+
199
+ it '#consumer' do
200
+ consumer = 'dummy consumer'
201
+ OAuth::Consumer.should_receive(:new).once.with(
202
+ @consumer_token,
203
+ @consumer_secret,
204
+ :site => 'http://api.twitter.com',
205
+ :proxy => ENV['http_proxy']
206
+ ).and_return(consumer)
207
+ @twitter.instance_variable_set('@consumer_token', @consumer_token)
208
+ @twitter.instance_variable_set('@consumer_secret', @consumer_secret)
209
+ 2.times { @twitter.consumer.should == consumer }
210
+ end
211
+ end
212
+ end
@@ -0,0 +1 @@
1
+ -fs -color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'oauth/cli/twitter'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth-cli-twitter
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - tily
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-31 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: oauth
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: termtter
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: pit
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ description: Twitter OAuth Interface for CLI Applications
80
+ email: tily05@gmail.com
81
+ executables: []
82
+
83
+ extensions: []
84
+
85
+ extra_rdoc_files:
86
+ - LICENSE
87
+ - README.md
88
+ files:
89
+ - .document
90
+ - .gitignore
91
+ - LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - VERSION
95
+ - example/define_constant.rb
96
+ - example/inclusion.rb
97
+ - example/simple.rb
98
+ - lib/oauth/cli/twitter.rb
99
+ - oauth-cli-twitter.gemspec
100
+ - spec/oauth_cli_twitter_spec.rb
101
+ - spec/spec.opts
102
+ - spec/spec_helper.rb
103
+ has_rdoc: true
104
+ homepage: http://github.com/tily/ruby-oauth-cli-twitter
105
+ licenses: []
106
+
107
+ post_install_message:
108
+ rdoc_options:
109
+ - --charset=UTF-8
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ requirements: []
131
+
132
+ rubyforge_project:
133
+ rubygems_version: 1.3.7
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Twitter OAuth Interface for CLI Applications
137
+ test_files:
138
+ - spec/oauth_cli_twitter_spec.rb
139
+ - spec/spec_helper.rb