tweetwine 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +6 -0
- data/example/show_metadata_example.rb +1 -1
- data/lib/tweetwine/cli.rb +1 -1
- data/lib/tweetwine/client.rb +40 -69
- data/lib/tweetwine/io.rb +3 -3
- data/lib/tweetwine/meta.rb +1 -1
- data/lib/tweetwine/retrying_http.rb +4 -4
- data/lib/tweetwine/startup_config.rb +1 -1
- data/lib/tweetwine/util.rb +1 -1
- data/test/client_test.rb +1 -0
- data/test/retrying_http_test.rb +4 -4
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
data/lib/tweetwine/cli.rb
CHANGED
@@ -37,7 +37,7 @@ module Tweetwine
|
|
37
37
|
@global_option_parser = create_global_option_parser(exec_name)
|
38
38
|
@config = StartupConfig.new(Client::COMMANDS + [:help], Client::DEFAULT_COMMAND, extra_opts)
|
39
39
|
@config.parse(args, config_file, [:http_proxy], &@global_option_parser)
|
40
|
-
@client = Client.new(
|
40
|
+
@client = Client.new(yield(@config.options), @config.options) if @config.command != :help
|
41
41
|
end
|
42
42
|
|
43
43
|
def show_help_command_and_exit(args)
|
data/lib/tweetwine/client.rb
CHANGED
@@ -25,10 +25,17 @@ module Tweetwine
|
|
25
25
|
@page_num = Util.parse_int_gt(options[:page_num], DEFAULT_PAGE_NUM, 1, "page number")
|
26
26
|
@url_shortener = if options[:shorten_urls] && options[:shorten_urls][:enable]
|
27
27
|
dependencies.url_shortener.call(options[:shorten_urls])
|
28
|
-
else
|
29
|
-
nil
|
30
28
|
end
|
31
|
-
|
29
|
+
end
|
30
|
+
|
31
|
+
def followers(args = [], options = nil)
|
32
|
+
response = get_from_rest_api("statuses/followers/#{@username}")
|
33
|
+
show_users_from_rest_api(*response)
|
34
|
+
end
|
35
|
+
|
36
|
+
def friends(args = [], options = nil)
|
37
|
+
response = get_from_rest_api("statuses/friends/#{@username}")
|
38
|
+
show_users_from_rest_api(*response)
|
32
39
|
end
|
33
40
|
|
34
41
|
def home(args = [], options = nil)
|
@@ -41,15 +48,15 @@ module Tweetwine
|
|
41
48
|
show_statuses_from_rest_api(*response)
|
42
49
|
end
|
43
50
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
51
|
+
def search(args = [], options = nil)
|
52
|
+
raise ArgumentError, "No search word" if args.empty?
|
53
|
+
query = if options && options[:bin_op] == :or then args.join(" OR ") else args.join(" ") end
|
54
|
+
response = get_from_search_api(query, :num_statuses, :page)
|
55
|
+
show_statuses_from_search_api(*response["results"])
|
48
56
|
end
|
49
57
|
|
50
58
|
def update(args = [], options = nil)
|
51
|
-
new_status =
|
52
|
-
new_status = @status_update_factory.create(new_status)
|
59
|
+
new_status = create_status_update(args.join(" "))
|
53
60
|
completed = false
|
54
61
|
unless new_status.empty?
|
55
62
|
@io.show_status_preview(new_status)
|
@@ -63,21 +70,10 @@ module Tweetwine
|
|
63
70
|
@io.info "Cancelled." unless completed
|
64
71
|
end
|
65
72
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
def followers(args = [], options = nil)
|
72
|
-
response = get_from_rest_api("statuses/followers/#{@username}")
|
73
|
-
show_users_from_rest_api(*response)
|
74
|
-
end
|
75
|
-
|
76
|
-
def search(args = [], options = nil)
|
77
|
-
raise ArgumentError, "No search word" if args.empty?
|
78
|
-
query = if options && options[:bin_op] == :or then args.join(" OR ") else args.join(" ") end
|
79
|
-
response = get_from_search_api(query, :num_statuses, :page)
|
80
|
-
show_statuses_from_search_api(*response["results"])
|
73
|
+
def user(args = [], options = nil)
|
74
|
+
user = if args.empty? then @username else args.first end
|
75
|
+
response = get_from_rest_api("statuses/user_timeline/#{user}", :num_statuses, :page)
|
76
|
+
show_statuses_from_rest_api(*response)
|
81
77
|
end
|
82
78
|
|
83
79
|
private
|
@@ -158,57 +154,32 @@ module Tweetwine
|
|
158
154
|
end
|
159
155
|
end
|
160
156
|
|
161
|
-
|
162
|
-
|
163
|
-
@io
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
def create(status)
|
168
|
-
StatusUpdate.new(status, @io, @url_shortener).to_s
|
157
|
+
def create_status_update(status)
|
158
|
+
status = if status.nil? || status.empty?
|
159
|
+
@io.prompt("Status update")
|
160
|
+
else
|
161
|
+
status.dup
|
169
162
|
end
|
163
|
+
status.strip!
|
164
|
+
shorten_urls_in(status) if @url_shortener
|
165
|
+
truncate_status(status) if status.length > MAX_STATUS_LENGTH
|
166
|
+
status
|
170
167
|
end
|
171
168
|
|
172
|
-
|
173
|
-
|
174
|
-
@
|
175
|
-
@url_shortener = url_shortener
|
176
|
-
@text = prepare(status)
|
177
|
-
end
|
178
|
-
|
179
|
-
def to_s
|
180
|
-
@text.to_s
|
169
|
+
def shorten_urls_in(status)
|
170
|
+
url_pairs = URI.extract(status, ["http", "https"]).uniq.map do |url_to_be_shortened|
|
171
|
+
[url_to_be_shortened, @url_shortener.shorten(url_to_be_shortened)]
|
181
172
|
end
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
def prepare(status)
|
186
|
-
status = unless status
|
187
|
-
@io.prompt("Status update")
|
188
|
-
else
|
189
|
-
status.dup
|
190
|
-
end
|
191
|
-
status.strip!
|
192
|
-
shorten_urls!(status) if @url_shortener
|
193
|
-
truncate!(status) if status.length > MAX_STATUS_LENGTH
|
194
|
-
status
|
195
|
-
end
|
196
|
-
|
197
|
-
def truncate!(status)
|
198
|
-
status.replace status[0...MAX_STATUS_LENGTH]
|
199
|
-
@io.warn("Status will be truncated.")
|
173
|
+
url_pairs.reject { |pair| pair.last.nil? || pair.last.empty? }.each do |url_pair|
|
174
|
+
status.gsub!(url_pair.first, url_pair.last)
|
200
175
|
end
|
176
|
+
rescue HttpError, LoadError => e
|
177
|
+
@io.warn "#{e}. Skipping URL shortening..."
|
178
|
+
end
|
201
179
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
end
|
206
|
-
url_pairs.reject { |pair| pair.last.nil? || pair.last.empty? }.each do |url_pair|
|
207
|
-
status.gsub!(url_pair.first, url_pair.last)
|
208
|
-
end
|
209
|
-
rescue HttpError, LoadError => e
|
210
|
-
@io.warn "#{e}. Skipping URL shortening..."
|
211
|
-
end
|
180
|
+
def truncate_status(status)
|
181
|
+
status.replace status[0...MAX_STATUS_LENGTH]
|
182
|
+
@io.warn("Status will be truncated.")
|
212
183
|
end
|
213
184
|
end
|
214
185
|
end
|
data/lib/tweetwine/io.rb
CHANGED
@@ -46,7 +46,7 @@ module Tweetwine
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def show_record(record)
|
49
|
-
clean_record
|
49
|
+
clean_record(record)
|
50
50
|
if record[:status]
|
51
51
|
show_record_as_user_with_status(record)
|
52
52
|
else
|
@@ -56,10 +56,10 @@ module Tweetwine
|
|
56
56
|
|
57
57
|
private
|
58
58
|
|
59
|
-
def clean_record
|
59
|
+
def clean_record(record)
|
60
60
|
record.each_pair do |key, value|
|
61
61
|
if value.is_a? Hash
|
62
|
-
clean_record
|
62
|
+
clean_record(value)
|
63
63
|
else
|
64
64
|
unless value.nil?
|
65
65
|
value = value.to_s
|
data/lib/tweetwine/meta.rb
CHANGED
@@ -27,13 +27,13 @@ module Tweetwine
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def do_with_retries
|
30
|
-
|
30
|
+
retries = 0
|
31
31
|
begin
|
32
|
-
tries += 1
|
33
32
|
yield
|
34
33
|
rescue Errno::ECONNRESET, RestClient::RequestTimeout => e
|
35
|
-
if
|
36
|
-
|
34
|
+
if retries < MAX_RETRIES
|
35
|
+
retries += 1
|
36
|
+
timeout = RETRY_BASE_WAIT_TIMEOUT**retries
|
37
37
|
@io.warn("Could not connect -- retrying in #{timeout} seconds") if @io
|
38
38
|
sleep timeout
|
39
39
|
retry
|
data/lib/tweetwine/util.rb
CHANGED
@@ -71,7 +71,7 @@ module Tweetwine
|
|
71
71
|
|
72
72
|
def self.find_hash_path(hash, path)
|
73
73
|
return nil if hash.nil?
|
74
|
-
path = [path]
|
74
|
+
path = [path] unless path.is_a? Array
|
75
75
|
path.inject(hash) do |result, key|
|
76
76
|
return hash.default if key.nil? || result.nil?
|
77
77
|
result[key]
|
data/test/client_test.rb
CHANGED
@@ -220,6 +220,7 @@ class ClientTest < Test::Unit::TestCase
|
|
220
220
|
|
221
221
|
should "cancel a status update via argument, when empty status" do
|
222
222
|
@http_resource.expects(:[]).never
|
223
|
+
@io.expects(:prompt).with("Status update").returns("")
|
223
224
|
@io.expects(:confirm).never
|
224
225
|
@io.expects(:info).with("Cancelled.")
|
225
226
|
@io.expects(:show_record).never
|
data/test/retrying_http_test.rb
CHANGED
@@ -68,10 +68,10 @@ class ClientTest < Test::Unit::TestCase
|
|
68
68
|
should "retry connection a maximum of certain number of times, case #{error_class}" do
|
69
69
|
retrying_calls = sequence("Retrying Client calls")
|
70
70
|
io_calls = sequence("IO")
|
71
|
-
Client::MAX_RETRIES.times do
|
71
|
+
(Client::MAX_RETRIES + 1).times do
|
72
72
|
RestClient.expects(:get).with("https://unresponsive.org").in_sequence(retrying_calls).raises(error_class)
|
73
73
|
end
|
74
|
-
|
74
|
+
Client::MAX_RETRIES.times do
|
75
75
|
@io.expects(:warn).in_sequence(io_calls)
|
76
76
|
end
|
77
77
|
assert_raise(HttpError) { @client.get("https://unresponsive.org") }
|
@@ -131,10 +131,10 @@ class ResourceTest < Test::Unit::TestCase
|
|
131
131
|
should "retry connection a maximum of certain number of times, case #{error_class}" do
|
132
132
|
retrying_calls = sequence("Retrying Resource calls")
|
133
133
|
io_calls = sequence("IO")
|
134
|
-
Resource::MAX_RETRIES.times do
|
134
|
+
(Resource::MAX_RETRIES + 1).times do
|
135
135
|
@wrapped.expects(:get).in_sequence(retrying_calls).raises(error_class)
|
136
136
|
end
|
137
|
-
|
137
|
+
Resource::MAX_RETRIES.times do
|
138
138
|
@io.expects(:warn).in_sequence(io_calls)
|
139
139
|
end
|
140
140
|
assert_raise(HttpError) { @resource.get }
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 10
|
9
|
+
version: 0.2.10
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tuomas Kareinen
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-02-
|
17
|
+
date: 2010-02-28 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -91,7 +91,7 @@ licenses: []
|
|
91
91
|
post_install_message:
|
92
92
|
rdoc_options:
|
93
93
|
- --title
|
94
|
-
- tweetwine 0.2.
|
94
|
+
- tweetwine 0.2.10
|
95
95
|
- --main
|
96
96
|
- README.rdoc
|
97
97
|
- --exclude
|