Adds editorconfig

This commit is contained in:
Harman Singh 2018-10-08 17:14:44 +05:30
parent 9ff17bc6ad
commit 57a6bd6e1d
14 changed files with 87 additions and 48 deletions

18
.editorconfig Normal file
View File

@ -0,0 +1,18 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://EditorConfig.org
root = true
[*]
end_of_line = lf
trim_trailing_whitespace = true
[**.rb]
indent_size = 2
indent_style = spaces
insert_final_newline = true
[**.xml]
trim_trailing_whitespace = false
[**.html]
trim_trailing_whitespace = false

View File

@ -13,22 +13,22 @@
* Creates a custom parser for XML using crack gem * Creates a custom parser for XML using crack gem
* Uses `get` request * Uses `get` request
* [Create HTML Nokogiri parser](nokogiri_html_parser.rb) * [Create HTML Nokogiri parser](nokogiri_html_parser.rb)
* Adds Html as a format * Adds Html as a format
* passed the body of request to Nokogiri * passed the body of request to Nokogiri
* [More Custom Parsers](custom_parsers.rb) * [More Custom Parsers](custom_parsers.rb)
* Create an additional parser for atom or make it the ONLY parser * Create an additional parser for atom or make it the ONLY parser
* [Basic Auth, Delicious](delicious.rb) * [Basic Auth, Delicious](delicious.rb)
* Basic Auth, shows how to merge those into options * Basic Auth, shows how to merge those into options
* Uses `get` requests * Uses `get` requests
* [Passing Headers, User Agent](headers_and_user_agents.rb) * [Passing Headers, User Agent](headers_and_user_agents.rb)
* Use the class method of Httparty * Use the class method of Httparty
* Pass the User-Agent in the headers * Pass the User-Agent in the headers
* Uses `get` requests * Uses `get` requests
* [Basic Post Request](basic.rb) * [Basic Post Request](basic.rb)
* Httparty included into poro class * Httparty included into poro class
* Uses `post` requests * Uses `post` requests
@ -36,7 +36,7 @@
* [Access Rubyurl Shortener](rubyurl.rb) * [Access Rubyurl Shortener](rubyurl.rb)
* Httparty included into poro class * Httparty included into poro class
* Uses `post` requests * Uses `post` requests
* [Add a custom log file](logging.rb) * [Add a custom log file](logging.rb)
* create a log file and have httparty log requests * create a log file and have httparty log requests
@ -44,23 +44,23 @@
* Httparty included into poro class * Httparty included into poro class
* Creates methods for different endpoints * Creates methods for different endpoints
* Uses `get` requests * Uses `get` requests
* [Accessing Tripit](tripit_sign_in.rb) * [Accessing Tripit](tripit_sign_in.rb)
* Httparty included into poro class * Httparty included into poro class
* Example of using `debug_output` to see headers/urls passed * Example of using `debug_output` to see headers/urls passed
* Getting and using Cookies * Getting and using Cookies
* Uses `get` requests * Uses `get` requests
* [Accessing Twitter](twitter.rb) * [Accessing Twitter](twitter.rb)
* Httparty included into poro class * Httparty included into poro class
* Basic Auth * Basic Auth
* Loads settings from a config file * Loads settings from a config file
* Uses `get` requests * Uses `get` requests
* Uses `post` requests * Uses `post` requests
* [Accessing WhoIsMyRep](whoismyrep.rb) * [Accessing WhoIsMyRep](whoismyrep.rb)
* Httparty included into poro class * Httparty included into poro class
* Uses `get` requests * Uses `get` requests
* Two ways to pass params to get, inline on the url or in query hash * Two ways to pass params to get, inline on the url or in query hash
* [Rescue Json Error](rescue_json.rb) * [Rescue Json Error](rescue_json.rb)

View File

