nethttputils 0.2.2.0 → 0.2.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca4a5b681f2630f07305d6d9c6df59eea09e4bbf
4
- data.tar.gz: 90f8e4f7d626205f0f9673b4eb2069e6bcde7df8
3
+ metadata.gz: bec88b8ff9beeae7cc18250b6a2d955aa6d7845b
4
+ data.tar.gz: 820c5f45fbd937fd89912eb30c35c264f98923df
5
5
  SHA512:
6
- metadata.gz: 6bbc62b4643d52eb8d78cd2ea83eea72888fcff29695c176f368774fa0e8fd1858bf0478c7be6ce99580223f659eef5813c3102bb11578eb6469b4b7f746b838
7
- data.tar.gz: f7690fbcf2ea1ac772e768429411b4b061ccf8d8dc02ed9382ab6798a3ba8ff8be554dfbee41c3adb449a6bf3e1f8cbf4d8c79787b0e214684fd161549bedfbb
6
+ metadata.gz: d5d9ab8603996adc703bb812d85fea42e359167736be39eecdd1aecc71d8c1667662672b8cb22ce7ff66384b655415aa342b4b0b0f005d3a5a7e09359074df88
7
+ data.tar.gz: 6ebc04827c686dfc8e15f9cdb14758ef5604a45e252e2472da070603dacb779a92f2ff11d5869b6b1d7bd64f9d4bb049b66dd69ddbbdc5bf91730e9a87877814
data/.travis.yml CHANGED
@@ -19,4 +19,3 @@ matrix:
19
19
  allow_failures:
20
20
  # something with `NetHTTPUtils.request_data("http://localhost:8000/?1=2&3=4", form: {1=>3})` test
21
21
  - rvm: jruby-head
22
- os: linux
data/lib/nethttputils.rb CHANGED
@@ -35,9 +35,10 @@ module NetHTTPUtils
35
35
  url
36
36
  rescue URI::InvalidURIError
37
37
  URI.escape url
38
- end
38
+ end unless uri.is_a? URI::HTTP
39
+
39
40
 
40
- logger.warn "Warning: query params included `url` are discarded because `:form` isn't empty" if uri.query && !form.empty?
41
+ logger.warn "Warning: query params included in `url` argument are discarded because `:form` isn't empty" if uri.query && !form.empty?
41
42
  # we can't just merge because URI fails to parse such queries as "/?1"
42
43
 
43
44
  uri.query = URI.encode_www_form form if :GET == (mtd = mtd.upcase) && !form.empty?
@@ -54,12 +55,17 @@ module NetHTTPUtils
54
55
  patch_request.call uri, form, request if patch_request
55
56
  request.basic_auth *auth if auth
56
57
  request["cookie"] = [*request["cookie"], cookies.map{ |k, v| "#{k}=#{v}" }].join "; " unless cookies.empty?
57
- request.set_form_data form if !form.empty? && mtd == :POST
58
- if mtd == :POST || mtd == :PATCH
59
- request["Content-Type"] = case type
60
- when :form ; "application/x-www-form-urlencoded;charset=UTF-8"
61
- when :json ; request.body = JSON.dump form # yes this overwrites form data set few lines higher
62
- "application/json"
58
+ # pp Object.instance_method(:method).bind(request).call(:set_form).source_location
59
+ if (mtd == :POST || mtd == :PATCH) && !form.empty?
60
+ case type
61
+ when :form ; if form.any?{ |k, v| v.respond_to? :to_path }
62
+ request.set_form form, "multipart/form-data"
63
+ else
64
+ request.set_form_data form
65
+ request.content_type = "application/x-www-form-urlencoded;charset=UTF-8"
66
+ end
67
+ when :json ; request.body = JSON.dump form
68
+ request.content_type = "application/json"
63
69
  else ; raise "unknown content-type '#{type}'"
64
70
  end
65
71
  end
data/nethttputils.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "nethttputils"
3
- spec.version = "0.2.2.0"
3
+ spec.version = "0.2.3.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 --
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.2.2.0
4
+ version: 0.2.3.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: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2018-05-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Back in 2015 I was a guy automating things at my job and two scripts had a common need --