seibii-http 1.0.0 → 1.0.4

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: '049d320d3ad81582683158b91dc868413b5c4e169125b31c2a44f96c23ece44d'
4
- data.tar.gz: 5807f9ba69b6d4f8ee5e08ddf0164fe0fe57ae140316a8b5a41d3a9545d145e1
3
+ metadata.gz: 695bc27dd326051ba625cff2aa68ea0588d4dc473ebe55de1f7d04a7d0910d3f
4
+ data.tar.gz: 198ce874071d08aec60edd8aaea8fb716e3872ac4fe7d23fdda3481bb3afc19e
5
5
  SHA512:
6
- metadata.gz: c66ac55bb44a41272d1c77d0f57c328320307ed9077c4f8f32dcb92ee0487525fd0ee4d8a3e35b85a71b3a07b2a1abab0d707db8cd0cbff5c7327eb871016ea5
7
- data.tar.gz: 445459558e6c883b0c5d8e921827469a87af65308aeefdd4eaa08ba0d36e516c2b4a7398bf48bcfa70843ee244c0ced97c57db1d82e630f271651ebaadc132d5
6
+ metadata.gz: 12178a3985e937a76355034bb2c2fade89220959d95b51e173038d090bbda94de6aeddcf6350225b07bb5d25c50e2d033259e6727a9ec4b0c617040211918eb1
7
+ data.tar.gz: c4c0e5a69b8c6d20be0416727a7002c694325f792c62f8b5b745815b49dfe1d03ec7bb8b290f6a014e9eb77c07ee31e64659147bd27b4564f0ec301701314676
data/.circleci/config.yml CHANGED
@@ -17,7 +17,7 @@ restore_bundle_cache: &restore_bundle_cache
17
17
  jobs:
18
18
  build:
19
19
  docker:
20
- - image: circleci/ruby
20
+ - image: circleci/ruby:2.7.2
21
21
  steps:
22
22
  - checkout
23
23
  - *restore_bundle_cache
@@ -29,7 +29,7 @@ jobs:
29
29
  - vendor/bundle
30
30
  rubocop:
31
31
  docker:
32
- - image: circleci/ruby
32
+ - image: circleci/ruby:2.7.2
33
33
  steps:
34
34
  - checkout
35
35
  - *restore_bundle_cache
@@ -38,7 +38,7 @@ jobs:
38
38
  - run: bundle exec rubocop
39
39
  rspec:
40
40
  docker:
41
- - image: circleci/ruby
41
+ - image: circleci/ruby:2.7.2
42
42
  steps:
43
43
  - checkout
44
44
  - *restore_bundle_cache
@@ -0,0 +1,17 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: monthly
7
+ time: "11:00"
8
+ timezone: Asia/Tokyo
9
+ open-pull-requests-limit: 20
10
+ reviewers:
11
+ - avexbesuke
12
+ - amatotsuji
13
+ - yuta-sanada0089
14
+ ignore:
15
+ - dependency-name: codecov
16
+ versions:
17
+ - ">= 0.2.14.a, < 0.2.15"
data/Gemfile.lock CHANGED
@@ -1,23 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- seibii-http (1.0.0)
4
+ seibii-http (1.0.4)
5
5
  oj
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- ast (2.4.1)
11
- bigdecimal (2.0.0)
12
- codecov (0.2.8)
13
- json
14
- simplecov
10
+ ast (2.4.2)
11
+ codecov (0.5.2)
12
+ simplecov (>= 0.15, < 0.22)
15
13
  coderay (1.1.3)
16
14
  diff-lcs (1.4.4)
17
- docile (1.3.2)
18
- ffi (1.13.1)
15
+ docile (1.3.5)
16
+ ffi (1.15.1)
19
17
  formatador (0.2.5)
20
- guard (2.16.2)
18
+ guard (2.17.0)
21
19
  formatador (>= 0.2.4)
22
20
  listen (>= 2.7, < 4.0)
23
21
  lumberjack (>= 1.0.12, < 2.0)
@@ -31,66 +29,66 @@ GEM
31
29
  guard (~> 2.1)
32
30
  guard-compat (~> 1.1)
33
31
  rspec (>= 2.99.0, < 4.0)
34
- guard-rubocop (1.3.0)
32
+ guard-rubocop (1.4.0)
35
33
  guard (~> 2.0)
36
- rubocop (~> 0.20)
37
- json (2.3.1)
38
- listen (3.2.1)
34
+ rubocop (< 2.0)
35
+ listen (3.5.1)
39
36
  rb-fsevent (~> 0.10, >= 0.10.3)