@ -95,7 +95,7 @@ module DigestAuthenticationUsingMD5Sess
def self.extended(base) def self.extended(base)
base.custom_headers["WWW-Authenticate"] = %(Digest realm="#{REALM}",qop="#{QOP}",algorithm="MD5-sess",nonce="#{NONCE}",opaque="opaque"') base.custom_headers["WWW-Authenticate"] = %(Digest realm="#{REALM}",qop="#{QOP}",algorithm="MD5-sess",nonce="#{NONCE}",opaque="opaque"')
end end
def process(request, response) def process(request, response)
if authorized?(request) if authorized?(request)
super super
@ -103,11 +103,11 @@ module DigestAuthenticationUsingMD5Sess
reply_with(response, 401, "Incorrect. You have 20 seconds to comply.") reply_with(response, 401, "Incorrect. You have 20 seconds to comply.")
end end
end end
def md5(str) def md5(str)
Digest::MD5.hexdigest(str) Digest::MD5.hexdigest(str)
end end
def authorized?(request) def authorized?(request)
auth = request.params["HTTP_AUTHORIZATION"] auth = request.params["HTTP_AUTHORIZATION"]
params = {} params = {}

View File

@ -593,7 +593,8 @@ module HTTParty
def validate_format def validate_format
if format && parser.respond_to?(:supports_format?) && !parser.supports_format?(format) if format && parser.respond_to?(:supports_format?) && !parser.supports_format?(format)
raise UnsupportedFormat, "'#{format.inspect}' Must be one of: #{parser.supported_formats.map(&:to_s).sort.join(', ')}" supported_format_names = parser.supported_formats.map(&:to_s).sort.join(', ')
raise UnsupportedFormat, "'#{format.inspect}' Must be one of: #{supported_format_names}"
end end
end end
end end

View File

@ -38,12 +38,12 @@ module HTTParty
# in the #options attribute. It is up to you to interpret them within your # in the #options attribute. It is up to you to interpret them within your
# connection adapter. Take a look at the implementation of # connection adapter. Take a look at the implementation of
# HTTParty::ConnectionAdapter#connection for examples of how they are used. # HTTParty::ConnectionAdapter#connection for examples of how they are used.
# The keys used in options are # The keys used in options are
# * :+timeout+: timeout in seconds # * :+timeout+: timeout in seconds
# * :+open_timeout+: http connection open_timeout in seconds, overrides timeout if set # * :+open_timeout+: http connection open_timeout in seconds, overrides timeout if set
# * :+read_timeout+: http connection read_timeout in seconds, overrides timeout if set # * :+read_timeout+: http connection read_timeout in seconds, overrides timeout if set
# * :+debug_output+: see HTTParty::ClassMethods.debug_output. # * :+debug_output+: see HTTParty::ClassMethods.debug_output.
# * :+cert_store+: contains certificate data. see method 'attach_ssl_certificates' # * :+cert_store+: contains certificate data. see method 'attach_ssl_certificates'
# * :+pem+: contains pem client certificate data. see method 'attach_ssl_certificates' # * :+pem+: contains pem client certificate data. see method 'attach_ssl_certificates'
# * :+p12+: contains PKCS12 client client certificate data. see method 'attach_ssl_certificates' # * :+p12+: contains PKCS12 client client certificate data. see method 'attach_ssl_certificates'
# * :+verify+: verify the servers certificate against the ca certificate. # * :+verify+: verify the servers certificate against the ca certificate.
@ -91,7 +91,14 @@ module HTTParty
host = clean_host(uri.host) host = clean_host(uri.host)
port = uri.port || (uri.scheme == 'https' ? 443 : 80) port = uri.port || (uri.scheme == 'https' ? 443 : 80)
if options.key?(:http_proxyaddr) if options.key?(:http_proxyaddr)
http = Net::HTTP.new(host, port, options[:http_proxyaddr], options[:http_proxyport], options[:http_proxyuser], options[:http_proxypass]) http = Net::HTTP.new(
host,
port,
options[:http_proxyaddr],
options[:http_proxyport],
options[:http_proxyuser],
options[:http_proxypass]
)
else else
http = Net::HTTP.new(host, port) http = Net::HTTP.new(host, port)
end end

View File

