diff --git a/.travis.yml b/.travis.yml index dfd89ff..977e3cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,23 @@ -bundler_args: --without development +dist: xenial language: ruby -rvm: - - 1.9.3 - - 2.0.0 - - jruby-head - - rbx-2 - - ruby-head + +before_install: + - bundle config without 'development' + +branches: + only: + - master + matrix: + fast_finish: true allow_failures: - rvm: jruby-head - rvm: ruby-head - fast_finish: true -sudo: false + - rvm: rbx-2 + include: + - rvm: 2.6.5 + - rvm: 2.5.7 + - rvm: 2.4.9 + - rvm: jruby-head + - rvm: ruby-head + - rvm: rbx-2 diff --git a/lib/twurl/cli.rb b/lib/twurl/cli.rb index c68210c..fa9327b 100644 --- a/lib/twurl/cli.rb +++ b/lib/twurl/cli.rb @@ -44,6 +44,7 @@ def parse_options(args) arguments = args.dup Twurl.options = Options.new + Twurl.options.args = arguments Twurl.options.trace = false Twurl.options.data = {} Twurl.options.headers = {} @@ -159,11 +160,9 @@ def extract_path!(arguments) end def escape_params(params) - split_params = params.split("&").map do |param| - key, value = param.split('=', 2) - CGI::escape(key) + '=' + CGI::escape(value) - end - split_params.join("&") + CGI::parse(params).map do |key, value| + "#{CGI.escape key}=#{CGI.escape value.first}" + end.join("&") end end @@ -230,9 +229,13 @@ def trace def data on('-d', '--data [data]', 'Sends the specified data in a POST request to the HTTP server.') do |data| - data.split('&').each do |pair| - key, value = pair.split('=', 2) - options.data[key] = value + if options.args.count { |item| /content-type: (.*)/i.match(item) } > 0 + options.data[data] = nil + else + data.split('&').each do |pair| + key, value = pair.split('=', 2) + options.data[key] = value + end end end end diff --git a/lib/twurl/oauth_client.rb b/lib/twurl/oauth_client.rb index a602ee9..4941f3b 100644 --- a/lib/twurl/oauth_client.rb +++ b/lib/twurl/oauth_client.rb @@ -113,7 +113,14 @@ def perform_request_from_options(options, &block) elsif request.content_type && options.data request.body = options.data.keys.first elsif options.data - request.set_form_data(options.data) + request.content_type = "application/x-www-form-urlencoded" + if options.data.length == 1 && options.data.values.first == nil + request.body = options.data.keys.first + else + request.body = options.data.map do |key, value| + "#{key}=#{CGI.escape value}" + end.join("&") + end end request.oauth!(consumer.http, consumer, access_token) diff --git a/twurl.gemspec b/twurl.gemspec index 77b7de8..8bea400 100644 --- a/twurl.gemspec +++ b/twurl.gemspec @@ -5,7 +5,6 @@ require 'twurl/version' Gem::Specification.new do |spec| spec.add_dependency 'oauth', '~> 0.4' - spec.add_development_dependency 'bundler', '~> 1.0' spec.authors = ["Marcel Molina", "Erik Michaels-Ober"] spec.description = %q{Curl for the Twitter API} spec.email = ['marcel@twitter.com'] @@ -17,7 +16,7 @@ Gem::Specification.new do |spec| spec.name = 'twurl' spec.rdoc_options = ['--title', 'twurl -- OAuth-enabled curl for the Twitter API', '--main', 'README', '--line-numbers', '--inline-source'] spec.require_paths = ['lib'] - spec.required_ruby_version = '>= 1.9.3' + spec.required_ruby_version = '>= 2.4.0' spec.rubyforge_project = 'twurl' spec.summary = spec.description spec.version = Twurl::Version