class Breathe::Client

Constants

BASE_URL

Attributes

api_key[R]
last_response[R]

Public Class Methods

new(api_key:, auto_paginate: false) click to toggle source
# File lib/breathe/client.rb, line 7
def initialize(api_key:, auto_paginate: false)
  @api_key = api_key
  @auto_paginate = auto_paginate
end

Public Instance Methods

absences() click to toggle source
# File lib/breathe/client.rb, line 12
def absences
  @absences ||= Absences.new(self)
end
agent() click to toggle source
# File lib/breathe/client.rb, line 37
def agent
  Sawyer::Agent.new(BASE_URL, links_parser: Sawyer::LinkParsers::Simple.new) do |http|
    http.headers["Content-Type"] = "application/json"
    http.headers["X-Api-Key"] = api_key
  end
end
employee_training_courses() click to toggle source
# File lib/breathe/client.rb, line 24
def employee_training_courses
  @employee_training_courses ||= EmployeeTrainingCourses.new(self)
end
employees() click to toggle source
# File lib/breathe/client.rb, line 20
def employees
  @employees ||= Employees.new(self)
end
request(method:, path:, data: {}, options: {}) click to toggle source
# File lib/breathe/client.rb, line 44
def request(method:, path:, data: {}, options: {})
  @last_response = agent.call(method, path, data, options)
  @last_response
end
response(method:, path:, args: {}) click to toggle source
# File lib/breathe/client.rb, line 28
def response(method:, path:, args: {})
  response = request(method: method, path: path, options: {query: args})
  parsed_response = Response.new(response: response, type: path.split("/").first)

  if parsed_response.success?
    @auto_paginate ? auto_paginated_response(parsed_response) : parsed_response
  end
end
sicknesses() click to toggle source
# File lib/breathe/client.rb, line 16
def sicknesses
  @sicknesses ||= Sicknesses.new(self)
end

Private Instance Methods

auto_paginated_response(parsed_response) click to toggle source
# File lib/breathe/client.rb, line 51
def auto_paginated_response(parsed_response)
  pages = parsed_response

  while (next_page = parsed_response.next_page)
    break if next_page.nil?

    pages.concat(next_page.body)
    parsed_response = next_page
  end

  pages
end