40
37
  rb-inotify (~> 0.9, >= 0.9.10)
41
- lumberjack (1.2.7)
38
+ lumberjack (1.2.8)
42
39
  method_source (1.0.0)
43
40
  nenv (0.3.0)
44
41
  notiffany (0.1.3)
45
42
  nenv (~> 0.1)
46
43
  shellany (~> 0.0)
47
- oj (3.10.12)
48
- bigdecimal (>= 1.0, < 3)
49
- parallel (1.19.2)
50
- parser (2.7.1.4)
44
+ oj (3.11.7)
45
+ parallel (1.20.1)
46
+ parser (3.0.1.1)
51
47
  ast (~> 2.4.1)
52
- pry (0.13.1)
48
+ pry (0.14.1)
53
49
  coderay (~> 1.1)
54
50
  method_source (~> 1.0)
55
51
  rainbow (3.0.0)
56
- rake (10.5.0)
57
- rb-fsevent (0.10.4)
52
+ rake (13.0.3)
53
+ rb-fsevent (0.11.0)
58
54
  rb-inotify (0.10.1)
59
55
  ffi (~> 1.0)
60
- regexp_parser (1.7.1)
61
- rexml (3.2.4)
62
- rspec (3.9.0)
63
- rspec-core (~> 3.9.0)
64
- rspec-expectations (~> 3.9.0)
65
- rspec-mocks (~> 3.9.0)
66
- rspec-core (3.9.2)
67
- rspec-support (~> 3.9.3)
68
- rspec-expectations (3.9.2)
56
+ regexp_parser (2.1.1)
57
+ rexml (3.2.5)
58
+ rspec (3.10.0)
59
+ rspec-core (~> 3.10.0)
60
+ rspec-expectations (~> 3.10.0)
61
+ rspec-mocks (~> 3.10.0)
62
+ rspec-core (3.10.0)
63
+ rspec-support (~> 3.10.0)
64
+ rspec-expectations (3.10.0)
69
65
  diff-lcs (>= 1.2.0, < 2.0)
70
- rspec-support (~> 3.9.0)
71
- rspec-mocks (3.9.1)
66
+ rspec-support (~> 3.10.0)
67
+ rspec-mocks (3.10.0)
72
68
  diff-lcs (>= 1.2.0, < 2.0)
73
- rspec-support (~> 3.9.0)
74
- rspec-support (3.9.3)
75
- rubocop (0.89.1)
69
+ rspec-support (~> 3.10.0)
70
+ rspec-support (3.10.0)
71
+ rubocop (1.18.1)
76
72
  parallel (~> 1.10)
77
- parser (>= 2.7.1.1)
73
+ parser (>= 3.0.0.0)
78
74
  rainbow (>= 2.2.2, < 4.0)
79
- regexp_parser (>= 1.7)
75
+ regexp_parser (>= 1.8, < 3.0)
80
76
  rexml
81
- rubocop-ast (>= 0.3.0, < 1.0)
77
+ rubocop-ast (>= 1.7.0, < 2.0)
82
78
  ruby-progressbar (~> 1.7)
83
- unicode-display_width (>= 1.4.0, < 2.0)
84
- rubocop-ast (0.3.0)
85
- parser (>= 2.7.1.4)
86
- ruby-progressbar (1.10.1)
79
+ unicode-display_width (>= 1.4.0, < 3.0)
80
+ rubocop-ast (1.7.0)
81
+ parser (>= 3.0.1.1)
82
+ ruby-progressbar (1.11.0)
87
83
  shellany (0.0.1)
88
- simplecov (0.19.0)
84
+ simplecov (0.21.2)
89
85
  docile (~> 1.1)
90
86
  simplecov-html (~> 0.11)
91
- simplecov-html (0.12.2)
92
- thor (1.0.1)
93
- unicode-display_width (1.7.0)
87
+ simplecov_json_formatter (~> 0.1)
88
+ simplecov-html (0.12.3)
89
+ simplecov_json_formatter (0.1.2)
90
+ thor (1.1.0)
91
+ unicode-display_width (2.0.0)
94
92
 
95
93
  PLATFORMS
96
94
  ruby
@@ -108,4 +106,4 @@ DEPENDENCIES
108
106
  simplecov
109
107
 
110
108
  BUNDLED WITH
