twurl 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/lib/twurl/cli.rb +17 -0
- data/lib/twurl/oauth_client.rb +8 -4
- data/lib/twurl/version.rb +1 -1
- data/test/cli_test.rb +17 -1
- data/test/oauth_client_test.rb +2 -1
- metadata +5 -4
data/CHANGELOG
ADDED
data/lib/twurl/cli.rb
CHANGED
@@ -39,6 +39,7 @@ module Twurl
|
|
39
39
|
Twurl.options = Options.new
|
40
40
|
Twurl.options.trace = false
|
41
41
|
Twurl.options.data = {}
|
42
|
+
Twurl.options.headers = {}
|
42
43
|
|
43
44
|
option_parser = OptionParser.new do |o|
|
44
45
|
o.extend AvailableOptions
|
@@ -64,11 +65,13 @@ module Twurl
|
|
64
65
|
o.section "Common options:" do
|
65
66
|
trace
|
66
67
|
data
|
68
|
+
headers
|
67
69
|
host
|
68
70
|
quiet
|
69
71
|
disable_ssl
|
70
72
|
request_method
|
71
73
|
help
|
74
|
+
version
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
@@ -190,6 +193,13 @@ module Twurl
|
|
190
193
|
end
|
191
194
|
end
|
192
195
|
|
196
|
+
def headers
|
197
|
+
on('-A', '--header [header]', 'Adds the specified header to the request to the HTTP server.') do |header|
|
198
|
+
key, value = header.split(': ')
|
199
|
+
options.headers[key] = value
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
193
203
|
def host
|
194
204
|
on('-H', '--host [host]', 'Specify host to make requests to (default: api.twitter.com)') do |host|
|
195
205
|
options.host = host
|
@@ -220,6 +230,13 @@ module Twurl
|
|
220
230
|
exit
|
221
231
|
end
|
222
232
|
end
|
233
|
+
|
234
|
+
def version
|
235
|
+
on_tail("-v", "--version", "Show version") do
|
236
|
+
CLI.puts Version
|
237
|
+
exit
|
238
|
+
end
|
239
|
+
end
|
223
240
|
end
|
224
241
|
end
|
225
242
|
|
data/lib/twurl/oauth_client.rb
CHANGED
@@ -64,15 +64,19 @@ module Twurl
|
|
64
64
|
|
65
65
|
[:get, :post, :put, :delete, :options, :head, :copy].each do |request_method|
|
66
66
|
class_eval(<<-EVAL, __FILE__, __LINE__)
|
67
|
-
def #{request_method}(url, options
|
67
|
+
def #{request_method}(url, *options)
|
68
68
|
# configure_http!
|
69
|
-
access_token.#{request_method}(url, options)
|
69
|
+
access_token.#{request_method}(url, *options)
|
70
70
|
end
|
71
71
|
EVAL
|
72
72
|
end
|
73
73
|
|
74
74
|
def perform_request_from_options(options)
|
75
|
-
|
75
|
+
if [:post, :put].include?(options.request_method.to_sym)
|
76
|
+
send(options.request_method, options.path, options.data, options.headers)
|
77
|
+
else
|
78
|
+
send(options.request_method, options.path, options.headers)
|
79
|
+
end
|
76
80
|
end
|
77
81
|
|
78
82
|
def exchange_credentials_for_access_token
|
@@ -167,4 +171,4 @@ module Twurl
|
|
167
171
|
@access_token ||= OAuth::AccessToken.new(consumer, token, secret)
|
168
172
|
end
|
169
173
|
end
|
170
|
-
end
|
174
|
+
end
|
data/lib/twurl/version.rb
CHANGED
data/test/cli_test.rb
CHANGED
@@ -94,6 +94,22 @@ class Twurl::CLI::OptionParsingTest < Test::Unit::TestCase
|
|
94
94
|
end
|
95
95
|
include DataParsingTests
|
96
96
|
|
97
|
+
module HeaderParsingTests
|
98
|
+
def test_extracting_a_single_header
|
99
|
+
options = Twurl::CLI.parse_options(['-A', 'Key: Value'])
|
100
|
+
assert_equal({'Key' => 'Value'}, options.headers)
|
101
|
+
|
102
|
+
options = Twurl::CLI.parse_options(['--header', 'Key: Value'])
|
103
|
+
assert_equal({'Key' => 'Value'}, options.headers)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_multiple_headers_when_option_is_specified_multiple_times_on_command_line_collects_all
|
107
|
+
options = Twurl::CLI.parse_options(['-A', 'Key: Value', '-A', 'Another: Pair'])
|
108
|
+
assert_equal({'Key' => 'Value', 'Another' => 'Pair'}, options.headers)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
include HeaderParsingTests
|
112
|
+
|
97
113
|
module SSLDisablingTests
|
98
114
|
def test_ssl_is_on_by_default
|
99
115
|
options = Twurl::CLI.parse_options([])
|
@@ -126,4 +142,4 @@ class Twurl::CLI::OptionParsingTest < Test::Unit::TestCase
|
|
126
142
|
end
|
127
143
|
end
|
128
144
|
include HostOptionTests
|
129
|
-
end
|
145
|
+
end
|
data/test/oauth_client_test.rb
CHANGED
@@ -11,6 +11,7 @@ class Twurl::OAuthClient::AbstractOAuthClientTest < Test::Unit::TestCase
|
|
11
11
|
options.request_method = 'get'
|
12
12
|
options.path = '/path/does/not/matter.xml'
|
13
13
|
options.data = {}
|
14
|
+
options.headers = {}
|
14
15
|
|
15
16
|
Twurl.options = options
|
16
17
|
end
|
@@ -159,4 +160,4 @@ class Twurl::OAuthClient::CredentialsForAccessTokenExchangeTest < Twurl::OAuthCl
|
|
159
160
|
client.exchange_credentials_for_access_token
|
160
161
|
assert !client.needs_to_authorize?
|
161
162
|
end
|
162
|
-
end
|
163
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twurl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 3
|
10
|
+
version: 0.6.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marcel Molina
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2011-01-04 00:00:00 -08:00
|
20
20
|
default_executable: twurl
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -93,6 +93,7 @@ extra_rdoc_files:
|
|
93
93
|
- INSTALL
|
94
94
|
files:
|
95
95
|
- .gitignore
|
96
|
+
- CHANGELOG
|
96
97
|
- COPYING
|
97
98
|
- Gemfile
|
98
99
|
- Gemfile.lock
|