Class: ChatWork::BaseClient
- Inherits:
-
Object
- Object
- ChatWork::BaseClient
- Defined in:
- lib/chatwork/base_client.rb
Direct Known Subclasses
Instance Method Summary collapse
- #handle_response(response) ⇒ Object
-
#initialize(api_base, api_version, header) ⇒ BaseClient
constructor
A new instance of BaseClient.
Constructor Details
#initialize(api_base, api_version, header) ⇒ BaseClient
Returns a new instance of BaseClient.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/chatwork/base_client.rb', line 6 def initialize(api_base, api_version, header) default_header = { "User-Agent" => "ChatWork#{api_version} RubyBinding/#{ChatWork::VERSION}", } default_header.merge!(header) @conn = Faraday.new("#{api_base}#{api_version}", headers: default_header) do |builder| builder.request :url_encoded builder.response :mashify builder.response :json builder.adapter Faraday.default_adapter end @api_version = api_version end |
Instance Method Details
#handle_response(response) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/chatwork/base_client.rb', line 22 def handle_response(response) case response.status when 200..299 response.body else raise ChatWork::ChatWorkError.from_response(response.status, response.body, response.headers) end end |