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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8dfecc45546053e16000e455aeb59cb5bae730a8016dc832a7159f270bb399a3
4
- data.tar.gz: 6855c9af527d966b3a9aef3474183732d395aedb22525244c390d726c96b3274
3
+ metadata.gz: '049d320d3ad81582683158b91dc868413b5c4e169125b31c2a44f96c23ece44d'
4
+ data.tar.gz: 5807f9ba69b6d4f8ee5e08ddf0164fe0fe57ae140316a8b5a41d3a9545d145e1
5
5
  SHA512:
6
- metadata.gz: a3147076b8719d15a7418ff28f301795155f85a87ac82e765217d2ed40f6079c278fdefb0b080a408371f68803a27acb849c9c0f473a7617a2effcc9c5cf0bf9
7
- data.tar.gz: 7d49c4bb540abd124d9f51cc4de1435ec8d29a979824b6fbaf204e24a6bf303fb117343b4a30e9f9dd340fcde87e0eeba367e98c2d25170e36e8d5d6e7e933ba
6
+ metadata.gz: c66ac55bb44a41272d1c77d0f57c328320307ed9077c4f8f32dcb92ee0487525fd0ee4d8a3e35b85a71b3a07b2a1abab0d707db8cd0cbff5c7327eb871016ea5
7
+ data.tar.gz: 445459558e6c883b0c5d8e921827469a87af65308aeefdd4eaa08ba0d36e516c2b4a7398bf48bcfa70843ee244c0ced97c57db1d82e630f271651ebaadc132d5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- seibii-http (0.1.0)
4
+ seibii-http (1.0.0)
5
5
  oj
6
6
 
7
7
  GEM
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.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
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.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
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
- with_logging(uri) { http(uri).request(request_object(method, uri, request_body, headers)) }
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Seibii
4
4
  module Http
5
- VERSION = '0.1.0'
5
+ VERSION = '1.0.0'
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: 0.1.0
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-25 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj