Module: ZohoCrm::Enumerable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Record::ListService, Record::SearchService
- Defined in:
- lib/zoho_crm/concerns/enumerable.rb
Instance Method Summary collapse
- #call ⇒ Object
- #each ⇒ Object
- #initialize(path:, list_key:, facade_klass:, page: 1, per_page: Float::INFINITY) ⇒ Object
Instance Method Details
#call ⇒ Object
23 24 25 |
# File 'lib/zoho_crm/concerns/enumerable.rb', line 23 def call self end |
#each ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zoho_crm/concerns/enumerable.rb', line 27 def each return to_enum(:each) unless block_given? return if invalid? total = 0 catch :list_end do loop do @response = connection.get(path, params) validate(:response) unless success? raise exception_for(response, errors) if bang? throw :list_end end throw :list_end unless response.body response.body[list_key].each do |hash| yield facade_klass.new(hash) total += 1 throw :list_end if total >= per_page end break unless response.body.dig('info', 'more_records') @_params[:page] = response.body.dig('info', 'page') + 1 end end end |
#initialize(path:, list_key:, facade_klass:, page: 1, per_page: Float::INFINITY) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/zoho_crm/concerns/enumerable.rb', line 15 def initialize(path:, list_key:, facade_klass:, page: 1, per_page: Float::INFINITY) @path = path @list_key = list_key @facade_klass = facade_klass @page = page @per_page = per_page end |