Class: SmartHR::Client

Defined Under Namespace

Modules: BankAccountSettingMethods, BizEstablishmentMethods, CrewCustomFieldTemplateGroupMethods, CrewCustomFieldTemplateMethods, CrewInputFormMethods, CrewMethods, DepartmentMethods, DependentMethods, DependentRelationMethods, EmploymentTypeMethods, JobTitleMethods, MailFormatMethods, PaymentPeriodMethods, UserMethods, WebhookMethods

Instance Method Summary collapse

Methods included from WebhookMethods

#create_webhook, #destroy_webhook, #find_webhook, #get_webhooks, #update_webhook

Methods included from UserMethods

#find_user, #get_users

Methods included from PaymentPeriodMethods

#find_payment_period, #get_payment_periods

Methods included from MailFormatMethods

#find_mail_format, #get_mail_formats

Methods included from JobTitleMethods

#create_job_title, #destroy_job_title, #find_job_title, #get_job_titles, #update_job_title

Methods included from EmploymentTypeMethods

#create_employment_type, #destroy_employment_type, #find_employment_type, #get_employment_types, #update_employment_type

Methods included from DependentRelationMethods

#get_dependent_relations

Methods included from DependentMethods

#create_crew_dependent, #destroy_crew_dependent, #find_crew_dependent, #get_crew_dependents, #update_crew_dependent

Methods included from DepartmentMethods

#create_department, #destroy_department, #find_department, #get_departments, #update_department

Methods included from CrewMethods

#create_crew, #destroy_crew, #destroy_crew_departments, #find_crew, #get_crews, #invite_crew, #update_crew

Methods included from CrewInputFormMethods

#find_crew_input_form, #get_crew_input_forms

Methods included from CrewCustomFieldTemplateMethods

#create_crew_custom_field_template, #destroy_crew_custom_field_template, #find_crew_custom_field_template, #get_crew_custom_field_templates, #update_crew_custom_field_template

Methods included from CrewCustomFieldTemplateGroupMethods

#create_crew_custom_field_template_group, #destroy_crew_custom_field_template_group, #find_crew_custom_field_template_group, #get_crew_custom_field_template_groups, #update_crew_custom_field_template_group

Methods included from BizEstablishmentMethods

#get_biz_establishments

Methods included from BankAccountSettingMethods

#get_bank_account_settings

Methods included from Converter

#hash_compact

Constructor Details

#initialize(tenant_id: nil, access_token: nil, sandbox: false, header: {}, api_version: 'v1') ⇒ Client

Returns a new instance of Client.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/smarthr/client.rb', line 39

def initialize(tenant_id: nil, access_token: nil, sandbox: false, header: {}, api_version: 'v1')
  raise unless tenant_id
  raise unless access_token

  url = sprintf(sandbox ? "https://%s.daruma.space/api/" : "https://%s.smarthr.jp/api/", tenant_id)
  header.merge!({
    "User-Agent" => "SmartHR/#{api_version} RubyBinding/#{SmartHR::VERSION}",
    "Authorization" => "Bearer #{access_token}"
  })

  @conn = Faraday.new(url, headers: 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



58
59
60
61
62
63
64
65
66
67
# File 'lib/smarthr/client.rb', line 58

def handle_response(response)
  case response.status
  when 200..299
    response.body
  else
    puts response.status
    puts response.body
    raise SmartHR::Error.from_response(response.status, response.body)
  end
end