@ -39,7 +39,9 @@ module HTTParty
if value.empty? if value.empty?
normalized_keys << ["#{key}[]", ''] normalized_keys << ["#{key}[]", '']
else else
normalized_keys = value.to_ary.flat_map { |element| normalize_keys("#{key}[]", element) } normalized_keys = value.to_ary.flat_map do |element|
normalize_keys("#{key}[]", element)
end
end end
elsif value.respond_to?(:to_hash) elsif value.respond_to?(:to_hash)
stack << [key, value.to_hash] stack << [key, value.to_hash]
@ -52,7 +54,9 @@ module HTTParty
if child_value.respond_to?(:to_hash) if child_value.respond_to?(:to_hash)
stack << ["#{parent}[#{child_key}]", child_value.to_hash] stack << ["#{parent}[#{child_key}]", child_value.to_hash]
elsif child_value.respond_to?(:to_ary) elsif child_value.respond_to?(:to_ary)
child_value.to_ary.each { |v| normalized_keys << normalize_keys("#{parent}[#{child_key}][]", v).flatten } child_value.to_ary.each do |v|
normalized_keys << normalize_keys("#{parent}[#{child_key}][]", v).flatten
end
else else
normalized_keys << normalize_keys("#{parent}[#{child_key}]", child_value).flatten normalized_keys << normalize_keys("#{parent}[#{child_key}]", child_value).flatten
end end

View File

@ -9,12 +9,12 @@ module HTTParty
duplicate = hash.dup duplicate = hash.dup
duplicate.each_pair do |key, value| duplicate.each_pair do |key, value|
duplicate[key] = if value.is_a?(Hash) if value.is_a?(Hash)
hash_deep_dup(value) duplicate[key] = hash_deep_dup(value)
elsif value.is_a?(Proc) elsif value.is_a?(Proc)
duplicate[key] = value.dup duplicate[key] = value.dup
else else
value duplicate[key] = value
end end
end end

View File

@ -14,11 +14,11 @@ module Net
authenticator.authorization_header.each do |v| authenticator.authorization_header.each do |v|
add_field('Authorization', v) add_field('Authorization', v)
end end
authenticator.cookie_header.each do |v| authenticator.cookie_header.each do |v|
add_field('Cookie', v) add_field('Cookie', v)
end end
end end
class DigestAuthenticator class DigestAuthenticator
@ -64,7 +64,8 @@ module Net
def parse(response_header) def parse(response_header)
header = response_header['www-authenticate'] header = response_header['www-authenticate']
.gsub(/qop=(auth(?:-int)?)/, 'qop="\\1"')
header = header.gsub(/qop=(auth(?:-int)?)/, 'qop="\\1"')
header =~ /Digest (.*)/ header =~ /Digest (.*)/
params = {} params = {}
@ -113,11 +114,11 @@ module Net
def algorithm_present? def algorithm_present?
@response.key?('algorithm') && !@response['algorithm'].empty? @response.key?('algorithm') && !@response['algorithm'].empty?
end end
def use_md5_sess? def use_md5_sess?
algorithm_present? && @response['algorithm'] == 'MD5-sess' algorithm_present? && @response['algorithm'] == 'MD5-sess'
end end
def a1 def a1
a1_user_realm_pwd = [@username, @response['realm'], @password].join(':') a1_user_realm_pwd = [@username, @response['realm'], @password].join(':')
if use_md5_sess? if use_md5_sess?

View File

@ -14,7 +14,11 @@ module HTTParty
@headers = Headers.new(response.to_hash) @headers = Headers.new(response.to_hash)
if request.options[:logger] if request.options[:logger]
logger = ::HTTParty::Logger.build(request.options[:logger], request.options[:log_level], request.options[:log_format]) logger = ::HTTParty::Logger.build(
request.options[:logger],
request.options[:log_level],
request.options[:log_format]
)
logger.format(request, self) logger.format(request, self)
end end
@ -59,10 +63,10 @@ module HTTParty
response.nil? || response.body.nil? || response.body.empty? response.nil? || response.body.nil? || response.body.empty?
end end
def to_s def to_s
if !response.nil? && !response.body.nil? && response.body.respond_to?(:to_s) if !response.nil? && !response.body.nil? && response.body.respond_to?(:to_s)
response.body.to_s response.body.to_s
else else
inspect inspect
end end
end end
@ -80,7 +84,7 @@ module HTTParty
parsed_response.display(port) parsed_response.display(port)
elsif !response.nil? && !response.body.nil? && response.body.respond_to?(:display) elsif !response.nil? && !response.body.nil? && response.body.respond_to?(:display)
response.body.display(port) response.body.display(port)
else else
port.write(inspect) port.write(inspect)
end end
end end
@ -89,7 +93,7 @@ module HTTParty
return true if super return true if super
parsed_response.respond_to?(name) || response.respond_to?(name) parsed_response.respond_to?(name) || response.respond_to?(name)
end end
protected protected
def method_missing(name, *args, &block) def method_missing(name, *args, &block)

