twpipe 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +41 -0
- data/Rakefile +48 -0
- data/bin/twpipe +51 -0
- data/lib/twpipe/version.rb +3 -0
- data/lib/twpipe.rb +92 -0
- data/spec/data/config/invalid.yml +4 -0
- data/spec/data/config/syntax_error.yml +6 -0
- data/spec/data/config/valid.yml +5 -0
- data/spec/lib/twpipe_spec.rb +76 -0
- data/spec/spec.opts +1 -0
- data/twpipe.gemspec +61 -0
- metadata +109 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 koshigoe
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= Twpipe
|
2
|
+
|
3
|
+
This is a simply Twitter Command-Line client.
|
4
|
+
|
5
|
+
== Synopsis
|
6
|
+
|
7
|
+
% twpipe input your messages separated space
|
8
|
+
|
9
|
+
% cat <<EOF | twpipe
|
10
|
+
messages from STDIN.
|
11
|
+
EOF
|
12
|
+
|
13
|
+
See more information:
|
14
|
+
|
15
|
+
% twpipe -h
|
16
|
+
|
17
|
+
== Configuration
|
18
|
+
|
19
|
+
The configuration file is generally located "~/.twpipe", and file format is the YAML.
|
20
|
+
The configuration is single Hash. This mean is all items are key-value pair(both key and value are string).
|
21
|
+
|
22
|
+
ctoken:: Consumer token
|
23
|
+
csecret:: Consumer secret
|
24
|
+
atoken:: Access token
|
25
|
+
asecret:: Access secret
|
26
|
+
|
27
|
+
In alpha-1, it has not available to configure from CLI yet.
|
28
|
+
|
29
|
+
== Note on Patches/Pull Requests
|
30
|
+
|
31
|
+
* Fork the project.
|
32
|
+
* Make your feature addition or bug fix.
|
33
|
+
* Add tests for it. This is important so I don't break it in a
|
34
|
+
future version unintentionally.
|
35
|
+
* Commit, do not mess with rakefile, version, or history.
|
36
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
37
|
+
* Send me a pull request. Bonus points for topic branches.
|
38
|
+
|
39
|
+
== Copyright
|
40
|
+
|
41
|
+
Copyright (c) 2010 koshigoe. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
require File.dirname(__FILE__) + "/lib/twpipe/version.rb"
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "twpipe"
|
9
|
+
gem.summary = 'This is a simply Twitter Command-Line client.'
|
10
|
+
gem.description = 'This is a simply Twitter Command-Line client.'
|
11
|
+
gem.email = "KoshigoeBushou@gmail.com"
|
12
|
+
gem.homepage = "http://github.com/koshigoe/twpipe"
|
13
|
+
gem.authors = ["koshigoe"]
|
14
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
gem.add_runtime_dependency "twitter"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
gem.version = Twpipe::VERSION
|
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
|
+
end
|
35
|
+
|
36
|
+
task :spec => :check_dependencies
|
37
|
+
|
38
|
+
task :default => :spec
|
39
|
+
|
40
|
+
require 'rake/rdoctask'
|
41
|
+
Rake::RDocTask.new do |rdoc|
|
42
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
43
|
+
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = "Twpipe #{version}"
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
data/bin/twpipe
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'twpipe'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
ARGV.options do |opt|
|
9
|
+
opt.version = '0.0.0'
|
10
|
+
opt.banner = <<EOF
|
11
|
+
This is a simply Twitter Command-Line client.
|
12
|
+
|
13
|
+
http://github.com/koshigoe/twpipe
|
14
|
+
|
15
|
+
Usage:
|
16
|
+
|
17
|
+
1) tweet simply
|
18
|
+
% #{File.basename($0)} [options] some message
|
19
|
+
|
20
|
+
2) tweet from stdin
|
21
|
+
% cat <<EOF | #{File.basename($0)}
|
22
|
+
some messages
|
23
|
+
by multilines.
|
24
|
+
At twitter, these messages are shown single line.
|
25
|
+
EOF
|
26
|
+
|
27
|
+
Options:
|
28
|
+
|
29
|
+
EOF
|
30
|
+
|
31
|
+
opt.on('-c CONFIG_FILE', '--config CONFIG_FILE', 'path to configuration file') {|v| options['config_path'] }
|
32
|
+
|
33
|
+
opt.permute!
|
34
|
+
end
|
35
|
+
|
36
|
+
if ARGV.size > 0
|
37
|
+
message = ARGV.join(' ')
|
38
|
+
else
|
39
|
+
message = ''
|
40
|
+
while buffer = gets
|
41
|
+
message << buffer
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
begin
|
46
|
+
Twpipe.config_path = options['config_path'] if options['config_path']
|
47
|
+
pipe = Twpipe.new
|
48
|
+
pipe.tweet(message)
|
49
|
+
rescue Twpipe::ConfigError => e
|
50
|
+
puts e.message
|
51
|
+
end
|
data/lib/twpipe.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'twitter'
|
3
|
+
require 'twpipe/version'
|
4
|
+
|
5
|
+
# == Twpipe
|
6
|
+
#
|
7
|
+
class Twpipe
|
8
|
+
class ConfigError < Exception; end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
# config_path:: the file path to configuration file
|
12
|
+
attr_accessor :config_path
|
13
|
+
end
|
14
|
+
|
15
|
+
unless instance_variable_defined?(:@config_path)
|
16
|
+
@config_path = File.expand_path('~/.twpipe')
|
17
|
+
end
|
18
|
+
|
19
|
+
# client:: twitter client that authenticated by oAuth (Twitter::Base)
|
20
|
+
attr_reader :client
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
setup_config
|
24
|
+
setup_client
|
25
|
+
end
|
26
|
+
|
27
|
+
# tweet your message
|
28
|
+
#
|
29
|
+
# message: string variable that you would tweet
|
30
|
+
#
|
31
|
+
def tweet(message)
|
32
|
+
@client.update(message)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def manual_of_configuration
|
38
|
+
@manual_of_configuration ||=<<EOF
|
39
|
+
- You must create configuration file which must set to "~/.twpipe".
|
40
|
+
- The format of configuration file must be YAML.
|
41
|
+
- Required configurations are:
|
42
|
+
ctoken:: consumer token
|
43
|
+
csecret:: consumer secret
|
44
|
+
atoken:: access token
|
45
|
+
asecret:: access secret
|
46
|
+
- Optional configurations are:
|
47
|
+
name:: your name at twitter
|
48
|
+
- If you would get more informations of configurations:
|
49
|
+
% grep config bin/twpipe
|
50
|
+
EOF
|
51
|
+
end
|
52
|
+
|
53
|
+
# required items of configuration
|
54
|
+
#
|
55
|
+
# ctoken:: consumer token
|
56
|
+
# csecret:: consumer secret
|
57
|
+
# atoken:: access token
|
58
|
+
# asecret:: access secret
|
59
|
+
#
|
60
|
+
def required_items_of_configuration
|
61
|
+
@required_items_of_configuration ||= %w(ctoken csecret atoken asecret).sort
|
62
|
+
end
|
63
|
+
|
64
|
+
def setup_config # :nodoc:
|
65
|
+
unless File.exist?(self.class.config_path)
|
66
|
+
raise ConfigError,
|
67
|
+
"Configuration file not found, see following messages:\n\n" \
|
68
|
+
"#{manual_of_configuration}"
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
begin
|
73
|
+
@config = YAML.load_file(self.class.config_path)
|
74
|
+
rescue
|
75
|
+
raise ConfigError,
|
76
|
+
"Configuration file was invalid, see following messages:\n\n" \
|
77
|
+
"#{manual_of_configuration}"
|
78
|
+
end
|
79
|
+
|
80
|
+
if (@config.keys & required_items_of_configuration).sort != required_items_of_configuration
|
81
|
+
raise ConfigError,
|
82
|
+
"Some items of configuration not found, see following messages:\n\n" \
|
83
|
+
"#{manual_of_configuration}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def setup_client
|
88
|
+
oauth = Twitter::OAuth.new(@config['ctoken'], @config['csecret'])
|
89
|
+
oauth.authorize_from_access(@config['atoken'], @config['asecret'])
|
90
|
+
@client = Twitter::Base.new(oauth)
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'twpipe'
|
3
|
+
|
4
|
+
describe Twpipe do
|
5
|
+
after do
|
6
|
+
Twpipe.config_path = '~/.twpipe'
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'utilities' do
|
10
|
+
describe 'config_path' do
|
11
|
+
it 'should be equal "~/.twpipe" at default' do
|
12
|
+
Twpipe.config_path.should == File.expand_path('~/.twpipe')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should be able to change value' do
|
16
|
+
Twpipe.config_path = 'hoge'
|
17
|
+
Twpipe.config_path.should == 'hoge'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'initialize' do
|
23
|
+
let(:manual) do
|
24
|
+
<<EOF
|
25
|
+
- You must create configuration file which must set to "~/.twpipe".
|
26
|
+
- The format of configuration file must be YAML.
|
27
|
+
- Required configurations are:
|
28
|
+
ctoken:: consumer token
|
29
|
+
csecret:: consumer secret
|
30
|
+
atoken:: access token
|
31
|
+
asecret:: access secret
|
32
|
+
- Optional configurations are:
|
33
|
+
name:: your name at twitter
|
34
|
+
- If you would get more informations of configurations:
|
35
|
+
% grep config bin/twpipe
|
36
|
+
EOF
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should raise error, if not exist specified configure file' do
|
40
|
+
message = "Configuration file not found, see following messages:\n\n#{manual}"
|
41
|
+
lambda { Twpipe.new }.should raise_error(Twpipe::ConfigError, message)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should raise error, if configuration format was invalid' do
|
45
|
+
Twpipe.config_path = File.join(File.dirname(__FILE__), '../data/config/syntax_error.yml')
|
46
|
+
|
47
|
+
message = "Configuration file was invalid, see following messages:\n\n#{manual}"
|
48
|
+
lambda { Twpipe.new }.should raise_error(Twpipe::ConfigError, message)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should raise error, if not enough required items of configuration' do
|
52
|
+
Twpipe.config_path = File.join(File.dirname(__FILE__), '../data/config/invalid.yml')
|
53
|
+
|
54
|
+
message = "Some items of configuration not found, see following messages:\n\n#{manual}"
|
55
|
+
lambda { Twpipe.new }.should raise_error(Twpipe::ConfigError, message)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should not raise error, if configuration is valid' do
|
59
|
+
Twpipe.config_path = File.join(File.dirname(__FILE__), '../data/config/valid.yml')
|
60
|
+
twpipe = nil
|
61
|
+
lambda { twpipe = Twpipe.new }.should_not raise_error
|
62
|
+
twpipe.client.should be_an_instance_of Twitter::Base
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'tweet' do
|
67
|
+
let(:twitter) { mock('Twitter:Base') }
|
68
|
+
|
69
|
+
it 'should receive Twitter::Base#update' do
|
70
|
+
Twpipe.config_path = File.join(File.dirname(__FILE__), '../data/config/valid.yml')
|
71
|
+
twpipe = Twpipe.new
|
72
|
+
twpipe.instance_variable_get(:@client).should_receive(:update).with('message')
|
73
|
+
twpipe.tweet('message')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/twpipe.gemspec
ADDED
@@ -0,0 +1,61 @@
|
|
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{twpipe}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["koshigoe"]
|
12
|
+
s.date = %q{2010-09-23}
|
13
|
+
s.default_executable = %q{twpipe}
|
14
|
+
s.description = %q{This is a simply Twitter Command-Line client.}
|
15
|
+
s.email = %q{KoshigoeBushou@gmail.com}
|
16
|
+
s.executables = ["twpipe"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"bin/twpipe",
|
27
|
+
"lib/twpipe.rb",
|
28
|
+
"lib/twpipe/version.rb",
|
29
|
+
"spec/data/config/invalid.yml",
|
30
|
+
"spec/data/config/syntax_error.yml",
|
31
|
+
"spec/data/config/valid.yml",
|
32
|
+
"spec/lib/twpipe_spec.rb",
|
33
|
+
"spec/spec.opts",
|
34
|
+
"twpipe.gemspec"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/koshigoe/twpipe}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.7}
|
40
|
+
s.summary = %q{This is a simply Twitter Command-Line client.}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/lib/twpipe_spec.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<twitter>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
54
|
+
s.add_dependency(%q<twitter>, [">= 0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
58
|
+
s.add_dependency(%q<twitter>, [">= 0"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twpipe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- koshigoe
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-23 00:00:00 +09:00
|
19
|
+
default_executable: twpipe
|
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: twitter
|
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
|
+
description: This is a simply Twitter Command-Line client.
|
52
|
+
email: KoshigoeBushou@gmail.com
|
53
|
+
executables:
|
54
|
+
- twpipe
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- LICENSE
|
59
|
+
- README.rdoc
|
60
|
+
files:
|
61
|
+
- .gitignore
|
62
|
+
- LICENSE
|
63
|
+
- README.rdoc
|
64
|
+
- Rakefile
|
65
|
+
- bin/twpipe
|
66
|
+
- lib/twpipe.rb
|
67
|
+
- lib/twpipe/version.rb
|
68
|
+
- spec/data/config/invalid.yml
|
69
|
+
- spec/data/config/syntax_error.yml
|
70
|
+
- spec/data/config/valid.yml
|
71
|
+
- spec/lib/twpipe_spec.rb
|
72
|
+
- spec/spec.opts
|
73
|
+
- twpipe.gemspec
|
74
|
+
has_rdoc: true
|
75
|
+
homepage: http://github.com/koshigoe/twpipe
|
76
|
+
licenses: []
|
77
|
+
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options:
|
80
|
+
- --charset=UTF-8
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.3.7
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: This is a simply Twitter Command-Line client.
|
108
|
+
test_files:
|
109
|
+
- spec/lib/twpipe_spec.rb
|