class Line::Social::Request::Base

Public Instance Methods

http_client(method, &block) click to toggle source
# File lib/line/social/request/base.rb, line 5
def http_client(method, &block)
  client = Faraday.new do |connection|
    connection.response :json, content_type: /\bjson$/
    connection.response :raise_error
    connection.adapter Faraday.default_adapter
  end

  client.run_request(method, nil, nil, nil, &block)
rescue Faraday::Error::ClientError => e
  error_message = JSON.parse(e.response[:body])["message"]

  case e.response[:status]
  when 400
    raise Line::Social::BadRequestError.new(error_message)
  when 401
    raise Line::Social::UnauthorizedError.new(error_message)
  when 403
    raise Line::Social::ForbiddenError.new(error_message)
  when 429
    raise Line::Social::TooManyRequestsError.new(error_message)
  when 500
    raise Line::Social::InternalServerError.new(error_message)
  end
end