twurl 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/INSTALL.md +2 -2
- data/README.md +2 -2
- data/lib/twurl/aliases_controller.rb +6 -2
- data/lib/twurl/app_only_oauth_client.rb +3 -6
- data/lib/twurl/cli.rb +20 -29
- data/lib/twurl/oauth_client.rb +21 -16
- data/lib/twurl/request_controller.rb +3 -3
- data/lib/twurl/version.rb +1 -1
- data/twurl.gemspec +3 -3
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9120a8daa09529e8e484e2bc15da6042ea1ced1100b1a23c8ea2a2481e194f2b
|
4
|
+
data.tar.gz: 549c25417c3e00e35bab15fb9299a6103b3a01717a3a56b9c78cc388cd1c20fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3df6c245df33cccfaec2ed2a28d370b5ed3de81a1f96bfb17b5852b4cce209bae975bdbfe9d9fdf7bd117f8bbd8826b4265a3acb5cc509103032ebcf2dc405ac
|
7
|
+
data.tar.gz: 300977ca1182b02d1f1673754b49e015a9e38b5c064967044f5243252097e6caf29a4d37ec0c385e35460a1db34265e2d7947449427abf83bc868d75cfb5833f
|
data/INSTALL.md
CHANGED
@@ -10,7 +10,7 @@ $ gem install twurl
|
|
10
10
|
```sh
|
11
11
|
# verify installation
|
12
12
|
$ twurl -v
|
13
|
-
0.9.
|
13
|
+
0.9.7
|
14
14
|
```
|
15
15
|
|
16
16
|
## Install from source
|
@@ -32,5 +32,5 @@ If you don't want to install Twurl globally on your system, use `--path` [option
|
|
32
32
|
```
|
33
33
|
$ bundle install --path path/to/directory
|
34
34
|
$ bundle exec twurl -v
|
35
|
-
0.9.
|
35
|
+
0.9.7
|
36
36
|
```
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Twurl
|
2
2
|
|
3
3
|
[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/twitter/twurl/blob/master/LICENSE)
|
4
|
-
|
5
|
-
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/twurl.svg)](https://badge.fury.io/rb/twurl)
|
5
|
+
[![CI](https://github.com/twitter/twurl/actions/workflows/ci.yml/badge.svg)](https://github.com/twitter/twurl/actions/workflows/ci.yml)
|
6
6
|
|
7
7
|
Twurl is like curl, but tailored specifically for the Twitter API.
|
8
8
|
It knows how to grant an access token to a client application for
|
@@ -15,9 +15,13 @@ module Twurl
|
|
15
15
|
end
|
16
16
|
when 1
|
17
17
|
if options.path
|
18
|
-
|
18
|
+
if Twurl::CLI::SUPPORTED_COMMANDS.include?(options.subcommands.first)
|
19
|
+
raise Exception, "ERROR: '#{options.subcommands.first}' is reserved for commands. Please use different alias name."
|
20
|
+
else
|
21
|
+
OAuthClient.rcfile.alias(options.subcommands.first, options.path)
|
22
|
+
end
|
19
23
|
else
|
20
|
-
|
24
|
+
raise Exception, NO_PATH_PROVIDED_MESSAGE
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
@@ -57,12 +57,9 @@ module Twurl
|
|
57
57
|
http.set_debug_output(Twurl.options.debug_output_io) if Twurl.options.trace
|
58
58
|
http.read_timeout = http.open_timeout = Twurl.options.timeout || 60
|
59
59
|
http.open_timeout = Twurl.options.connection_timeout if Twurl.options.connection_timeout
|
60
|
-
|
61
|
-
http.
|
62
|
-
|
63
|
-
http.use_ssl = true
|
64
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
65
|
-
end
|
60
|
+
http.max_retries = 0
|
61
|
+
http.use_ssl = true
|
62
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
66
63
|
http
|
67
64
|
end
|
68
65
|
|
data/lib/twurl/cli.rb
CHANGED
@@ -6,8 +6,6 @@ module Twurl
|
|
6
6
|
PROTOCOL_PATTERN = /^\w+:\/\//
|
7
7
|
README = File.dirname(__FILE__) + '/../../README.md'
|
8
8
|
@output ||= STDOUT
|
9
|
-
class NoPathFound < Exception
|
10
|
-
end
|
11
9
|
|
12
10
|
class << self
|
13
11
|
attr_accessor :output
|
@@ -15,8 +13,8 @@ module Twurl
|
|
15
13
|
def run(args)
|
16
14
|
begin
|
17
15
|
options = parse_options(args)
|
18
|
-
rescue
|
19
|
-
|
16
|
+
rescue Twurl::Exception => exception
|
17
|
+
abort(exception.message)
|
20
18
|
end
|
21
19
|
dispatch(options)
|
22
20
|
end
|
@@ -80,7 +78,6 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
80
78
|
headers
|
81
79
|
host
|
82
80
|
quiet
|
83
|
-
disable_ssl
|
84
81
|
request_method
|
85
82
|
help
|
86
83
|
version
|
@@ -98,11 +95,11 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
98
95
|
begin
|
99
96
|
arguments = option_parser.parse!(args)
|
100
97
|
rescue OptionParser::InvalidOption
|
101
|
-
|
102
|
-
|
98
|
+
raise Exception "ERROR: undefined option"
|
99
|
+
rescue Twurl::Exception
|
100
|
+
raise
|
103
101
|
rescue
|
104
|
-
|
105
|
-
exit
|
102
|
+
raise Exception "ERROR: invalid argument"
|
106
103
|
end
|
107
104
|
Twurl.options.command = extract_command!(arguments)
|
108
105
|
Twurl.options.path = extract_path!(arguments)
|
@@ -110,7 +107,7 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
110
107
|
|
111
108
|
if Twurl.options.command == DEFAULT_COMMAND and Twurl.options.path.nil? and Twurl.options.args.empty?
|
112
109
|
CLI.puts option_parser
|
113
|
-
raise
|
110
|
+
raise Exception, "No path found"
|
114
111
|
end
|
115
112
|
|
116
113
|
Twurl.options
|
@@ -172,7 +169,7 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
172
169
|
|
173
170
|
def escape_params(params)
|
174
171
|
CGI::parse(params).map do |key, value|
|
175
|
-
"#{CGI.escape
|
172
|
+
"#{CGI.escape(key)}=#{CGI.escape(value.first)}"
|
176
173
|
end.join("&")
|
177
174
|
end
|
178
175
|
end
|
@@ -234,12 +231,12 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
234
231
|
|
235
232
|
def data
|
236
233
|
on('-d', '--data [data]', 'Sends the specified data in a POST request to the HTTP server.') do |data|
|
237
|
-
if options.args.count { |item|
|
238
|
-
options.
|
234
|
+
if options.args.count { |item| /^content-type:\s+application\/json/i.match(item) } > 0
|
235
|
+
options.json_data = true
|
236
|
+
options.data = data
|
239
237
|
else
|
240
|
-
|
241
|
-
key
|
242
|
-
options.data[key] = value
|
238
|
+
CGI.parse(data).each_pair do |key, value|
|
239
|
+
options.data[key] = value.first
|
243
240
|
end
|
244
241
|
end
|
245
242
|
end
|
@@ -247,9 +244,13 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
247
244
|
|
248
245
|
def raw_data
|
249
246
|
on('-r', '--raw-data [data]', 'Sends the specified data as it is in a POST request to the HTTP server.') do |data|
|
250
|
-
|
251
|
-
|
247
|
+
if options.raw_data
|
248
|
+
raise Exception, "ERROR: can't specify '-r' option more than once"
|
249
|
+
elsif options.args.include?('-d') || options.args.include?('--data')
|
250
|
+
raise Exception, "ERROR: can't use '-r' and '-d' options together"
|
252
251
|
end
|
252
|
+
options.raw_data = true
|
253
|
+
options.data = data
|
253
254
|
end
|
254
255
|
end
|
255
256
|
|
@@ -277,12 +278,6 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
277
278
|
end
|
278
279
|
end
|
279
280
|
|
280
|
-
def disable_ssl
|
281
|
-
on('-U', '--no-ssl', 'Disable SSL (default: SSL is enabled)') do |use_ssl|
|
282
|
-
options.protocol = 'http'
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
281
|
def request_method
|
287
282
|
on('-X', '--request-method [method]', 'Request method (default: GET)') do |request_method|
|
288
283
|
options.request_method = request_method.downcase
|
@@ -298,7 +293,7 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
298
293
|
|
299
294
|
def version
|
300
295
|
on_tail("-v", "--version", "Show version") do
|
301
|
-
CLI.puts Version
|
296
|
+
CLI.puts "twurl version: #{Version}\nplatform: #{RUBY_ENGINE} #{RUBY_VERSION} (#{RUBY_PLATFORM})"
|
302
297
|
exit
|
303
298
|
end
|
304
299
|
end
|
@@ -374,10 +369,6 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
374
369
|
"#{protocol}://#{host}"
|
375
370
|
end
|
376
371
|
|
377
|
-
def ssl?
|
378
|
-
protocol == 'https'
|
379
|
-
end
|
380
|
-
|
381
372
|
def debug_output_io
|
382
373
|
super || STDERR
|
383
374
|
end
|
data/lib/twurl/oauth_client.rb
CHANGED
@@ -162,16 +162,20 @@ module Twurl
|
|
162
162
|
|
163
163
|
request.body = multipart_body.join
|
164
164
|
request.content_type = "multipart/form-data, boundary=\"#{boundary}\""
|
165
|
-
elsif
|
166
|
-
request.body = options.data
|
165
|
+
elsif options.json_data
|
166
|
+
request.body = options.data
|
167
167
|
elsif options.data
|
168
|
-
request.content_type = "application/x-www-form-urlencoded"
|
169
|
-
if options.
|
170
|
-
request.body = options.data
|
168
|
+
request.content_type = "application/x-www-form-urlencoded" unless request.content_type
|
169
|
+
if options.raw_data
|
170
|
+
request.body = options.data
|
171
171
|
else
|
172
|
-
|
173
|
-
|
174
|
-
|
172
|
+
begin
|
173
|
+
request.body = options.data.map do |key, value|
|
174
|
+
"#{key}" + (value.nil? ? "" : "=#{CGI.escape(value)}")
|
175
|
+
end.join("&")
|
176
|
+
rescue
|
177
|
+
raise Exception, "ERROR: failed to parse POST request body"
|
178
|
+
end
|
175
179
|
end
|
176
180
|
end
|
177
181
|
request
|
@@ -202,7 +206,11 @@ module Twurl
|
|
202
206
|
def perform_pin_authorize_workflow
|
203
207
|
@request_token = consumer.get_request_token
|
204
208
|
CLI.puts("Go to #{generate_authorize_url} and paste in the supplied PIN")
|
205
|
-
|
209
|
+
begin
|
210
|
+
pin = STDIN.gets.chomp
|
211
|
+
rescue SystemExit, Interrupt
|
212
|
+
raise Exception, "Operation cancelled"
|
213
|
+
end
|
206
214
|
access_token = @request_token.get_access_token(:oauth_verifier => pin.chomp)
|
207
215
|
{:oauth_token => access_token.token, :oauth_token_secret => access_token.secret}
|
208
216
|
end
|
@@ -212,7 +220,7 @@ module Twurl
|
|
212
220
|
params = request['Authorization'].sub(/^OAuth\s+/, '').split(/,\s+/).map { |p|
|
213
221
|
k, v = p.split('=')
|
214
222
|
v =~ /"(.*?)"/
|
215
|
-
"#{k}=#{CGI
|
223
|
+
"#{k}=#{CGI.escape($1)}"
|
216
224
|
}.join('&')
|
217
225
|
"#{Twurl.options.base_url}#{request.path}?#{params}"
|
218
226
|
end
|
@@ -260,12 +268,9 @@ module Twurl
|
|
260
268
|
consumer.http.set_debug_output(Twurl.options.debug_output_io) if Twurl.options.trace
|
261
269
|
consumer.http.read_timeout = consumer.http.open_timeout = Twurl.options.timeout || 60
|
262
270
|
consumer.http.open_timeout = Twurl.options.connection_timeout if Twurl.options.connection_timeout
|
263
|
-
|
264
|
-
consumer.http.
|
265
|
-
|
266
|
-
consumer.http.use_ssl = true
|
267
|
-
consumer.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
268
|
-
end
|
271
|
+
consumer.http.max_retries = 0
|
272
|
+
consumer.http.use_ssl = true
|
273
|
+
consumer.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
269
274
|
end
|
270
275
|
|
271
276
|
def consumer
|
@@ -22,11 +22,11 @@ module Twurl
|
|
22
22
|
}
|
23
23
|
}
|
24
24
|
rescue URI::InvalidURIError
|
25
|
-
|
25
|
+
raise Exception, INVALID_URI_MESSAGE
|
26
26
|
rescue Net::ReadTimeout
|
27
|
-
|
27
|
+
raise Exception, READ_TIMEOUT_MESSAGE
|
28
28
|
rescue Net::OpenTimeout
|
29
|
-
|
29
|
+
raise Exception, OPEN_TIMEOUT_MESSAGE
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
data/lib/twurl/version.rb
CHANGED
@@ -2,7 +2,7 @@ module Twurl
|
|
2
2
|
class Version
|
3
3
|
MAJOR = 0 unless defined? Twurl::Version::MAJOR
|
4
4
|
MINOR = 9 unless defined? Twurl::Version::MINOR
|
5
|
-
PATCH =
|
5
|
+
PATCH = 7 unless defined? Twurl::Version::PATCH
|
6
6
|
PRE = nil unless defined? Twurl::Version::PRE # Time.now.to_i.to_s
|
7
7
|
|
8
8
|
class << self
|
data/twurl.gemspec
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'twurl/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.add_dependency 'oauth', '~> 0.4'
|
7
|
+
spec.add_dependency 'ostruct', '>= 0.3.3'
|
8
8
|
spec.authors = ["Marcel Molina", "Erik Michaels-Ober", "@TwitterDev team"]
|
9
9
|
spec.description = %q{Curl for the Twitter API}
|
10
10
|
spec.bindir = 'bin'
|
11
11
|
spec.executables << 'twurl'
|
12
12
|
spec.extra_rdoc_files = Dir["*.md", "LICENSE"]
|
13
13
|
spec.files = Dir["*.md", "LICENSE", "twurl.gemspec", "bin/*", "lib/**/*"]
|
14
|
-
spec.homepage = '
|
14
|
+
spec.homepage = 'https://github.com/twitter/twurl'
|
15
15
|
spec.licenses = ['MIT']
|
16
16
|
spec.name = 'twurl'
|
17
17
|
spec.rdoc_options = ['--title', 'twurl -- OAuth-enabled curl for the Twitter API', '--main', 'README.md', '--line-numbers', '--inline-source']
|
18
18
|
spec.require_paths = ['lib']
|
19
|
-
spec.required_ruby_version = '>= 2.
|
19
|
+
spec.required_ruby_version = '>= 2.5.0'
|
20
20
|
spec.summary = spec.description
|
21
21
|
spec.version = Twurl::Version
|
22
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twurl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcel Molina
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-04-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: oauth
|
@@ -26,6 +26,20 @@ dependencies:
|
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '0.4'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: ostruct
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 0.3.3
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.3.3
|
29
43
|
description: Curl for the Twitter API
|
30
44
|
email:
|
31
45
|
executables:
|
@@ -33,9 +47,9 @@ executables:
|
|
33
47
|
extensions: []
|
34
48
|
extra_rdoc_files:
|
35
49
|
- CODE_OF_CONDUCT.md
|
50
|
+
- CONTRIBUTING.md
|
36
51
|
- INSTALL.md
|
37
52
|
- README.md
|
38
|
-
- CONTRIBUTING.md
|
39
53
|
- LICENSE
|
40
54
|
files:
|
41
55
|
- CODE_OF_CONDUCT.md
|
@@ -58,7 +72,7 @@ files:
|
|
58
72
|
- lib/twurl/request_controller.rb
|
59
73
|
- lib/twurl/version.rb
|
60
74
|
- twurl.gemspec
|
61
|
-
homepage:
|
75
|
+
homepage: https://github.com/twitter/twurl
|
62
76
|
licenses:
|
63
77
|
- MIT
|
64
78
|
metadata: {}
|
@@ -76,14 +90,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
90
|
requirements:
|
77
91
|
- - ">="
|
78
92
|
- !ruby/object:Gem::Version
|
79
|
-
version: 2.
|
93
|
+
version: 2.5.0
|
80
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
95
|
requirements:
|
82
96
|
- - ">="
|
83
97
|
- !ruby/object:Gem::Version
|
84
98
|
version: '0'
|
85
99
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
100
|
+
rubygems_version: 3.3.26
|
87
101
|
signing_key:
|
88
102
|
specification_version: 4
|
89
103
|
summary: Curl for the Twitter API
|