json_requester 2.0.6 → 2.0.7

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/json_requester.rb +14 -14
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17b47e2fd4ae4d58bedc74c0e94d6523da84c269d5957373852fcefc95b39772
4
- data.tar.gz: 98655925a0e0d991e47f9e7b73cd3e06068bfcd15b0dc585ffff5dc83a03ce23
3
+ metadata.gz: 6b5c16b22f8ebb2f6dfb24fcc7c90a4989c69028d83d763b7220796abbc635b1
4
+ data.tar.gz: 5d4eb12d1807eb72ca2284b6207c0320c702738ba74553ed8c0bd049a6ffa6f7
5
5
  SHA512:
6
- metadata.gz: d74bac135c3d80b9fa0822be608dfcc14819eda008f1038d0951039edf796c3d32fd513ce212b508f615b495980b049746ecd452c1cf8f7b906adc66aec5faac
7
- data.tar.gz: 1445c55fe7f867f080597820ec7825b9ef94bb36dc9fb956bfdc5709e0fa7771f9712a07d13af5c1c09d9ad91f5499c3eba74c7cea07b44cec76c6505e729d67
6
+ metadata.gz: d2b407242fc322ff2a23401b02bde6e5046da77d40296ffa2c72f5d8a61c6055fb7f8f680f7be3057b7b819bdae14a7297dd672000ce333b72fcc7a3143a1009
7
+ data.tar.gz: 517b6d56cc8dfaa17b569b8288d6a94c254e7ed0a0f636fdcd7af2dbcc97f3ac681102070ac82d0f6d979b462f157292ed3d8b2c50cb62222d05a43ff58728ec
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'faraday'
4
- require 'faraday/multipart'
5
- require 'json'
3
+ require "faraday"
4
+ require "faraday/multipart"
5
+ require "json"
6
6
 
7
7
  class JsonRequester
8
8
  attr_reader :host, :conn
9
9
 
10
- def initialize(host, multipart: false, ssl_verify: true, timeout: 60, user_agent: '')
10
+ def initialize(host, multipart: false, ssl_verify: true, timeout: 60, user_agent: "")
11
11
  @host = host
12
12
  @multipart = multipart
13
13
  @ssl_verify = ssl_verify
@@ -15,7 +15,7 @@ class JsonRequester
15
15
  @user_agent = user_agent.strip.to_s
16
16
  end
17
17
 
18
- def http_send(http_method, path, params = {}, headers = {}, sort_params: true, need_response_header: false, content_type_charset: 'utf-8')
18
+ def http_send(http_method, path, params = {}, headers = {}, sort_params: true, need_response_header: false, content_type_charset: "utf-8")
19
19
  puts "send #{http_method} request to #{@host} with\npath: #{path}\nparams: #{params}\nheaders: #{headers}"
20
20
  if http_method == :get
21
21
  normal_send(http_method, path, params, headers, sort_params: sort_params, need_response_header: need_response_header)
@@ -36,12 +36,12 @@ class JsonRequester
36
36
  error_response(e)
37
37
  end
38
38
 
39
- def json_send(http_method, path, params = {}, headers = {}, sort_params: true, need_response_header: false, content_type_charset: 'utf-8')
39
+ def json_send(http_method, path, params = {}, headers = {}, sort_params: true, need_response_header: false, content_type_charset: "utf-8")
40
40
  conn = init_conn(sort_params: sort_params)
41
41
  res = conn.send(http_method) do |req|
42
42
  req.url path
43
43
  req.headers = headers if object_present?(headers)
44
- req.headers['Content-Type'] = object_present?(content_type_charset) ? "application/json;charset=#{content_type_charset}" : 'application/json'
44
+ req.headers["Content-Type"] = object_present?(content_type_charset) ? "application/json;charset=#{content_type_charset}" : "application/json"
45
45
  req.body = params.to_json if object_present?(params)
46
46
  end
47
47
  process_response(res, need_response_header: need_response_header)
@@ -54,7 +54,7 @@ class JsonRequester
54
54
  res = conn.send(http_method) do |req|
55
55
  req.url path
56
56
  req.headers = headers if object_present?(headers)
57
- req.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
57
+ req.headers["Content-Type"] = "application/x-www-form-urlencoded;charset=utf-8"
58
58
  req.body = URI.encode_www_form(params) if object_present?(params)
59
59
  end
60
60
  process_response(res, need_response_header: need_response_header)
@@ -93,21 +93,21 @@ class JsonRequester
93
93
  end
94
94
 
95
95
  def process_response(response, need_response_header: false)
96
- result = { 'status' => response.status }
96
+ result = { "status" => response.status }
97
97
  begin
98
98
  body = JSON.parse(response.body)
99
- body = { 'body' => body } unless body.is_a?(Hash)
100
- body['body_status'] = body.delete('status') unless body['status'].nil?
99
+ body = { "body" => body } unless body.is_a?(Hash)
100
+ body["body_status"] = body.delete("status") unless body["status"].nil?
101
101
  rescue StandardError
102
- body = { 'body' => response.body }
102
+ body = { "body" => response.body }
103
103
  end
104
104
  result.merge!(body)
105
- result['headers'] = response.headers.to_h if need_response_header
105
+ result["headers"] = response.headers.to_h if need_response_header
106
106
  result
107
107
  end
108
108
 
109
109
  def error_response(err)
110
- { 'status' => 500, 'message' => "#{err.class.name}: #{err.message}" }
110
+ { "status" => 500, "message" => "#{err.class.name}: #{err.message}" }
111
111
  end
112
112
 
113
113
  def object_present?(object)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_requester
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - JiaRou Lee