seibii-http 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +22 -9
- data/lib/seibii/http/clients/base.rb +2 -1
- data/lib/seibii/http/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '049d320d3ad81582683158b91dc868413b5c4e169125b31c2a44f96c23ece44d'
|
4
|
+
data.tar.gz: 5807f9ba69b6d4f8ee5e08ddf0164fe0fe57ae140316a8b5a41d3a9545d145e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c66ac55bb44a41272d1c77d0f57c328320307ed9077c4f8f32dcb92ee0487525fd0ee4d8a3e35b85a71b3a07b2a1abab0d707db8cd0cbff5c7327eb871016ea5
|
7
|
+
data.tar.gz: 445459558e6c883b0c5d8e921827469a87af65308aeefdd4eaa08ba0d36e516c2b4a7398bf48bcfa70843ee244c0ced97c57db1d82e630f271651ebaadc132d5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -14,10 +14,15 @@ gem 'seibii-http'
|
|
14
14
|
### Base client
|
15
15
|
```ruby
|
16
16
|
def get
|
17
|
-
Seibii::Http::Clients::Base
|
18
|
-
.
|
19
|
-
|
20
|
-
|
17
|
+
Seibii::Http::Clients::Base
|
18
|
+
.new(logger: ->() { |log| Rails.logger.debug(log) }) # logger is optional
|
19
|
+
.request(
|
20
|
+
method: :get, # required
|
21
|
+
uri: URI.parse('https://example.com/example'), # required
|
22
|
+
request_body: nil, # optional
|
23
|
+
headers: { Accept: '*/*' } # optional
|
24
|
+
) #=> response body String
|
25
|
+
rescue Seibii::Http::ClientError => e # 404 will not raise exception but just return nil response
|
21
26
|
p e
|
22
27
|
p e.response.status #=> 400..499
|
23
28
|
p e.response.body
|
@@ -29,14 +34,22 @@ end
|
|
29
34
|
```
|
30
35
|
|
31
36
|
### Json client
|
37
|
+
- `{ Content-Type: 'application/json`, Accept: 'application/json'}` headers will be added.
|
38
|
+
- You can use hash to make request parameters and receive response
|
39
|
+
|
32
40
|
```ruby
|
33
41
|
def post
|
34
|
-
Seibii::Http::Clients::Json
|
35
|
-
.
|
36
|
-
|
37
|
-
|
42
|
+
Seibii::Http::Clients::Json
|
43
|
+
.new(logger: ->() { |log| Rails.logger.debug(log) }) # logger is optional
|
44
|
+
.request(
|
45
|
+
method: :post, # required
|
46
|
+
uri: URI.parse('https://example.com/example'), # required
|
47
|
+
params: { a: 'b', c: 'd' }, # optional
|
48
|
+
headers: { Authorization: 'Bearer token' } # optional
|
49
|
+
) #=> response json hash
|
50
|
+
rescue Seibii::Http::ClientError => e # 404 will not raise exception but just return nil response
|
38
51
|
p e
|
39
|
-
p e.response.status #=> 400..499
|
52
|
+
p e.response.status #=> 400..499
|
40
53
|
p e.response.body
|
41
54
|
rescue Seibii::Http::ServerError => e
|
42
55
|
p e
|
@@ -9,7 +9,8 @@ module Seibii
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def request(method:, uri:, request_body: nil, headers: {})
|
12
|
-
|
12
|
+
parsed_uri = URI.parse(uri)
|
13
|
+
with_logging(uri) { http(parsed_uri).request(request_object(method, parsed_uri, request_body, headers)) }
|
13
14
|
.yield_self { |response| handle_http_status(response) }
|
14
15
|
end
|
15
16
|
|
data/lib/seibii/http/version.rb
CHANGED
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:
|
4
|
+
version: 1.0.0
|
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-
|
11
|
+
date: 2020-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|