Class: Dotloop::Person

Inherits:
Object
  • Object
show all
Includes:
QueryParamHelpers
Defined in:
lib/dotloop/person.rb

Constant Summary

Constants included from QueryParamHelpers

QueryParamHelpers::BATCH_SIZE, QueryParamHelpers::MAX_LOOPS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Person

Returns a new instance of Person.



6
7
8
# File 'lib/dotloop/person.rb', line 6

def initialize(client:)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/dotloop/person.rb', line 4

def client
  @client
end

Instance Method Details

#all(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dotloop/person.rb', line 10

def all(options = {})
  persons = []
  url = '/person'
  (1..MAX_LOOPS).each do |i|
    options[:batch_number] = i
    current_person = @client.get(url, query_params(options)).map do |person_attrs|
      Dotloop::Models::Person.new(person_attrs)
    end
    persons += current_person
    break if current_person.size < BATCH_SIZE
  end
  persons
end

#find(person_id:) ⇒ Object



24
25
26
27
# File 'lib/dotloop/person.rb', line 24

def find(person_id:)
  person = @client.get("/person/#{person_id.to_i}").first
  Dotloop::Models::Person.new(person)
end