nethttputils 0.4.3.2 → 0.4.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8a3bdaaec8992d13db534ec38ce63c28f303bc52
4
- data.tar.gz: 70adf066cd7c2d63247da3955057b9872a3d1a4f
2
+ SHA256:
3
+ metadata.gz: bf38b9ab048dec93ae1ed7cdc00746477bdfffe66394e3dca8c97dee19b85d2d
4
+ data.tar.gz: 44f1439d888cf72395de49ae8b2192193cb31f0648d57abb00be1a4d5cdcdb32
5
5
  SHA512:
6
- metadata.gz: adbfb02313e49c395e8f44b25d2f5f7cbfaa749220d61d855e1e29f5b3c656797347a802acbda55b40afcceb05ffa65b77ae90339f59ac12f55a9a2b88737f23
7
- data.tar.gz: 37f2b5b2ea2db8620558444a21eaeeac9b15d4dcaba06d3007e7b112db84d91869a0238560c3c834f725386b64a17a377e2e4bbe081002ae7b5861b3ef93ec24
6
+ metadata.gz: 8e445cb04ac14bb07b658d2211e048a1d51c1002ce4e0c50303a73e82474b4e6b74ce1d9d17b30de35a43f0cc0db1e12eeedd4a80cbc924a6974224f9d1dc282
7
+ data.tar.gz: 8c11645091d88847e45e4849d5782c9b562c98a5ef7613b502a5953263db5608e5f8eabadd5850089d85e06ce679912bc58716caec922e5c3cfb0e16a15bc56c
data/lib/nethttputils.rb CHANGED
@@ -28,6 +28,7 @@ module NetHTTPUtils
28
28
  end
29
29
 
30
30
  class << self
31
+ require "addressable"
31
32
 
32
33
  def remove_tags str
33
34
  str.gsub(/<script( [a-z-]+="[^"]*")*>.*?<\/script>/m, "").
@@ -38,12 +39,14 @@ module NetHTTPUtils
38
39
  def start_http url, max_start_http_retry_delay = 3600, timeout = nil, no_redirect = false, proxy = nil
39
40
  timeout ||= 30
40
41
  uri = url
41
- uri = URI.parse begin
42
+
43
+ uri = begin
42
44
  URI url
43
- url
44
45
  rescue URI::InvalidURIError
45
- CGI.escape url
46
+ URI Addressable::URI.escape url
46
47
  end unless url.is_a? URI::HTTP
48
+ raise Error, "can't parse host" unless uri.host
49
+
47
50
  delay = 5
48
51
  begin
49
52
  Net::HTTP.start(
@@ -131,11 +134,12 @@ module NetHTTPUtils
131
134
  # request.basic_auth *p(auth.map(&URI.method(:escape))) if auth
132
135
  request.basic_auth *auth if auth
133
136
  if (mtd == :POST || mtd == :PATCH) && !form.empty?
137
+ form.replace form.map{ |k, v| [k.to_s, v.is_a?(Integer) ? v.to_s : v] }.to_h
134
138
  case type
135
139
  when :json
136
140
  request.body = JSON.dump form
137
141
  request.content_type = "application/json"
138
- when :multipart
142
+ when :multipart # in this case form can be of width 3 (when sending files)
139
143
  request.set_form form, "multipart/form-data"
140
144
  when :form
141
145
  if form.any?{ |k, v| v.respond_to? :to_path }
@@ -173,7 +177,7 @@ module NetHTTPUtils
173
177
  end.chunk(&:first).map do |file, group|
174
178
  "#{file}:#{group.map(&:last).chunk{|_|_}.map(&:first).join(",")}"
175
179
  end
176
- logger.debug stack.join " -> "
180
+ logger.info stack.join " -> "
177
181
  end
178
182
  end
179
183
  do_request = lambda do |request|
@@ -208,10 +212,10 @@ module NetHTTPUtils
208
212
  response.fetch("x-rate-limit-reset").to_i,
209
213
  now.to_i,
210
214
  ]
211
- elsif response.key? "x-ratelimit-remaining"
215
+ elsif response.key? "x-ratelimit-remaining" # this is probably reddit-specific because ...
212
216
  [
213
217
  response.fetch("x-ratelimit-remaining").to_i,
214
- now + response.fetch("x-ratelimit-reset").to_i,
218
+ now.to_i + response.fetch("x-ratelimit-reset").to_i, # ... reddit sucks and so does not use timestamp here
215
219
  now.to_i,
216
220
  ]
217
221
  end
@@ -244,7 +248,6 @@ module NetHTTPUtils
244
248
  when /\A30\d\z/
245
249
  next response if no_redirect
246
250
  logger.info "redirect: #{response["location"]}"
247
- require "addressable"
248
251
  new_uri = URI.join request.uri.to_s, Addressable::URI.escape(response["location"])
249
252
  new_host = new_uri.host
250
253
  raise Error.new "redirected in place" if new_uri == http.instance_variable_get(:@uri)
data/nethttputils.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "nethttputils"
3
- spec.version = "0.4.3.2"
3
+ spec.version = "0.4.4.0"
4
4
  spec.summary = "this tool is like a pet that I adopted young and now I depend on, sorry"
5
5
  spec.description = <<-EOF
6
6
  Back in 2015 I was a guy automating things at my job and two scripts had a common need --
@@ -20,8 +20,6 @@ Gem::Specification.new do |spec|
20
20
  spec.email = "nakilon@gmail.com"
21
21
  spec.license = "MIT"
22
22
 
23
- spec.require_path = "lib"
24
23
  spec.files = %w{ LICENSE nethttputils.gemspec lib/nethttputils.rb }
25
-
26
24
  spec.add_dependency "addressable"
27
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nethttputils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3.2
4
+ version: 0.4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov aka Nakilon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-02 00:00:00.000000000 Z
11
+ date: 2023-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -62,8 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  requirements: []
65
- rubyforge_project:
66
- rubygems_version: 2.5.2.3
65
+ rubygems_version: 3.3.25
67
66
  signing_key:
68
67
  specification_version: 4
69
68
  summary: this tool is like a pet that I adopted young and now I depend on, sorry