httparty 0.24.2 → 0.24.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/README.md +1 -1
- data/examples/tripit_sign_in.rb +2 -2
- data/lib/httparty/parser.rb +36 -5
- data/lib/httparty/response.rb +15 -1
- data/lib/httparty/version.rb +1 -1
- data/lib/httparty.rb +4 -3
- metadata +3 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2389baaffd615950f7d364a762d1c7e046e6e1819070b6974137a79737ed5cef
|
|
4
|
+
data.tar.gz: 33be08cb6b537efbbe5f691eff3308c9a126f03998d8cda1827ee946edadaffd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 205b2eda67b38f7d4febba842ee9fd13450ffae372f92455ed925b9646ad68872e6a60c7efe7ab97635209737eba19f1efddf8fd6ea58732b8552986304890f9
|
|
7
|
+
data.tar.gz: 431bf5342636a7a88bf3d64116535e20d547f089f6cabea8f66700215d9aaafc6ad8903e8205105183d24bb55115d676b28e6026d9c1a0aa969a74d6e53ec471
|
data/.github/workflows/ci.yml
CHANGED
data/README.md
CHANGED
|
@@ -19,7 +19,7 @@ gem install httparty
|
|
|
19
19
|
|
|
20
20
|
```ruby
|
|
21
21
|
# Use the class methods to get down to business quickly
|
|
22
|
-
response = HTTParty.get('
|
|
22
|
+
response = HTTParty.get('https://api.stackexchange.com/2.2/questions?site=stackoverflow')
|
|
23
23
|
|
|
24
24
|
puts response.body, response.code, response.message, response.headers.inspect
|
|
25
25
|
|
data/examples/tripit_sign_in.rb
CHANGED
|
@@ -9,7 +9,7 @@ class TripIt
|
|
|
9
9
|
def initialize(email, password)
|
|
10
10
|
@email = email
|
|
11
11
|
get_response = self.class.get('/account/login')
|
|
12
|
-
get_response_cookie = parse_cookie(get_response
|
|
12
|
+
get_response_cookie = parse_cookie(get_response)
|
|
13
13
|
|
|
14
14
|
post_response = self.class.post(
|
|
15
15
|
'/account/login',
|
|
@@ -20,7 +20,7 @@ class TripIt
|
|
|
20
20
|
headers: {'Cookie' => get_response_cookie.to_cookie_string }
|
|
21
21
|
)
|
|
22
22
|
|
|
23
|
-
@cookie = parse_cookie(post_response
|
|
23
|
+
@cookie = parse_cookie(post_response)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def account_settings
|
data/lib/httparty/parser.rb
CHANGED
|
@@ -103,11 +103,12 @@ module HTTParty
|
|
|
103
103
|
# @return [nil] when the response body is nil, an empty string, spaces only or "null"
|
|
104
104
|
def parse
|
|
105
105
|
return nil if body.nil?
|
|
106
|
+
# The bom has to be removed before the blank body checks below, otherwise a
|
|
107
|
+
# body that is nothing but a bom is handed to the format parser as an
|
|
108
|
+
# empty string and blows up instead of being reported as nil.
|
|
109
|
+
@body = strip_utf8_bom(body)
|
|
106
110
|
return nil if body == 'null'
|
|
107
111
|
return nil if body.valid_encoding? && body.strip.empty?
|
|
108
|
-
if body.valid_encoding? && body.encoding == Encoding::UTF_8
|
|
109
|
-
@body = body.gsub(/\A#{UTF8_BOM}/, '')
|
|
110
|
-
end
|
|
111
112
|
if supports_format?
|
|
112
113
|
parse_supported_format
|
|
113
114
|
else
|
|
@@ -119,14 +120,44 @@ module HTTParty
|
|
|
119
120
|
|
|
120
121
|
def xml
|
|
121
122
|
require 'multi_xml'
|
|
122
|
-
MultiXml.parse(body)
|
|
123
|
+
(defined?(MultiXML) ? MultiXML : MultiXml).parse(body)
|
|
123
124
|
end
|
|
124
125
|
|
|
125
126
|
UTF8_BOM = "\xEF\xBB\xBF"
|
|
127
|
+
UTF8_BOM_ENCODINGS = [Encoding::UTF_8, Encoding::US_ASCII, Encoding::BINARY].freeze
|
|
128
|
+
|
|
129
|
+
# Compares bytes rather than characters because Net::HTTP hands bodies
|
|
130
|
+
# over as ASCII-8BIT when the response has no charset, and a UTF-8 regex
|
|
131
|
+
# would never match those. ASCII-8BIT bodies in a format we don't parse
|
|
132
|
+
# are left alone, since they may be genuine binary data (images, files).
|
|
133
|
+
def strip_utf8_bom(string)
|
|
134
|
+
return string unless UTF8_BOM_ENCODINGS.include?(string.encoding)
|
|
135
|
+
return string if string.encoding == Encoding::BINARY && !supports_format?
|
|
136
|
+
return string.byteslice(UTF8_BOM.bytesize..-1) if utf8_bom?(string)
|
|
137
|
+
|
|
138
|
+
# Valid UTF-8 bodies have always been handed back as a copy, so mutating
|
|
139
|
+
# parsed_response doesn't also change response.body. Other encodings
|
|
140
|
+
# (ASCII-8BIT, US-ASCII, ISO-8859-1, invalid UTF-8) have always been
|
|
141
|
+
# handed back as the same object, and still are.
|
|
142
|
+
if string.encoding == Encoding::UTF_8 && string.valid_encoding?
|
|
143
|
+
string.dup
|
|
144
|
+
else
|
|
145
|
+
string
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Checks bytes one at a time so the common no-BOM case allocates nothing.
|
|
150
|
+
def utf8_bom?(string)
|
|
151
|
+
string.getbyte(0) == 0xEF && string.getbyte(1) == 0xBB && string.getbyte(2) == 0xBF
|
|
152
|
+
end
|
|
126
153
|
|
|
127
154
|
def json
|
|
128
155
|
require 'json'
|
|
129
|
-
JSON.
|
|
156
|
+
if JSON::VERSION.to_i >= 3
|
|
157
|
+
JSON.parse(body, :allow_nan => true)
|
|
158
|
+
else
|
|
159
|
+
JSON.parse(body, :quirks_mode => true, :allow_nan => true)
|
|
160
|
+
end
|
|
130
161
|
end
|
|
131
162
|
|
|
132
163
|
def csv
|
data/lib/httparty/response.rb
CHANGED
|
@@ -133,13 +133,27 @@ module HTTParty
|
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
def throw_exception
|
|
136
|
-
|
|
136
|
+
raise_on = @request.options[:raise_on]
|
|
137
|
+
return if raise_on.nil?
|
|
138
|
+
|
|
139
|
+
matchers = raise_on.is_a?(Range) ? [raise_on] : [*raise_on]
|
|
140
|
+
|
|
141
|
+
if matchers.any? { |matcher| code_matches?(matcher) }
|
|
137
142
|
::Kernel.raise ::HTTParty::ResponseError.new(@response), "Code #{code} - #{body}"
|
|
138
143
|
end
|
|
139
144
|
end
|
|
140
145
|
|
|
141
146
|
private
|
|
142
147
|
|
|
148
|
+
def code_matches?(matcher)
|
|
149
|
+
case matcher
|
|
150
|
+
when Range
|
|
151
|
+
matcher.cover?(code) || matcher.cover?(code.to_s)
|
|
152
|
+
else
|
|
153
|
+
/#{matcher}/.match?(code.to_s)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
143
157
|
def warn_about_nil_deprecation
|
|
144
158
|
trace_line = caller.reject { |line| line.include?('httparty') }.first
|
|
145
159
|
warning = "[DEPRECATION] HTTParty will no longer override `response#nil?`. " \
|
data/lib/httparty/version.rb
CHANGED
data/lib/httparty.rb
CHANGED
|
@@ -84,14 +84,15 @@ module HTTParty
|
|
|
84
84
|
default_options[:log_format] = format
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
-
# Raises HTTParty::ResponseError if response
|
|
87
|
+
# Raises HTTParty::ResponseError if the response status matches a code,
|
|
88
|
+
# range, or regular expression string.
|
|
88
89
|
#
|
|
89
90
|
# class Foo
|
|
90
91
|
# include HTTParty
|
|
91
|
-
# raise_on [404, 500, '
|
|
92
|
+
# raise_on [404, 500..599, '3[0-9]*']
|
|
92
93
|
# end
|
|
93
94
|
def raise_on(codes = [])
|
|
94
|
-
default_options[:raise_on] = *codes
|
|
95
|
+
default_options[:raise_on] = codes.is_a?(Range) ? [codes] : [*codes]
|
|
95
96
|
end
|
|
96
97
|
|
|
97
98
|
# Allows setting http proxy information to be used
|
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: httparty
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.24.
|
|
4
|
+
version: 0.24.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Nunemaker
|
|
8
8
|
- Sandro Turriate
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: csv
|
|
@@ -148,8 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
148
147
|
- !ruby/object:Gem::Version
|
|
149
148
|
version: '0'
|
|
150
149
|
requirements: []
|
|
151
|
-
rubygems_version:
|
|
152
|
-
signing_key:
|
|
150
|
+
rubygems_version: 4.0.18
|
|
153
151
|
specification_version: 4
|
|
154
152
|
summary: Makes http fun! Also, makes consuming restful web services dead easy.
|
|
155
153
|
test_files: []
|