mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
Fix a large number of style nits.
Working slowly through the rubocop list.
This commit is contained in:
parent
85ad601e33
commit
543dbc3816
12 changed files with 41 additions and 38 deletions
3
Rakefile
3
Rakefile
|
@ -81,7 +81,7 @@ namespace :windows do
|
|||
if ok
|
||||
FileUtils.mkdir_p(pkg_dir)
|
||||
FileUtils.mv(File.join(base, gem_filename), pkg_dir)
|
||||
Bundler.ui.confirm("rest-client #{RestClient::VERSION} " +
|
||||
Bundler.ui.confirm("rest-client #{RestClient::VERSION} " \
|
||||
"built to pkg/#{gem_filename}")
|
||||
else
|
||||
abort "Command `gem build` failed: #{res}"
|
||||
|
@ -114,4 +114,3 @@ Rake::RDocTask.new do |t|
|
|||
t.rdoc_files.include('README.rdoc')
|
||||
t.rdoc_files.include('lib/*.rb')
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$:.unshift File.dirname(__FILE__) + "/../lib"
|
||||
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
|
||||
|
||||
require 'rubygems'
|
||||
require 'restclient'
|
||||
|
@ -58,7 +58,7 @@ end
|
|||
POSSIBLE_VERBS.each do |m|
|
||||
eval <<-end_eval
|
||||
def #{m}(path, *args, &b)
|
||||
r[path].#{m}(*args, &b)
|
||||
r[path].#{m}(*args, &b)
|
||||
end
|
||||
end_eval
|
||||
end
|
||||
|
|
|
@ -82,7 +82,7 @@ module RestClient
|
|||
Request.execute args, &block
|
||||
end
|
||||
|
||||
def AbstractResponse.beautify_headers(headers)
|
||||
def self.beautify_headers(headers)
|
||||
headers.inject({}) do |out, (key, value)|
|
||||
out[key.gsub(/-/, '_').downcase.to_sym] = %w{ set-cookie }.include?(key.downcase) ? value : value.first
|
||||
out
|
||||
|
|
|
@ -86,7 +86,7 @@ module RestClient
|
|||
# probably an HTML error page) is e.response.
|
||||
class Exception < RuntimeError
|
||||
attr_accessor :response
|
||||
attr_writer :message
|
||||
attr_writer :message
|
||||
|
||||
def initialize response = nil, initial_response_code = nil
|
||||
@response = response
|
||||
|
|
|
@ -155,9 +155,10 @@ module RestClient
|
|||
end
|
||||
|
||||
private
|
||||
def parser
|
||||
URI.const_defined?(:Parser) ? URI::Parser.new : URI
|
||||
end
|
||||
|
||||
def parser
|
||||
URI.const_defined?(:Parser) ? URI::Parser.new : URI
|
||||
end
|
||||
end
|
||||
|
||||
class Multipart < Base
|
||||
|
|
|
@ -408,7 +408,7 @@ module RestClient
|
|||
net.start do |http|
|
||||
if @block_response
|
||||
net_http_do_request(http, req, payload ? payload.to_s : nil,
|
||||
& @block_response)
|
||||
&@block_response)
|
||||
else
|
||||
res = net_http_do_request(http, req, payload ? payload.to_s : nil) \
|
||||
{ |http_response| fetch_body(http_response) }
|
||||
|
@ -511,20 +511,25 @@ module RestClient
|
|||
end
|
||||
|
||||
def log_request
|
||||
if RestClient.log
|
||||
out = []
|
||||
out << "RestClient.#{method} #{url.inspect}"
|
||||
out << payload.short_inspect if payload
|
||||
out << processed_headers.to_a.sort.map { |(k, v)| [k.inspect, v.inspect].join("=>") }.join(", ")
|
||||
RestClient.log << out.join(', ') + "\n"
|
||||
end
|
||||
return unless RestClient.log
|
||||
|
||||
out = []
|
||||
out << "RestClient.#{method} #{url.inspect}"
|
||||
out << payload.short_inspect if payload
|
||||
out << processed_headers.to_a.sort.map { |(k, v)| [k.inspect, v.inspect].join("=>") }.join(", ")
|
||||
RestClient.log << out.join(', ') + "\n"
|
||||
end
|
||||
|
||||
def log_response res
|
||||
if RestClient.log
|
||||
size = @raw_response ? File.size(@tf.path) : (res.body.nil? ? 0 : res.body.size)
|
||||
RestClient.log << "# => #{res.code} #{res.class.to_s.gsub(/^Net::HTTP/, '')} | #{(res['Content-type'] || '').gsub(/;.*$/, '')} #{size} bytes\n"
|
||||
end
|
||||
return unless RestClient.log
|
||||
|
||||
size = if @raw_response
|
||||
File.size(@tf.path)
|
||||
else
|
||||
res.body.nil? ? 0 : res.body.size
|
||||
end
|
||||
|
||||
RestClient.log << "# => #{res.code} #{res.class.to_s.gsub(/^Net::HTTP/, '')} | #{(res['Content-type'] || '').gsub(/;.*$/, '')} #{size} bytes\n"
|
||||
end
|
||||
|
||||
# Return a hash of headers whose keys are capitalized strings
|
||||
|
|
|
@ -149,10 +149,9 @@ module RestClient
|
|||
#
|
||||
def [](suburl, &new_block)
|
||||
case
|
||||
when block_given? then self.class.new(concat_urls(url, suburl), options, &new_block)
|
||||
when block then self.class.new(concat_urls(url, suburl), options, &block)
|
||||
else
|
||||
self.class.new(concat_urls(url, suburl), options)
|
||||
when block_given? then self.class.new(concat_urls(url, suburl), options, &new_block)
|
||||
when block then self.class.new(concat_urls(url, suburl), options, &block)
|
||||
else self.class.new(concat_urls(url, suburl), options)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ module RestClient
|
|||
self
|
||||
end
|
||||
|
||||
def Response.create body, net_http_res, args
|
||||
def self.create body, net_http_res, args
|
||||
result = body || ''
|
||||
result.extend Response
|
||||
result.net_http_res = net_http_res
|
||||
|
|
|
@ -27,4 +27,3 @@ Gem::Specification.new do |s|
|
|||
|
||||
s.required_ruby_version = '>= 1.9.2'
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ describe RestClient::Request do
|
|||
|
||||
it "can use a block to process response" do
|
||||
response_value = nil
|
||||
block = Proc.new do |http_response|
|
||||
block = proc do |http_response|
|
||||
response_value = http_response.body
|
||||
end
|
||||
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
||||
|
|
|
@ -80,14 +80,14 @@ describe RestClient::Resource do
|
|||
end
|
||||
|
||||
it "passes a given block to subresources" do
|
||||
block = Proc.new{|r| r}
|
||||
block = proc {|r| r}
|
||||
parent = RestClient::Resource.new('http://example.com', &block)
|
||||
parent['posts'].block.should eq block
|
||||
end
|
||||
|
||||
it "the block should be overrideable" do
|
||||
block1 = Proc.new {|r| r}
|
||||
block2 = Proc.new {|r| }
|
||||
block1 = proc {|r| r}
|
||||
block2 = proc {|r| }
|
||||
parent = RestClient::Resource.new('http://example.com', &block1)
|
||||
# parent['posts', &block2].block.should eq block2 # ruby 1.9 syntax
|
||||
parent.send(:[], 'posts', &block2).block.should eq block2
|
||||
|
@ -95,7 +95,7 @@ describe RestClient::Resource do
|
|||
end
|
||||
|
||||
it "the block should be overrideable in ruby 1.9 syntax" do
|
||||
block1 = Proc.new {|r| r}
|
||||
block1 = proc {|r| r}
|
||||
block2 = ->(r) {}
|
||||
|
||||
parent = RestClient::Resource.new('http://example.com', &block1)
|
||||
|
|
|
@ -35,9 +35,9 @@ describe RestClient::Response do
|
|||
response = RestClient::Response.create('abc', net_http_res, {})
|
||||
response.headers[:set_cookie].should eq ["main_page=main_page_no_rewrite; path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT", "remember_me=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT", "user=somebody; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"]
|
||||
response.cookies.should eq({
|
||||
"main_page" => "main_page_no_rewrite",
|
||||
"remember_me" => "",
|
||||
"user" => "somebody"
|
||||
"main_page" => "main_page_no_rewrite",
|
||||
"remember_me" => "",
|
||||
"user" => "somebody"
|
||||
})
|
||||
end
|
||||
|
||||
|
@ -45,9 +45,9 @@ describe RestClient::Response do
|
|||
net_http_res = double('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => ["main_page=main_page_no_rewrite; path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT, remember_me=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT, user=somebody; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"]})
|
||||
response = RestClient::Response.create('abc', net_http_res, {})
|
||||
response.cookies.should eq({
|
||||
"main_page" => "main_page_no_rewrite",
|
||||
"remember_me" => "",
|
||||
"user" => "somebody"
|
||||
"main_page" => "main_page_no_rewrite",
|
||||
"remember_me" => "",
|
||||
"user" => "somebody"
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue