json_requester 1.0.12 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/json_requester.rb +9 -3
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz: '
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '041898e00afdd4c92015862bf81b7e09c61ba47a878eb9f2d90b77669862c722'
|
4
|
+
data.tar.gz: 1ee45b7f13909acfe21330fb8c311bb79f82bf9213c93974db199dba6f5eb86e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ef9fec55ef8e7acb71540acc7505290d40f638350339a6cce963a8945e9d516d77be11243908a2a12d440afd6534e1ce4141d83b0d3ad6edb5e0967faf526ee
|
7
|
+
data.tar.gz: e2e6296099857c012b2e402f952f49a02b8ebbcf24d5ff0c3bc2c380fcee797e6c144ed55eb1c685a82cd35857ccd1cbec6d8282699d024a8dece57f93bfe1d2
|
data/README.md
CHANGED
@@ -13,7 +13,8 @@ $ gem install json_requester
|
|
13
13
|
```ruby
|
14
14
|
host = 'http://httpbingo.org'
|
15
15
|
# `timeout` at Faraday gem default is 60 secs.
|
16
|
-
|
16
|
+
# `user_agent` at Faraday gem default is like "Faraday v1.10.0", it would be deep_merge at Faraday default setting.
|
17
|
+
requester = JsonRequester.new(host, timeout: 120, user_agent: 'My Agent 1.2')
|
17
18
|
|
18
19
|
http_method = :get # :get / :post / :put / :delete
|
19
20
|
path = ''
|
data/lib/json_requester.rb
CHANGED
@@ -4,11 +4,12 @@ require 'json'
|
|
4
4
|
class JsonRequester
|
5
5
|
attr_reader :host, :conn
|
6
6
|
|
7
|
-
def initialize(host, multipart: false, ssl_verify: true, timeout: 60)
|
7
|
+
def initialize(host, multipart: false, ssl_verify: true, timeout: 60, user_agent: '')
|
8
8
|
@host = host
|
9
9
|
@multipart = multipart
|
10
10
|
@ssl_verify = ssl_verify
|
11
11
|
@timeout = timeout
|
12
|
+
@user_agent = user_agent.strip.to_s
|
12
13
|
end
|
13
14
|
|
14
15
|
def http_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false)
|
@@ -32,12 +33,16 @@ class JsonRequester
|
|
32
33
|
error_response(e)
|
33
34
|
end
|
34
35
|
|
35
|
-
def json_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false)
|
36
|
+
def json_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false, content_type_charset: 'utf-8')
|
36
37
|
conn = init_conn(sort_params: sort_params)
|
37
38
|
res = conn.send(http_method) do |req|
|
38
39
|
req.url path
|
39
40
|
req.headers = headers if object_present?(headers)
|
40
|
-
|
41
|
+
if content_type_charset.present?
|
42
|
+
req.headers['Content-Type'] = "application/json;charset=#{content_type_charset}"
|
43
|
+
else
|
44
|
+
req.headers['Content-Type'] = 'application/json'
|
45
|
+
end
|
41
46
|
req.body = params.to_json if object_present?(params)
|
42
47
|
end
|
43
48
|
process_response(res, need_response_header: need_response_header)
|
@@ -73,6 +78,7 @@ class JsonRequester
|
|
73
78
|
def init_conn(sort_params: true)
|
74
79
|
# https://lostisland.github.io/faraday/#/customization/index?id=order-of-parameters
|
75
80
|
Faraday::NestedParamsEncoder.sort_params = sort_params # faraday default is true
|
81
|
+
Faraday.default_connection_options = { headers: { user_agent: @user_agent } } unless @user_agent.empty?
|
76
82
|
|
77
83
|
Faraday.new(url: host, ssl: { verify: @ssl_verify }) do |faraday|
|
78
84
|
faraday.request :multipart if @multipart # multipart form POST request
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_requester
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JiaRou Lee
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,34 +16,34 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.10'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
22
|
+
version: 1.10.3
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '1.
|
29
|
+
version: '1.10'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.
|
32
|
+
version: 1.10.3
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: pry
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.14.
|
39
|
+
version: 0.14.2
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.14.
|
46
|
+
version: 0.14.2
|
47
47
|
description: wrapper of faraday
|
48
48
|
email: laura34963@kdanmobile.com
|
49
49
|
executables: []
|
@@ -59,7 +59,7 @@ licenses:
|
|
59
59
|
metadata:
|
60
60
|
source_code_uri: https://github.com/kdan-mobile-software-ltd/json_requester
|
61
61
|
changelog_uri: https://github.com/kdan-mobile-software-ltd/json_requester/blob/master/CHANGELOG.md
|
62
|
-
post_install_message:
|
62
|
+
post_install_message:
|
63
63
|
rdoc_options:
|
64
64
|
- "--charset=UTF-8"
|
65
65
|
require_paths:
|
@@ -75,8 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
79
|
-
signing_key:
|
78
|
+
rubygems_version: 3.4.10
|
79
|
+
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: Basic Wrapper of Faraday
|
82
82
|
test_files: []
|