Class: ChatWork::BaseClient

Inherits:
Object
  • Object
show all
Includes:
Converter
Defined in:
lib/chatwork/base_client.rb

Direct Known Subclasses

Client, OAuthClient

Instance Method Summary collapse

Methods included from Converter

#boolean_to_integer

Constructor Details

#initialize(api_base:, api_version: "", header:) ⇒ BaseClient

Returns a new instance of BaseClient.

Parameters:

  • api_base (String)
  • api_version (String) (defaults to: "")
  • header (Hash<String,String>)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/chatwork/base_client.rb', line 8

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, headers: default_header) do |builder|
    builder.request :chatwork_multipart
    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



25
26
27
28
29
30
31
32
# File 'lib/chatwork/base_client.rb', line 25

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