seibii-http 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +60 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +10 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +111 -0
- data/Guardfile +49 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/lib/seibii/http.rb +28 -0
- data/lib/seibii/http/clients.rb +11 -0
- data/lib/seibii/http/clients/base.rb +62 -0
- data/lib/seibii/http/clients/json.rb +23 -0
- data/lib/seibii/http/version.rb +7 -0
- data/seibii-http.gemspec +40 -0
- metadata +204 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8dfecc45546053e16000e455aeb59cb5bae730a8016dc832a7159f270bb399a3
|
4
|
+
data.tar.gz: 6855c9af527d966b3a9aef3474183732d395aedb22525244c390d726c96b3274
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3147076b8719d15a7418ff28f301795155f85a87ac82e765217d2ed40f6079c278fdefb0b080a408371f68803a27acb849c9c0f473a7617a2effcc9c5cf0bf9
|
7
|
+
data.tar.gz: 7d49c4bb540abd124d9f51cc4de1435ec8d29a979824b6fbaf204e24a6bf303fb117343b4a30e9f9dd340fcde87e0eeba367e98c2d25170e36e8d5d6e7e933ba
|
@@ -0,0 +1,60 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
update_bundler: &update_bundler
|
4
|
+
run:
|
5
|
+
name: update bundler
|
6
|
+
command: gem update bundler
|
7
|
+
|
8
|
+
bundle_install: &bundle_install
|
9
|
+
run:
|
10
|
+
name: bundle install
|
11
|
+
command: bundle update --bundler && bundle install --path vendor/bundle --jobs 4
|
12
|
+
|
13
|
+
restore_bundle_cache: &restore_bundle_cache
|
14
|
+
restore_cache:
|
15
|
+
key: cache-bundler-{{ checksum "Gemfile.lock" }}
|
16
|
+
|
17
|
+
jobs:
|
18
|
+
build:
|
19
|
+
docker:
|
20
|
+
- image: circleci/ruby
|
21
|
+
steps:
|
22
|
+
- checkout
|
23
|
+
- *restore_bundle_cache
|
24
|
+
- *update_bundler
|
25
|
+
- *bundle_install
|
26
|
+
- save_cache:
|
27
|
+
key: cache-bundler-{{ checksum "Gemfile.lock" }}
|
28
|
+
paths:
|
29
|
+
- vendor/bundle
|
30
|
+
rubocop:
|
31
|
+
docker:
|
32
|
+
- image: circleci/ruby
|
33
|
+
steps:
|
34
|
+
- checkout
|
35
|
+
- *restore_bundle_cache
|
36
|
+
- *update_bundler
|
37
|
+
- *bundle_install
|
38
|
+
- run: bundle exec rubocop
|
39
|
+
rspec:
|
40
|
+
docker:
|
41
|
+
- image: circleci/ruby
|
42
|
+
steps:
|
43
|
+
- checkout
|
44
|
+
- *restore_bundle_cache
|
45
|
+
- *update_bundler
|
46
|
+
- *bundle_install
|
47
|
+
- run:
|
48
|
+
environment:
|
49
|
+
COVERAGE: true
|
50
|
+
CODECOV_TOKEN: 32316e82-23f7-41a7-86dc-52d616999b22
|
51
|
+
command: bundle exec rspec
|
52
|
+
workflows:
|
53
|
+
version: 2.1
|
54
|
+
rspec:
|
55
|
+
jobs:
|
56
|
+
- build
|
57
|
+
- rubocop:
|
58
|
+
requires: [build]
|
59
|
+
- rspec:
|
60
|
+
requires: [build]
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.3
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at unhappychoice@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
seibii-http (0.1.0)
|
5
|
+
oj
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.1)
|
11
|
+
bigdecimal (2.0.0)
|
12
|
+
codecov (0.2.8)
|
13
|
+
json
|
14
|
+
simplecov
|
15
|
+
coderay (1.1.3)
|
16
|
+
diff-lcs (1.4.4)
|
17
|
+
docile (1.3.2)
|
18
|
+
ffi (1.13.1)
|
19
|
+
formatador (0.2.5)
|
20
|
+
guard (2.16.2)
|
21
|
+
formatador (>= 0.2.4)
|
22
|
+
listen (>= 2.7, < 4.0)
|
23
|
+
lumberjack (>= 1.0.12, < 2.0)
|
24
|
+
nenv (~> 0.1)
|
25
|
+
notiffany (~> 0.0)
|
26
|
+
pry (>= 0.9.12)
|
27
|
+
shellany (~> 0.0)
|
28
|
+
thor (>= 0.18.1)
|
29
|
+
guard-compat (1.2.1)
|
30
|
+
guard-rspec (4.7.3)
|
31
|
+
guard (~> 2.1)
|
32
|
+
guard-compat (~> 1.1)
|
33
|
+
rspec (>= 2.99.0, < 4.0)
|
34
|
+
guard-rubocop (1.3.0)
|
35
|
+
guard (~> 2.0)
|
36
|
+
rubocop (~> 0.20)
|
37
|
+
json (2.3.1)
|
38
|
+
listen (3.2.1)
|
39
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
40
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
41
|
+
lumberjack (1.2.7)
|
42
|
+
method_source (1.0.0)
|
43
|
+
nenv (0.3.0)
|
44
|
+
notiffany (0.1.3)
|
45
|
+
nenv (~> 0.1)
|
46
|
+
shellany (~> 0.0)
|
47
|
+
oj (3.10.12)
|
48
|
+
bigdecimal (>= 1.0, < 3)
|
49
|
+
parallel (1.19.2)
|
50
|
+
parser (2.7.1.4)
|
51
|
+
ast (~> 2.4.1)
|
52
|
+
pry (0.13.1)
|
53
|
+
coderay (~> 1.1)
|
54
|
+
method_source (~> 1.0)
|
55
|
+
rainbow (3.0.0)
|
56
|
+
rake (10.5.0)
|
57
|
+
rb-fsevent (0.10.4)
|
58
|
+
rb-inotify (0.10.1)
|
59
|
+
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)
|
69
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
70
|
+
rspec-support (~> 3.9.0)
|
71
|
+
rspec-mocks (3.9.1)
|
72
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
73
|
+
rspec-support (~> 3.9.0)
|
74
|
+
rspec-support (3.9.3)
|
75
|
+
rubocop (0.89.1)
|
76
|
+
parallel (~> 1.10)
|
77
|
+
parser (>= 2.7.1.1)
|
78
|
+
rainbow (>= 2.2.2, < 4.0)
|
79
|
+
regexp_parser (>= 1.7)
|
80
|
+
rexml
|
81
|
+
rubocop-ast (>= 0.3.0, < 1.0)
|
82
|
+
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)
|
87
|
+
shellany (0.0.1)
|
88
|
+
simplecov (0.19.0)
|
89
|
+
docile (~> 1.1)
|
90
|
+
simplecov-html (~> 0.11)
|
91
|
+
simplecov-html (0.12.2)
|
92
|
+
thor (1.0.1)
|
93
|
+
unicode-display_width (1.7.0)
|
94
|
+
|
95
|
+
PLATFORMS
|
96
|
+
ruby
|
97
|
+
|
98
|
+
DEPENDENCIES
|
99
|
+
bundler (~> 2.0)
|
100
|
+
codecov
|
101
|
+
guard
|
102
|
+
guard-rspec
|
103
|
+
guard-rubocop
|
104
|
+
rake
|
105
|
+
rspec (>= 3.0.0)
|
106
|
+
rubocop
|
107
|
+
seibii-http!
|
108
|
+
simplecov
|
109
|
+
|
110
|
+
BUNDLED WITH
|
111
|
+
2.0.2
|
data/Guardfile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A sample Guardfile
|
4
|
+
# More info at https://github.com/guard/guard#readme
|
5
|
+
|
6
|
+
## Uncomment and set this to only include directories you want to watch
|
7
|
+
# directories %w(app lib config test spec features) \
|
8
|
+
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
9
|
+
|
10
|
+
## Note: if you are using the `directories` clause above and you are not
|
11
|
+
## watching the project directory ('.'), then you will want to move
|
12
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
13
|
+
#
|
14
|
+
# $ mkdir config
|
15
|
+
# $ mv Guardfile config/
|
16
|
+
# $ ln -s config/Guardfile .
|
17
|
+
#
|
18
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
19
|
+
|
20
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
21
|
+
# rspec may be run, below are examples of the most common uses.
|
22
|
+
# * bundler: 'bundle exec rspec'
|
23
|
+
# * bundler binstubs: 'bin/rspec'
|
24
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
25
|
+
# installed the spring binstubs per the docs)
|
26
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
27
|
+
# * 'just' rspec: 'rspec'
|
28
|
+
|
29
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
30
|
+
require 'guard/rspec/dsl'
|
31
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
32
|
+
|
33
|
+
# Feel free to open issues for suggestions and improvements
|
34
|
+
|
35
|
+
# RSpec files
|
36
|
+
rspec = dsl.rspec
|
37
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
38
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
39
|
+
watch(rspec.spec_files)
|
40
|
+
|
41
|
+
# Ruby files
|
42
|
+
ruby = dsl.ruby
|
43
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
44
|
+
end
|
45
|
+
|
46
|
+
guard :rubocop do
|
47
|
+
watch(/.+\.rb$/)
|
48
|
+
watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
|
49
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Yuji Ueki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Seibii::Http
|
2
|
+
[![Circle CI](https://circleci.com/gh/seibii/seibii-http.svg?style=shield)](https://circleci.com/gh/seibii/seibii-http)
|
3
|
+
[![codecov](https://codecov.io/gh/seibii/seibii-http/branch/master/graph/badge.svg)](https://codecov.io/gh/seibii/seibii-http)
|
4
|
+
![GitHub](https://img.shields.io/github/license/seibii/seibii-http.svg)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'seibii-http'
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
### Base client
|
15
|
+
```ruby
|
16
|
+
def get
|
17
|
+
Seibii::Http::Clients::Base.new(logger: ->() { |log| Rails.logger.debug(log) })
|
18
|
+
.request(method: :get, uri: URI.parse('https://example.com/example'), request_body: nil, headers: { Accept: '*/*' })
|
19
|
+
#=> response body String
|
20
|
+
rescue Seibii::Http::ClientError => e
|
21
|
+
p e
|
22
|
+
p e.response.status #=> 400..499
|
23
|
+
p e.response.body
|
24
|
+
rescue Seibii::Http::ServerError => e
|
25
|
+
p e
|
26
|
+
p e.response.status #=> 500..599
|
27
|
+
p e.response.body
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
### Json client
|
32
|
+
```ruby
|
33
|
+
def post
|
34
|
+
Seibii::Http::Clients::Json.new(logger: ->() { |log| Rails.logger.debug(log) })
|
35
|
+
.request(method: :post, uri: URI.parse('https://example.com/example'), params: { a: 'b', c: 'd' }, headers: { Authorization: 'Bearer token' })
|
36
|
+
#=> response json hash
|
37
|
+
rescue Seibii::Http::ClientError => e
|
38
|
+
p e
|
39
|
+
p e.response.status #=> 400..499
|
40
|
+
p e.response.body
|
41
|
+
rescue Seibii::Http::ServerError => e
|
42
|
+
p e
|
43
|
+
p e.response.status #=> 500..599
|
44
|
+
p e.response.body
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/unhappychoice/seibii-http. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
55
|
+
|
56
|
+
## Code of Conduct
|
57
|
+
|
58
|
+
Everyone interacting in the Seibii::Http project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/unhappychoice/seibii-http/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/lib/seibii/http.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'oj'
|
5
|
+
require 'seibii/http/clients'
|
6
|
+
require 'seibii/http/version'
|
7
|
+
|
8
|
+
module Seibii
|
9
|
+
module Http
|
10
|
+
class ClientError < StandardError
|
11
|
+
attr_reader :response
|
12
|
+
|
13
|
+
def initialize(response)
|
14
|
+
super
|
15
|
+
@response = response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class ServerError < StandardError
|
20
|
+
attr_reader :response
|
21
|
+
|
22
|
+
def initialize(response)
|
23
|
+
super
|
24
|
+
@response = response
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seibii
|
4
|
+
module Http
|
5
|
+
module Clients
|
6
|
+
class Base
|
7
|
+
def initialize(logger: nil)
|
8
|
+
@logger = logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def request(method:, uri:, request_body: nil, headers: {})
|
12
|
+
with_logging(uri) { http(uri).request(request_object(method, uri, request_body, headers)) }
|
13
|
+
.yield_self { |response| handle_http_status(response) }
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def http(uri)
|
19
|
+
@http ||= Net::HTTP.new(uri.host, uri.port).tap do |instance|
|
20
|
+
instance.use_ssl = uri.scheme == 'https'
|
21
|
+
instance.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def request_object(method, uri, request_body, headers)
|
26
|
+
http_class_for(method)
|
27
|
+
.new(uri.request_uri)
|
28
|
+
.tap { |instance| headers.each { |key, value| instance[key.to_s] = value } }
|
29
|
+
.tap { |instance| instance.body = request_body }
|
30
|
+
end
|
31
|
+
|
32
|
+
def http_class_for(method)
|
33
|
+
case method
|
34
|
+
when :head then Net::HTTP::Head
|
35
|
+
when :get then Net::HTTP::Get
|
36
|
+
when :post then Net::HTTP::Post
|
37
|
+
when :patch then Net::HTTP::Patch
|
38
|
+
when :put then Net::HTTP::Put
|
39
|
+
when :delete then Net::HTTP::Delete
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def with_logging(uri)
|
44
|
+
started_at = Time.now.to_f
|
45
|
+
@logger&.call("Fetching #{uri}")
|
46
|
+
result = yield
|
47
|
+
@logger&.call("Fetched #{uri} (#{Time.now.to_f - started_at} sec)")
|
48
|
+
result
|
49
|
+
end
|
50
|
+
|
51
|
+
def handle_http_status(response)
|
52
|
+
case response.code.to_i
|
53
|
+
when 404 then nil
|
54
|
+
when 400..499 then raise ClientError, response
|
55
|
+
when 500..599 then raise ServerError, response
|
56
|
+
else response.body
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seibii
|
4
|
+
module Http
|
5
|
+
module Clients
|
6
|
+
class Json
|
7
|
+
def initialize(logger: nil)
|
8
|
+
@base = Base.new(logger: logger)
|
9
|
+
end
|
10
|
+
|
11
|
+
def request(method:, uri:, params: nil, headers: {})
|
12
|
+
response_body = @base.request(
|
13
|
+
method: method,
|
14
|
+
uri: uri,
|
15
|
+
request_body: params&.yield_self { |p| Oj.dump(p, mode: :compat) },
|
16
|
+
headers: headers.merge('Accept': 'application/json', 'Content-Type': 'application/json')
|
17
|
+
)
|
18
|
+
Oj.load(response_body, mode: :compat, symbol_keys: true)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/seibii-http.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'seibii/http/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'seibii-http'
|
7
|
+
spec.version = Seibii::Http::VERSION
|
8
|
+
spec.authors = ['Yuji Ueki']
|
9
|
+
spec.email = ['unhappychoice@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Internal HTTP client for seibii services'
|
12
|
+
spec.description = 'Internal HTTP client for seibii services'
|
13
|
+
spec.homepage = 'https://github.com/seibii/seibii-http'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/seibii/seibii-http'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/seibii/seibii-http'
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_runtime_dependency 'oj'
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
32
|
+
spec.add_development_dependency 'codecov'
|
33
|
+
spec.add_development_dependency 'guard'
|
34
|
+
spec.add_development_dependency 'guard-rspec'
|
35
|
+
spec.add_development_dependency 'guard-rubocop'
|
36
|
+
spec.add_development_dependency 'rake'
|
37
|
+
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
38
|
+
spec.add_development_dependency 'rubocop'
|
39
|
+
spec.add_development_dependency 'simplecov'
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seibii-http
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuji Ueki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.0.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 3.0.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: Internal HTTP client for seibii services
|
154
|
+
email:
|
155
|
+
- unhappychoice@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".circleci/config.yml"
|
161
|
+
- ".gitignore"
|
162
|
+
- ".rubocop.yml"
|
163
|
+
- ".ruby-version"
|
164
|
+
- ".travis.yml"
|
165
|
+
- CODE_OF_CONDUCT.md
|
166
|
+
- Gemfile
|
167
|
+
- Gemfile.lock
|
168
|
+
- Guardfile
|
169
|
+
- LICENSE.txt
|
170
|
+
- README.md
|
171
|
+
- Rakefile
|
172
|
+
- lib/seibii/http.rb
|
173
|
+
- lib/seibii/http/clients.rb
|
174
|
+
- lib/seibii/http/clients/base.rb
|
175
|
+
- lib/seibii/http/clients/json.rb
|
176
|
+
- lib/seibii/http/version.rb
|
177
|
+
- seibii-http.gemspec
|
178
|
+
homepage: https://github.com/seibii/seibii-http
|
179
|
+
licenses:
|
180
|
+
- MIT
|
181
|
+
metadata:
|
182
|
+
homepage_uri: https://github.com/seibii/seibii-http
|
183
|
+
source_code_uri: https://github.com/seibii/seibii-http
|
184
|
+
changelog_uri: https://github.com/seibii/seibii-http
|
185
|
+
post_install_message:
|
186
|
+
rdoc_options: []
|
187
|
+
require_paths:
|
188
|
+
- lib
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
requirements: []
|
200
|
+
rubygems_version: 3.0.3
|
201
|
+
signing_key:
|
202
|
+
specification_version: 4
|
203
|
+
summary: Internal HTTP client for seibii services
|
204
|
+
test_files: []
|