111
- 2.0.2
109
+ 2.1.4
data/README.md CHANGED
@@ -19,8 +19,11 @@ def get
19
19
  .request(
20
20
  method: :get, # required
21
21
  uri: URI.parse('https://example.com/example'), # required
22
+ read_timeout: 5, # optional, default set 60
23
+ write_timeout: 60, # optional, default set 60
22
24
  request_body: nil, # optional
23
- headers: { Accept: '*/*' } # optional
25
+ headers: { Accept: '*/*' }, # optional
26
+ need_verify_cert: false # optional
24
27
  ) #=> response body String
25
28
  rescue Seibii::Http::ClientError => e # 404 will not raise exception but just return nil response
26
29
  p e
@@ -44,8 +47,11 @@ def post
44
47
  .request(
45
48
  method: :post, # required
46
49
  uri: URI.parse('https://example.com/example'), # required
50
+ read_timeout: 60, # optional, default set 60
51
+ write_timeout: 5, # optional, default set 60
47
52
  params: { a: 'b', c: 'd' }, # optional
48
- headers: { Authorization: 'Bearer token' } # optional
53
+ headers: { Authorization: 'Bearer token' }, # optional
54
+ need_verify_cert: false # optional
49
55
  ) #=> response json hash
50
56
  rescue Seibii::Http::ClientError => e # 404 will not raise exception but just return nil response
51
57
  p e
@@ -8,18 +8,21 @@ module Seibii
8
8
  @logger = logger
9
9
  end
10
10
 
11
- def request(method:, uri:, request_body: nil, headers: {})
11
+ def request(method:, uri:, read_timeout: 60, write_timeout: 60, request_body: nil, headers: {}, need_verify_cert: false) # rubocop:disable Metrics/ParameterLists, Layout/LineLength
12
12
  parsed_uri = URI.parse(uri)
13
- with_logging(uri) { http(parsed_uri).request(request_object(method, parsed_uri, request_body, headers)) }
13
+ http = http(parsed_uri, need_verify_cert)
14
+ http.read_timeout = read_timeout
15
+ http.write_timeout = write_timeout
16
+ with_logging(uri) { http.request(request_object(method, parsed_uri, request_body, headers)) }
14
17
  .yield_self { |response| handle_http_status(response) }
15
18
  end
16
19
 
17
20
  private
18
21
 
19
- def http(uri)
22
+ def http(uri, need_verify_cert)
20
23
  @http ||= Net::HTTP.new(uri.host, uri.port).tap do |instance|
21
24
  instance.use_ssl = uri.scheme == 'https'
22
- instance.verify_mode = OpenSSL::SSL::VERIFY_NONE
25
+ instance.verify_mode = need_verify_cert ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
23
26
  end
24
27
  end
25
28
 
@@ -52,8 +55,8 @@ module Seibii
52
55
  def handle_http_status(response)
53
56
  case response.code.to_i
54
57
  when 404 then nil
55
- when 400..499 then raise ClientError, response
56
- when 500..599 then raise ServerError, response
58
+ when 400..499 then raise ClientError, response.body
59
+ when 500..599 then raise ServerError, response.body
57
60
  else response.body
58
61
  end
59
62
  end
@@ -8,12 +8,15 @@ module Seibii
8
8
  @base = Base.new(logger: logger)
9
9
  end
10
10
 
11
- def request(method:, uri:, params: nil, headers: {})
11
+ def request(method:, uri:, params: nil, headers: {}, need_verify_cert: false, read_timeout: 60, write_timeout: 60) # rubocop:disable Metrics/ParameterLists, Layout/LineLength
12
12
  response_body = @base.request(
13
13
  method: method,
14
14
  uri: uri,
15
15
  request_body: params&.yield_self { |p| Oj.dump(p, mode: :compat) },
16
- headers: headers.merge('Accept': 'application/json', 'Content-Type': 'application/json')
16
+ headers: headers.merge(Accept: 'application/json', 'Content-Type': 'application/json'),
17
+ need_verify_cert: need_verify_cert,
18
+ read_timeout: read_timeout,
19
+ write_timeout: write_timeout
17
20
  )
18
21
  Oj.load(response_body, mode: :compat, symbol_keys: true)
19
22
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Seibii
4
4
  module Http
5
- VERSION = '1.0.0'
5
+ VERSION = '1.0.4'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seibii-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Ueki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-26 00:00:00.000000000 Z
11
+ date: 2021-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -158,6 +158,7 @@ extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
160
  - ".circleci/config.yml"
161
+ - ".github/dependabot.yml"
161
162
  - ".gitignore"
162
163
  - ".rubocop.yml"
163
164
  - ".ruby-version"