tuomas-tweetwine 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +4 -0
- data/Rakefile +1 -1
- data/bin/tweetwine +3 -0
- data/lib/tweetwine/client.rb +26 -20
- data/test/client_test.rb +24 -9
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
data/Rakefile
CHANGED
data/bin/tweetwine
CHANGED
@@ -30,6 +30,9 @@ Usage: tweetwine [options...] [command]
|
|
30
30
|
opt.on("-n", "--num N", Integer, "The number of statuses to fetch, defaults to #{Client::DEFAULT_NUM_STATUSES}") do |arg|
|
31
31
|
options[:num_statuses] = arg
|
32
32
|
end
|
33
|
+
opt.on("-p", "--page N", Integer, "The page number of the statuses to fetch, defaults to #{Client::DEFAULT_PAGE_NUM}") do |arg|
|
34
|
+
options[:page_num] = arg
|
35
|
+
end
|
33
36
|
opt.on_tail("-h", "--help", "Show this help message") do
|
34
37
|
puts opt
|
35
38
|
exit(1)
|
data/lib/tweetwine/client.rb
CHANGED
@@ -5,12 +5,12 @@ module Tweetwine
|
|
5
5
|
class ClientError < RuntimeError; end
|
6
6
|
|
7
7
|
class Client
|
8
|
-
attr_reader :num_statuses
|
8
|
+
attr_reader :num_statuses, :page_num
|
9
9
|
|
10
10
|
COMMANDS = [:home, :mentions, :user, :update]
|
11
11
|
|
12
12
|
DEFAULT_NUM_STATUSES = 20
|
13
|
-
|
13
|
+
DEFAULT_PAGE_NUM = 1
|
14
14
|
MAX_STATUS_LENGTH = 140
|
15
15
|
|
16
16
|
def initialize(options)
|
@@ -18,28 +18,21 @@ module Tweetwine
|
|
18
18
|
raise ArgumentError, "No authentication data given" if @username.empty?
|
19
19
|
@base_url = "https://#{@username}:#{options[:password]}@twitter.com/"
|
20
20
|
@colorize = options[:colorize] || false
|
21
|
-
@num_statuses =
|
22
|
-
|
23
|
-
options[:num_statuses]
|
24
|
-
else
|
25
|
-
raise ArgumentError, "Invalid number of statuses to show -- must be between 1..#{MAX_NUM_STATUSES}"
|
26
|
-
end
|
27
|
-
else
|
28
|
-
DEFAULT_NUM_STATUSES
|
29
|
-
end
|
21
|
+
@num_statuses = parse_positive_int_option(options[:num_statuses], DEFAULT_NUM_STATUSES, 1, "number of statuses_to_show")
|
22
|
+
@page_num = parse_positive_int_option(options[:page_num], DEFAULT_PAGE_NUM, 1, "page number")
|
30
23
|
@io = IO.new(options)
|
31
24
|
end
|
32
25
|
|
33
26
|
def home
|
34
|
-
|
27
|
+
get_result_as_json_and_show "statuses/friends_timeline"
|
35
28
|
end
|
36
29
|
|
37
30
|
def mentions
|
38
|
-
|
31
|
+
get_result_as_json_and_show "statuses/mentions"
|
39
32
|
end
|
40
33
|
|
41
34
|
def user(user = @username)
|
42
|
-
|
35
|
+
get_result_as_json_and_show "statuses/user_timeline/#{user}"
|
43
36
|
end
|
44
37
|
|
45
38
|
def update(new_status = nil)
|
@@ -59,16 +52,29 @@ module Tweetwine
|
|
59
52
|
|
60
53
|
private
|
61
54
|
|
62
|
-
def
|
63
|
-
|
55
|
+
def parse_positive_int_option(value, default, min, name_for_error)
|
56
|
+
if value
|
57
|
+
value = value.to_i
|
58
|
+
if value >= min
|
59
|
+
value
|
60
|
+
else
|
61
|
+
raise ArgumentError, "Invalid #{name_for_error} -- must be greater than or equal to #{min}"
|
62
|
+
end
|
63
|
+
else
|
64
|
+
default
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_result_as_json_and_show(url_body)
|
69
|
+
@io.show_statuses JSON.parse(get(url_body + ".json?count=#{@num_statuses}&page=#{@page_num}"))
|
64
70
|
end
|
65
71
|
|
66
|
-
def get(
|
67
|
-
rest_client_action(:get, @base_url +
|
72
|
+
def get(body_url)
|
73
|
+
rest_client_action(:get, @base_url + body_url)
|
68
74
|
end
|
69
75
|
|
70
|
-
def post(
|
71
|
-
rest_client_action(:post, @base_url +
|
76
|
+
def post(body_url, body)
|
77
|
+
rest_client_action(:post, @base_url + body_url, body)
|
72
78
|
end
|
73
79
|
|
74
80
|
def rest_client_action(action, *args)
|
data/test/client_test.rb
CHANGED
@@ -12,18 +12,32 @@ class ClientTest < Test::Unit::TestCase
|
|
12
12
|
assert_nothing_raised { Client.new({ :username => "foo", :password => "bar" }) }
|
13
13
|
end
|
14
14
|
|
15
|
-
should "use default
|
15
|
+
should "use default number of statuses if not configured otherwise" do
|
16
16
|
@client = Client.new({ :username => "foo", :password => "bar" })
|
17
17
|
assert_equal Client::DEFAULT_NUM_STATUSES, @client.num_statuses
|
18
18
|
end
|
19
19
|
|
20
|
-
should "use configured
|
20
|
+
should "use configured number of statuses if in allowed range" do
|
21
21
|
@client = Client.new({ :username => "foo", :password => "bar", :num_statuses => 12 })
|
22
22
|
assert_equal 12, @client.num_statuses
|
23
23
|
end
|
24
24
|
|
25
|
-
should "raise an exception for configured
|
26
|
-
assert_raises(ArgumentError) { Client.new({ :username => "foo", :password => "bar", :num_statuses =>
|
25
|
+
should "raise an exception for configured number of statuses if not in allowed range" do
|
26
|
+
assert_raises(ArgumentError) { Client.new({ :username => "foo", :password => "bar", :num_statuses => 0 }) }
|
27
|
+
end
|
28
|
+
|
29
|
+
should "use default page number if not configured otherwise" do
|
30
|
+
@client = Client.new({ :username => "foo", :password => "bar" })
|
31
|
+
assert_equal Client::DEFAULT_PAGE_NUM, @client.page_num
|
32
|
+
end
|
33
|
+
|
34
|
+
should "use configured page number if in allowed range" do
|
35
|
+
@client = Client.new({ :username => "foo", :password => "bar", :page_num => 12 })
|
36
|
+
assert_equal 12, @client.page_num
|
37
|
+
end
|
38
|
+
|
39
|
+
should "raise an exception for configured page number if not in allowed range" do
|
40
|
+
assert_raises(ArgumentError) { Client.new({ :username => "foo", :password => "bar", :page_num => 0 }) }
|
27
41
|
end
|
28
42
|
end
|
29
43
|
|
@@ -32,11 +46,12 @@ class ClientTest < Test::Unit::TestCase
|
|
32
46
|
@client = Client.new({ :username => "foo", :password => "bar" })
|
33
47
|
@io = mock()
|
34
48
|
@client.instance_variable_set(:@io, @io)
|
49
|
+
@query_params = "count=#{Client::DEFAULT_NUM_STATUSES}&page=#{Client::DEFAULT_PAGE_NUM}"
|
35
50
|
end
|
36
51
|
|
37
52
|
should "raise ClientError for invalid request" do
|
38
53
|
RestClient.expects(:get) \
|
39
|
-
.with("https://foo:bar@twitter.com/statuses/friends_timeline.json
|
54
|
+
.with("https://foo:bar@twitter.com/statuses/friends_timeline.json?#{@query_params}") \
|
40
55
|
.raises(RestClient::Unauthorized)
|
41
56
|
assert_raises(ClientError) { @client.home }
|
42
57
|
end
|
@@ -55,7 +70,7 @@ class ClientTest < Test::Unit::TestCase
|
|
55
70
|
}
|
56
71
|
]
|
57
72
|
RestClient.expects(:get) \
|
58
|
-
.with("https://foo:bar@twitter.com/statuses/friends_timeline.json
|
73
|
+
.with("https://foo:bar@twitter.com/statuses/friends_timeline.json?#{@query_params}") \
|
59
74
|
.returns(statuses.to_json)
|
60
75
|
@io.expects(:show_statuses).with(statuses)
|
61
76
|
@client.home
|
@@ -77,7 +92,7 @@ class ClientTest < Test::Unit::TestCase
|
|
77
92
|
}
|
78
93
|
]
|
79
94
|
RestClient.expects(:get) \
|
80
|
-
.with("https://foo:bar@twitter.com/statuses/mentions.json
|
95
|
+
.with("https://foo:bar@twitter.com/statuses/mentions.json?#{@query_params}") \
|
81
96
|
.returns(statuses.to_json)
|
82
97
|
@io.expects(:show_statuses).with(statuses)
|
83
98
|
@client.mentions
|
@@ -92,7 +107,7 @@ class ClientTest < Test::Unit::TestCase
|
|
92
107
|
}
|
93
108
|
]
|
94
109
|
RestClient.expects(:get) \
|
95
|
-
.with("https://foo:bar@twitter.com/statuses/user_timeline/zanzibar.json
|
110
|
+
.with("https://foo:bar@twitter.com/statuses/user_timeline/zanzibar.json?#{@query_params}") \
|
96
111
|
.returns(statuses.to_json)
|
97
112
|
@io.expects(:show_statuses).with(statuses)
|
98
113
|
@client.user("zanzibar")
|
@@ -107,7 +122,7 @@ class ClientTest < Test::Unit::TestCase
|
|
107
122
|
}
|
108
123
|
]
|
109
124
|
RestClient.expects(:get) \
|
110
|
-
.with("https://foo:bar@twitter.com/statuses/user_timeline/foo.json
|
125
|
+
.with("https://foo:bar@twitter.com/statuses/user_timeline/foo.json?#{@query_params}") \
|
111
126
|
.returns(statuses.to_json)
|
112
127
|
@io.expects(:show_statuses).with(statuses)
|
113
128
|
@client.user
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tuomas-tweetwine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tuomas Kareinen
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-12 00:00:00 -07:00
|
13
13
|
default_executable: tweetwine
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -58,12 +58,12 @@ files:
|
|
58
58
|
- test/test_config.yaml
|
59
59
|
- test/test_helper.rb
|
60
60
|
- test/util_test.rb
|
61
|
-
has_rdoc:
|
61
|
+
has_rdoc: false
|
62
62
|
homepage: http://github.com/tuomas/tweetwine
|
63
63
|
post_install_message:
|
64
64
|
rdoc_options:
|
65
65
|
- --title
|
66
|
-
- Tweetwine 0.1.
|
66
|
+
- Tweetwine 0.1.4
|
67
67
|
- --main
|
68
68
|
- README.rdoc
|
69
69
|
- --exclude
|