Class: Freee::Api::Taxes

Inherits:
Object
  • Object
show all
Defined in:
lib/freee/taxes/client.rb

Constant Summary collapse

PATH =

税区分取得用PATH

'/api/1/taxes/codes'

Instance Method Summary collapse

Constructor Details

#initializeTaxes

A new instance of HTTP Client.



11
12
13
14
15
16
17
# File 'lib/freee/taxes/client.rb', line 11

def initialize
  @client = Faraday.new(url: Parameter::SITE) do |faraday|
    faraday.request :json
    faraday.response :json, content_type: /\bjson$/
    faraday.adapter Faraday.default_adapter
  end
end

Instance Method Details

#get_tax_codes(access_token, params) ⇒ Hash

Parameters:

  • access_token (String)

    アクセストークン

  • params (Hash)

    新規作成用の取引先パラメータ

Returns:

  • (Hash)

    GETレスポンスの結果



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/freee/taxes/client.rb', line 24

def get_tax_codes(access_token, params)
  raise 'アクセストークンが設定されていません' if access_token.empty?
  raise '事業所IDが設定されていません' unless params.key?(:company_id)
  @client.authorization :Bearer, access_token
  response = @client.get do |req|
    req.url PATH
    req.body = params.to_json
  end
  case response.status
  when 401
    raise 'Unauthorized'
  end
  response
end