tweetwine 0.2.12 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +7 -0
- data/Gemfile +17 -0
- data/README.md +57 -47
- data/Rakefile +17 -26
- data/bin/tweetwine +11 -12
- data/contrib/tweetwine-completion.bash +2 -3
- data/example/application_behavior_example.rb +173 -0
- data/example/example_helper.rb +44 -28
- data/example/fixture/config.yaml +8 -0
- data/example/fixture/shorten_rubygems.html +5 -0
- data/example/fixture/shorten_rubylang.html +5 -0
- data/example/fixture/update_utf8.json +1 -0
- data/example/fixture/update_with_urls.json +1 -0
- data/example/fixture/{update.json → update_without_urls.json} +0 -0
- data/example/search_statuses_example.rb +49 -16
- data/example/show_followers_example.rb +7 -8
- data/example/show_friends_example.rb +7 -8
- data/example/show_home_example.rb +19 -16
- data/example/show_mentions_example.rb +8 -9
- data/example/show_user_example.rb +16 -13
- data/example/update_status_example.rb +143 -26
- data/example/use_http_proxy_example.rb +40 -20
- data/lib/tweetwine/basic_object.rb +19 -0
- data/lib/tweetwine/character_encoding.rb +59 -0
- data/lib/tweetwine/cli.rb +354 -230
- data/lib/tweetwine/config.rb +65 -0
- data/lib/tweetwine/http.rb +120 -0
- data/lib/tweetwine/oauth.rb +104 -0
- data/lib/tweetwine/obfuscate.rb +21 -0
- data/lib/tweetwine/option_parser.rb +31 -0
- data/lib/tweetwine/promise.rb +39 -0
- data/lib/tweetwine/twitter.rb +211 -0
- data/lib/tweetwine/{io.rb → ui.rb} +30 -21
- data/lib/tweetwine/url_shortener.rb +15 -9
- data/lib/tweetwine/util.rb +30 -15
- data/lib/tweetwine.rb +72 -12
- data/man/tweetwine.7 +43 -69
- data/man/tweetwine.7.ronn +57 -47
- data/test/character_encoding_test.rb +87 -0
- data/test/cli_test.rb +19 -6
- data/test/config_test.rb +244 -0
- data/test/fixture/oauth.rb +21 -0
- data/test/fixture/test_config.yaml +4 -4
- data/test/http_test.rb +199 -0
- data/test/oauth_test.rb +77 -0
- data/test/obfuscate_test.rb +16 -0
- data/test/option_parser_test.rb +60 -0
- data/test/promise_test.rb +56 -0
- data/test/test_helper.rb +76 -8
- data/test/twitter_test.rb +625 -0
- data/test/{io_test.rb → ui_test.rb} +92 -74
- data/test/url_shortener_test.rb +115 -135
- data/test/util_test.rb +136 -85
- data/tweetwine.gemspec +53 -0
- metadata +112 -56
- data/example/show_metadata_example.rb +0 -86
- data/lib/tweetwine/client.rb +0 -187
- data/lib/tweetwine/meta.rb +0 -5
- data/lib/tweetwine/options.rb +0 -24
- data/lib/tweetwine/retrying_http.rb +0 -99
- data/lib/tweetwine/startup_config.rb +0 -50
- data/man/tweetwine.1 +0 -109
- data/man/tweetwine.1.ronn +0 -69
- data/test/client_test.rb +0 -544
- data/test/options_test.rb +0 -45
- data/test/retrying_http_test.rb +0 -147
- data/test/startup_config_test.rb +0 -162
@@ -1,99 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require "rest_client"
|
4
|
-
|
5
|
-
module Tweetwine
|
6
|
-
class HttpError < RuntimeError; end
|
7
|
-
|
8
|
-
module RetryingHttp
|
9
|
-
def self.proxy=(url)
|
10
|
-
RestClient.proxy = url
|
11
|
-
end
|
12
|
-
|
13
|
-
class Base
|
14
|
-
MAX_RETRIES = 3
|
15
|
-
RETRY_BASE_WAIT_TIMEOUT = 4
|
16
|
-
|
17
|
-
def self.use_retries_with(*methods)
|
18
|
-
methods.each do |method_name|
|
19
|
-
module_eval do
|
20
|
-
non_retrying_method_name = "original_#{method_name}".to_sym
|
21
|
-
alias_method non_retrying_method_name, method_name
|
22
|
-
define_method(method_name) do |*args|
|
23
|
-
do_with_retries { send(non_retrying_method_name, *args).to_s }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def do_with_retries
|
32
|
-
retries = 0
|
33
|
-
begin
|
34
|
-
yield
|
35
|
-
rescue Errno::ECONNRESET, RestClient::RequestTimeout => e
|
36
|
-
if retries < MAX_RETRIES
|
37
|
-
retries += 1
|
38
|
-
timeout = RETRY_BASE_WAIT_TIMEOUT**retries
|
39
|
-
@io.warn("Could not connect -- retrying in #{timeout} seconds") if @io
|
40
|
-
sleep timeout
|
41
|
-
retry
|
42
|
-
else
|
43
|
-
raise HttpError, e
|
44
|
-
end
|
45
|
-
rescue RestClient::Exception, SocketError, SystemCallError => e
|
46
|
-
raise HttpError, e
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class Client < Base
|
52
|
-
attr_accessor :io
|
53
|
-
|
54
|
-
def initialize(io)
|
55
|
-
@io = io
|
56
|
-
end
|
57
|
-
|
58
|
-
def get(*args)
|
59
|
-
RestClient.get(*args)
|
60
|
-
end
|
61
|
-
|
62
|
-
def post(*args)
|
63
|
-
RestClient.post(*args)
|
64
|
-
end
|
65
|
-
|
66
|
-
def as_resource(url, options = {})
|
67
|
-
resource = Resource.new(RestClient::Resource.new(url, options))
|
68
|
-
resource.io = @io
|
69
|
-
resource
|
70
|
-
end
|
71
|
-
|
72
|
-
use_retries_with :get, :post
|
73
|
-
end
|
74
|
-
|
75
|
-
class Resource < Base
|
76
|
-
attr_accessor :io
|
77
|
-
|
78
|
-
def initialize(wrapped_resource)
|
79
|
-
@wrapped = wrapped_resource
|
80
|
-
end
|
81
|
-
|
82
|
-
def [](suburl)
|
83
|
-
instance = self.class.new(@wrapped[suburl])
|
84
|
-
instance.io = @io
|
85
|
-
instance
|
86
|
-
end
|
87
|
-
|
88
|
-
def get(*args)
|
89
|
-
@wrapped.get(*args)
|
90
|
-
end
|
91
|
-
|
92
|
-
def post(*args)
|
93
|
-
@wrapped.post(*args)
|
94
|
-
end
|
95
|
-
|
96
|
-
use_retries_with :get, :post
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require "yaml"
|
4
|
-
|
5
|
-
module Tweetwine
|
6
|
-
class StartupConfig
|
7
|
-
attr_reader :options, :command
|
8
|
-
|
9
|
-
def initialize(supported_commands, default_command, default_opts = {})
|
10
|
-
raise ArgumentError, "Must give at least one supported command" if supported_commands.empty?
|
11
|
-
raise ArgumentError, "Default command is not a supported command" unless supported_commands.include? default_command
|
12
|
-
@supported_commands, @default_command = supported_commands, default_command
|
13
|
-
@options, @command = default_opts, nil
|
14
|
-
end
|
15
|
-
|
16
|
-
def parse(args = [], config_file = nil, env_lookouts = [], &cmd_option_parser)
|
17
|
-
options = @options.merge(parse_options(args, config_file, env_lookouts, &cmd_option_parser))
|
18
|
-
command = if args.empty? then @default_command else args.shift.to_sym end
|
19
|
-
raise ArgumentError, "Unknown command" unless @supported_commands.include? command
|
20
|
-
@options, @command = options, command
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def parse_options(args, config_file, env_lookouts, &cmd_option_parser)
|
27
|
-
cmd_options = if cmd_option_parser then parse_cmdline_args(args, &cmd_option_parser) else {} end
|
28
|
-
config_options = if config_file && File.exists?(config_file) then parse_config_file(config_file) else {} end
|
29
|
-
env_options = if env_lookouts then parse_env_vars(env_lookouts) else {} end
|
30
|
-
env_options.merge(config_options.merge(cmd_options))
|
31
|
-
end
|
32
|
-
|
33
|
-
def parse_cmdline_args(args, &cmd_option_parser)
|
34
|
-
yield args
|
35
|
-
end
|
36
|
-
|
37
|
-
def parse_config_file(config_file)
|
38
|
-
options = YAML.load(File.read(config_file))
|
39
|
-
Util.symbolize_hash_keys(options)
|
40
|
-
end
|
41
|
-
|
42
|
-
def parse_env_vars(env_lookouts)
|
43
|
-
env_lookouts.inject({}) do |result, env_var_name|
|
44
|
-
env_option = ENV[env_var_name.to_s]
|
45
|
-
result[env_var_name.to_sym] = env_option if env_option && !env_option.empty?
|
46
|
-
result
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/man/tweetwine.1
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
.\" generated with Ronn/v0.5
|
2
|
-
.\" http://github.com/rtomayko/ronn/
|
3
|
-
.
|
4
|
-
.TH "TWEETWINE" "1" "April 2010" "Tuomas Kareinen" "Tweetwine Manual"
|
5
|
-
.
|
6
|
-
.SH "NAME"
|
7
|
-
\fBtweetwine\fR \-\- a simple Twitter command line agent
|
8
|
-
.
|
9
|
-
.SH "SYNOPSIS"
|
10
|
-
.
|
11
|
-
.nf
|
12
|
-
|
13
|
-
tweetwine [ <GLOBAL_OPTIONS> ]
|
14
|
-
tweetwine [ <GLOBAL_OPTIONS> ] <COMMAND> [ <COMMAND_OPTIONS> ]
|
15
|
-
.
|
16
|
-
.fi
|
17
|
-
.
|
18
|
-
.SH "DESCRIPTION"
|
19
|
-
Tweetwine supports showing the home timeline of the authenticated user, the
|
20
|
-
latest statuses of friends and followers, and the latest statuses that mention
|
21
|
-
the user. If that's not enough, statuses can be searched with arbitrary terms.
|
22
|
-
In addition, new statuses can be sent.
|
23
|
-
.
|
24
|
-
.P
|
25
|
-
\fICOMMAND\fR is one of
|
26
|
-
.
|
27
|
-
.IP "\(bu" 4
|
28
|
-
\fBfollowers\fR,
|
29
|
-
.
|
30
|
-
.IP "\(bu" 4
|
31
|
-
\fBfriends\fR,
|
32
|
-
.
|
33
|
-
.IP "\(bu" 4
|
34
|
-
\fBhome\fR,
|
35
|
-
.
|
36
|
-
.IP "\(bu" 4
|
37
|
-
\fBmentions\fR,
|
38
|
-
.
|
39
|
-
.IP "\(bu" 4
|
40
|
-
\fBsearch\fR,
|
41
|
-
.
|
42
|
-
.IP "\(bu" 4
|
43
|
-
\fBupdate\fR, or
|
44
|
-
.
|
45
|
-
.IP "\(bu" 4
|
46
|
-
\fBuser\fR.
|
47
|
-
.
|
48
|
-
.IP "" 0
|
49
|
-
.
|
50
|
-
.P
|
51
|
-
The default is \fBhome\fR.
|
52
|
-
.
|
53
|
-
.SH "OPTIONS"
|
54
|
-
Options given from command line override corresponding settings from
|
55
|
-
configuration (\fB~/.tweetwine\fR).
|
56
|
-
.
|
57
|
-
.P
|
58
|
-
\fIGLOBAL_OPTIONS\fR are:
|
59
|
-
.
|
60
|
-
.TP
|
61
|
-
\fB\-a\fR, \fB\-\-auth USERNAME:PASSWORD\fR
|
62
|
-
Authentication.
|
63
|
-
.
|
64
|
-
.TP
|
65
|
-
\fB\-c\fR, \fB\-\-[no\-]colors\fR
|
66
|
-
Colorize output with ANSI escape codes.
|
67
|
-
.
|
68
|
-
.TP
|
69
|
-
\fB\-n\fR, \fB\-\-num N\fR
|
70
|
-
The number of statuses in page, default 20.
|
71
|
-
.
|
72
|
-
.TP
|
73
|
-
\fB\-\-[no\-]http\-proxy URL\fR
|
74
|
-
Use proxy for HTTP and HTTPS.
|
75
|
-
.
|
76
|
-
.TP
|
77
|
-
\fB\-\-no\-url\-shorten\fR
|
78
|
-
Do not shorten URLs for status update.
|
79
|
-
.
|
80
|
-
.TP
|
81
|
-
\fB\-p\fR, \fB\-\-page N\fR
|
82
|
-
The page number for statuses, default 1.
|
83
|
-
.
|
84
|
-
.TP
|
85
|
-
\fB\-v\fR, \fB\-\-version\fR
|
86
|
-
Show version information and exit.
|
87
|
-
.
|
88
|
-
.TP
|
89
|
-
\fB\-h\fR, \fB\-\-help\fR
|
90
|
-
Show help message and exit.
|
91
|
-
.
|
92
|
-
.P
|
93
|
-
In order to see \fICOMMAND_OPTIONS\fR, enter:
|
94
|
-
.
|
95
|
-
.IP "" 4
|
96
|
-
.
|
97
|
-
.nf
|
98
|
-
|
99
|
-
$ tweetwine help <COMMAND>
|
100
|
-
.
|
101
|
-
.fi
|
102
|
-
.
|
103
|
-
.IP "" 0
|
104
|
-
.
|
105
|
-
.SH "COPYRIGHT"
|
106
|
-
Tweetwine is Copyright (c) 2009\-2010 Tuomas Kareinen
|
107
|
-
.
|
108
|
-
.SH "SEE ALSO"
|
109
|
-
tweetwine(7), \fIhttp://github.com/tuomas/tweetwine\fR
|
data/man/tweetwine.1.ronn
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
tweetwine(1) -- a simple Twitter command line agent
|
2
|
-
===================================================
|
3
|
-
|
4
|
-
## SYNOPSIS
|
5
|
-
|
6
|
-
tweetwine [ <GLOBAL_OPTIONS> ]
|
7
|
-
tweetwine [ <GLOBAL_OPTIONS> ] <COMMAND> [ <COMMAND_OPTIONS> ]
|
8
|
-
|
9
|
-
## DESCRIPTION
|
10
|
-
|
11
|
-
Tweetwine supports showing the home timeline of the authenticated user, the
|
12
|
-
latest statuses of friends and followers, and the latest statuses that mention
|
13
|
-
the user. If that's not enough, statuses can be searched with arbitrary terms.
|
14
|
-
In addition, new statuses can be sent.
|
15
|
-
|
16
|
-
<COMMAND> is one of
|
17
|
-
|
18
|
-
* `followers`,
|
19
|
-
* `friends`,
|
20
|
-
* `home`,
|
21
|
-
* `mentions`,
|
22
|
-
* `search`,
|
23
|
-
* `update`, or
|
24
|
-
* `user`.
|
25
|
-
|
26
|
-
The default is `home`.
|
27
|
-
|
28
|
-
## OPTIONS
|
29
|
-
|
30
|
-
Options given from command line override corresponding settings from
|
31
|
-
configuration (`~/.tweetwine`).
|
32
|
-
|
33
|
-
<GLOBAL_OPTIONS> are:
|
34
|
-
|
35
|
-
* `-a`, `--auth USERNAME:PASSWORD`:
|
36
|
-
Authentication.
|
37
|
-
|
38
|
-
* `-c`, `--[no-]colors`:
|
39
|
-
Colorize output with ANSI escape codes.
|
40
|
-
|
41
|
-
* `-n`, `--num N`:
|
42
|
-
The number of statuses in page, default 20.
|
43
|
-
|
44
|
-
* `--[no-]http-proxy URL`:
|
45
|
-
Use proxy for HTTP and HTTPS.
|
46
|
-
|
47
|
-
* `--no-url-shorten`:
|
48
|
-
Do not shorten URLs for status update.
|
49
|
-
|
50
|
-
* `-p`, `--page N`:
|
51
|
-
The page number for statuses, default 1.
|
52
|
-
|
53
|
-
* `-v`, `--version`:
|
54
|
-
Show version information and exit.
|
55
|
-
|
56
|
-
* `-h`, `--help`:
|
57
|
-
Show help message and exit.
|
58
|
-
|
59
|
-
In order to see <COMMAND_OPTIONS>, enter:
|
60
|
-
|
61
|
-
$ tweetwine help <COMMAND>
|
62
|
-
|
63
|
-
## COPYRIGHT
|
64
|
-
|
65
|
-
Tweetwine is Copyright (c) 2009-2010 Tuomas Kareinen
|
66
|
-
|
67
|
-
## SEE ALSO
|
68
|
-
|
69
|
-
tweetwine(7), <http://github.com/tuomas/tweetwine>
|