nx-http 0.1.9 → 0.1.10

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
2
  SHA256:
3
- metadata.gz: ca5a2913361cd569bf8111137517ffa3f59eb52ac73e2d2a152ad6bac3b6a980
4
- data.tar.gz: 5e48b239e63b54775f09480031a68d72d08b7cc8b38bef18b7904b02a4f3dacf
3
+ metadata.gz: 77ece682f337723392a39b0879637b82d2c177eb21ffee22147403285c7f61c4
4
+ data.tar.gz: b4cdefb0bd341993abb031946e659790cb01ceb25a7a9d2336d13bf3e5440b95
5
5
  SHA512:
6
- metadata.gz: f83d2ca6b3614c00aca6068839945bbd57159f8282aee36a095a4225ad40ec7fb201520d7647b53701a9d04881f84eb9af6d3de554e4e19357a676936e80dabc
7
- data.tar.gz: 2af1d40b910260031c82dbd127434d0ba0ce59ddb8c5d82a98c64a56aada95e28a55fe032a38e20d5c8bc50de60394766bc0958b40a929cd14fa07d1327b07f3
6
+ metadata.gz: c41793dd4e41dffde12b3d9d08aabf62d1d7bb744cd065988bab67d6dddce56691175390d7a9ddafcdcb14605bbf9bb7a910ea1817c8587c3a5ed7221e313103
7
+ data.tar.gz: d3c185c427fc7e5a7656096517edb32584706b26f57d6501de31c8d2211e0a687e5e908e5a75b6ee6a4b2d1a9bd5f6a921b08e0700e5e127edf86692253fa3cf
@@ -4,7 +4,7 @@ require_relative "../lib/nx-http"
4
4
  # p Nx::ContentType::JSON
5
5
  tempfile = open("https://tva1.sinaimg.cn/large/da432263gy1gcj74ifcokj205f06gjre.jpg")
6
6
  res = Nx::Http.upload("https://picupload.weibo.com/interface/pic_upload.php", { pic1: tempfile }) do |http, request|
7
- request["Cookie"] = "SUB=_2A25zZYAzDeRhGeVI7VMZ8yzEyz-IHXVQEvb7rDV8PUNbmtAKLVPMkW9NTBpP0VsITWW-3vSzKJ0qcv_7qLmry_H2; Path=/; Domain=.weibo.com; HttpOnly"
7
+ request["Cookie"] = "SUB=_2A25zYkVLDeRhGeVI7VMZ8yzEyz-IHXVQFjGDrDV8PUNbmtAKLXLQkW9NTBpP0Tnizi_36CKgyQIO4Vzqxh9l_8Q2; Path=/; Domain=.weibo.com; HttpOnly"
8
8
  end
9
9
 
10
10
  p res.body
data/lib/nx/http.rb CHANGED
@@ -1,17 +1,11 @@
1
1
  module Nx
2
2
  class Http
3
3
  def self.upload(in_url, in_data)
4
- url = URI(in_url)
5
- http = Net::HTTP.new(url.host, url.port)
6
- http.use_ssl = url.scheme == "https"
7
-
8
- data = DataTransform.multipart(in_data)
9
- request = Net::HTTP::Post.new(url.path)
10
- request.set_form(data, ContentType::MULTIPART)
11
- if block_given?
12
- yield(http, request)
4
+ post(in_url, in_data) do |http, request, uri, method|
5
+ data = DataTransform.multipart(in_data)
6
+ request.set_form(data, ContentType::MULTIPART)
7
+ yield(http, request, uri, method)
13
8
  end
14
- http.request(request)
15
9
  end
16
10
 
17
11
  def self.request(in_method, in_url, in_data = {}, in_options = {})
@@ -25,24 +19,18 @@ module Nx
25
19
 
26
20
  # request:
27
21
  method_class = Net::HTTP.const_get method.capitalize
28
- request = method_class.new(in_url)
22
+ request = method_class.new(uri)
29
23
 
30
24
  # callback area:
31
25
  if method == "get"
32
26
  uri.query = URI.encode_www_form(in_data)
33
27
  else
34
28
  in_options.each do |key, value|
35
- if key == :content_type
36
- request[key] = ContentType.const_get value.upcase
37
- else
38
- request[key] = value
39
- end
29
+ request[key] = value
40
30
  end
41
31
  end
42
32
 
43
- if block_given?
44
- yield(http, request)
45
- end
33
+ yield(http, request, uri, method) if block_given?
46
34
 
47
35
  begin
48
36
  http.request(request)
data/lib/nx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Nx
2
2
  class Http
3
- VERSION = "0.1.9"
3
+ VERSION = "0.1.10"
4
4
  end
5
5
  end
data/nx-http-0.1.9.gem ADDED
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.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - afeiship
@@ -69,7 +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.8.gem
72
+ - nx-http-0.1.9.gem
73
73
  - nx-http.gemspec
74
74
  - package.json
75
75
  homepage: https://github.com/afeiship/nx-http
data/nx-http-0.1.8.gem DELETED
Binary file