View File

@ -22,10 +22,10 @@ module HTTParty
end end
def ==(other) def ==(other)
if other.is_a?(::Net::HTTPHeader) if other.is_a?(::Net::HTTPHeader)
@header == other.instance_variable_get(:@header) @header == other.instance_variable_get(:@header)
elsif other.is_a?(Hash) elsif other.is_a?(Hash)
@header == other || @header == Headers.new(other).instance_variable_get(:@header) @header == other || @header == Headers.new(other).instance_variable_get(:@header)
end end
end end
end end

View File

@ -312,8 +312,12 @@ RSpec.describe HTTParty::ConnectionAdapter do
context 'as well as proxy user and password' do context 'as well as proxy user and password' do
let(:options) do let(:options) do
{http_proxyaddr: '1.2.3.4', http_proxyport: 8080, {
http_proxyuser: 'user', http_proxypass: 'pass'} http_proxyaddr: '1.2.3.4',
http_proxyport: 8080,
http_proxyuser: 'user',
http_proxypass: 'pass'
}
end end
describe '#proxy_user' do describe '#proxy_user' do

View File

@ -185,8 +185,8 @@ RSpec.describe Net::HTTPHeader::DigestAuthenticator do
context "with http basic auth response when net digest auth expected" do context "with http basic auth response when net digest auth expected" do
it "should not fail" do it "should not fail" do
@digest = setup_digest({ @digest = setup_digest({
'www-authenticate' => 'WWW-Authenticate: Basic realm="testrealm.com""' 'www-authenticate' => 'WWW-Authenticate: Basic realm="testrealm.com""'
}) })
expect(authorization_header).to include("Digest") expect(authorization_header).to include("Digest")
end end
@ -232,8 +232,8 @@ RSpec.describe Net::HTTPHeader::DigestAuthenticator do
context "with algorithm specified" do context "with algorithm specified" do
before do before do
@digest = setup_digest({ @digest = setup_digest({
'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth", algorithm=MD5' 'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth", algorithm=MD5'
}) })
end end
it "should recognise algorithm was specified" do it "should recognise algorithm was specified" do
@ -248,8 +248,8 @@ RSpec.describe Net::HTTPHeader::DigestAuthenticator do
context "with md5-sess algorithm specified" do context "with md5-sess algorithm specified" do
before do before do
@digest = setup_digest({ @digest = setup_digest({
'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth", algorithm=MD5-sess' 'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth", algorithm=MD5-sess'
}) })
end end
it "should recognise algorithm was specified" do it "should recognise algorithm was specified" do

View File

@ -299,10 +299,10 @@ RSpec.describe HTTParty::Response do
'Content-Encoding' => 'meow'} 'Content-Encoding' => 'meow'}
end end
let (:some_headers) do let (:some_headers) do
HTTParty::Response::Headers.new.tap do |h| HTTParty::Response::Headers.new.tap do |h|
some_headers_hash.each_pair do |k,v| some_headers_hash.each_pair do |k,v|
h[k] = v h[k] = v
end end
end end
end end
it "can initialize without headers" do it "can initialize without headers" do

View File

@ -8,7 +8,7 @@
body {font:13px arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}table {font-size:inherit;font:100%;}select, input, textarea {font:99% arial,helvetica,clean,sans-serif;}pre, code {font:115% monospace;*font-size:100%;}body * {line-height:1.22em;} body {font:13px arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}table {font-size:inherit;font:100%;}select, input, textarea {font:99% arial,helvetica,clean,sans-serif;}pre, code {font:115% monospace;*font-size:100%;}body * {line-height:1.22em;}
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}/*ol,ul {list-style:none;}*/caption,th {text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym {border:0;} body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}/*ol,ul {list-style:none;}*/caption,th {text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym {border:0;}
/* end of yahoo reset and fonts */ /* end of yahoo reset and fonts */
body {color:#333; background:#4b1a1a; line-height:1.3;} body {color:#333; background:#4b1a1a; line-height:1.3;}
p {margin:0 0 20px;} p {margin:0 0 20px;}
a {color:#4b1a1a;} a {color:#4b1a1a;}