nx-http 0.1.10 → 0.1.11

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
  SHA256:
3
- metadata.gz: 77ece682f337723392a39b0879637b82d2c177eb21ffee22147403285c7f61c4
4
- data.tar.gz: b4cdefb0bd341993abb031946e659790cb01ceb25a7a9d2336d13bf3e5440b95
3
+ metadata.gz: a9eb78e5131e69d6b9a12dfa6ae3b498ac443002acb0cd6265298fbc6abfb2be
4
+ data.tar.gz: 76878b79ce34f57bd444c3b15ec9fe3a247e5bc039c91639e77ab3609e8dae40
5
5
  SHA512:
6
- metadata.gz: c41793dd4e41dffde12b3d9d08aabf62d1d7bb744cd065988bab67d6dddce56691175390d7a9ddafcdcb14605bbf9bb7a910ea1817c8587c3a5ed7221e313103
7
- data.tar.gz: d3c185c427fc7e5a7656096517edb32584706b26f57d6501de31c8d2211e0a687e5e908e5a75b6ee6a4b2d1a9bd5f6a921b08e0700e5e127edf86692253fa3cf
6
+ metadata.gz: 29f22cc251d0912c5e562fdca3ab3f2dd980dbc70328f3f07109fcd1485eef01053892447aef954b8ebb46b368384ae5265d6f39fd5ba8c48cd0864daf98e386
7
+ data.tar.gz: 1c896d33582c00f3b20bb4ca86195de2d54ed2ff60563182a4f5f81ac6b686c1ce18dd2fc0f4e986c3418936d9b5439757c9b0dd0c30686456fb02e60a64370c
@@ -19,11 +19,15 @@ COOKIE = "PANWEB=1; csrfToken=HGPEF5J4BMUKDsBEOzo8FNRr; recommendTime=mac2020-03
19
19
  # # response = http.post(url, { pic1: HTTP::FormData::File.new(tempfile) }, headers)
20
20
  # puts response.body
21
21
 
22
- res = Nx::Http.post("https://pan.baidu.com/api/precreate") do |http, request|
22
+ res = Nx::Http.post("https://pan.baidu.com/api/precreate", {
23
+ path: "/db.file",
24
+ autoinit: 1,
25
+ block_list: '[""]',
26
+ }) do |http, request|
23
27
  request["Content-Type"] = "application/x-www-form-urlencoded"
24
28
  request["Cookie"] = COOKIE
25
29
  request["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"
26
- request.body = "path=/db.file&autoinit=1&block_list=%5B%225910a591dd8fc18c32a8f3df4fdc1761%22%5D"
30
+ # request.body = "path=/db.file&autoinit=1&block_list=%5B%225910a591dd8fc18c32a8f3df4fdc1761%22%5D"
27
31
  end
28
32
 
29
33
  puts res.body
@@ -1,8 +1,8 @@
1
1
  module Nx
2
2
  module ContentType
3
+ PLAIN = "text/plain"
4
+ JSON = "application/json;charset=utf-8"
3
5
  URLENCODED = "application/x-www-form-urlencoded"
4
6
  MULTIPART = "multipart/form-data"
5
- JSON = "application/json;charset=utf-8"
6
- PLAIN = "text/plain"
7
7
  end
8
8
  end
@@ -1,6 +1,6 @@
1
1
  module Nx
2
2
  class DataTransform
3
- def self.raw(data)
3
+ def self.plain(data)
4
4
  data
5
5
  end
6
6
 
data/lib/nx/http.rb CHANGED
@@ -9,6 +9,8 @@ module Nx
9
9
  end
10
10
 
11
11
  def self.request(in_method, in_url, in_data = {}, in_options = {})
12
+ default_options = { data_type: :urlencoded }
13
+ options = default_options.merge(in_options)
12
14
  # uri:
13
15
  uri = URI(in_url)
14
16
  method = in_method.downcase
@@ -20,14 +22,16 @@ module Nx
20
22
  # request:
21
23
  method_class = Net::HTTP.const_get method.capitalize
22
24
  request = method_class.new(uri)
25
+ request.content_type = ContentType.const_get(options[:data_type].upcase)
23
26
 
24
27
  # callback area:
25
28
  if method == "get"
26
29
  uri.query = URI.encode_www_form(in_data)
27
30
  else
28
- in_options.each do |key, value|
31
+ options.each do |key, value|
29
32
  request[key] = value
30
33
  end
34
+ request.body = DataTransform.send(options[:data_type], in_data)
31
35
  end
32
36
 
33
37
  yield(http, request, uri, method) if block_given?
data/lib/nx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Nx
2
2
  class Http
3
- VERSION = "0.1.10"
3
+ VERSION = "0.1.11"
4
4
  end
5
5
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nx-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - afeiship
@@ -69,6 +69,7 @@ files:
69
69
  - lib/nx/data_transform.rb
70
70
  - lib/nx/http.rb
71
71
  - lib/nx/version.rb
72
+ - nx-http-0.1.10.gem
72
73
  - nx-http-0.1.9.gem
73
74
  - nx-http.gemspec
74
75
  - package.json