0.0
No release in over 3 years
Internal HTTP client for seibii services
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
 Project Readme

Seibii::Http

Circle CI codecov GitHub

Installation

gem 'seibii-http'

Usage

Base client

def get
  Seibii::Http::Clients::Base
    .new(logger: ->() { |log| Rails.logger.debug(log) }) # logger is optional
    .request(
       method: :get, # required
       uri: URI.parse('https://example.com/example'), # required
       read_timeout: 5, # optional, default set 60
       write_timeout: 60, # optional, default set 60
       request_body: nil, # optional
       headers: { Accept: '*/*' }, # optional
       need_verify_cert: false # optional
    ) #=> response body String
rescue Seibii::Http::ClientError => e # 404 will not raise exception but just return nil response
  p e
  p e.response.status #=> 400..499
  p e.response.body
rescue Seibii::Http::ServerError => e
  p e
  p e.response.status #=> 500..599
  p e.response.body
end

Json client

  • { Content-Type: 'application/json, Accept: 'application/json'}` headers will be added.
  • You can use hash to make request parameters and receive response
def post
  Seibii::Http::Clients::Json
    .new(logger: ->() { |log| Rails.logger.debug(log) }) # logger is optional
    .request(
       method: :post, # required
       uri: URI.parse('https://example.com/example'), # required
       read_timeout: 60, # optional, default set 60
       write_timeout: 5, # optional, default set 60
       params: { a: 'b', c: 'd' }, # optional
       headers: { Authorization: 'Bearer token' }, # optional
       need_verify_cert: false # optional
    ) #=> response json hash
rescue Seibii::Http::ClientError => e # 404 will not raise exception but just return nil response
  p e
  p e.response.status #=> 400..499 
  p e.response.body
rescue Seibii::Http::ServerError => e
  p e
  p e.response.status #=> 500..599
  p e.response.body
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/seibii/seibii-http. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Seibii::Http project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.