Class: PipeDrive::OverallSourceBase

Inherits:
ResourceBase show all
Defined in:
lib/pipe_drive/overall_source_base.rb

Direct Known Subclasses

Pipeline, Stage

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ResourceBase

field_keys, find_by, pagination_list, resource_name

Methods inherited from Base

bulk_delete, create, delete, #delete, find_by_id, #initialize, #parameterize, parameterize, requester, #requester, search_and_setup_by, #update, update

Constructor Details

This class inherits a constructor from PipeDrive::Base

Class Method Details

.list(options = {}, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/pipe_drive/overall_source_base.rb', line 14

def list(options={}, &block)
  path = "/#{resource_name}s"
  resources = requester.http_get(path, options) do |result|
    result[:data].nil? ? [] : list_objects(result)
  end
  resources.each do |resource|
    yield resource
  end if block_given?
  resources
end

.search(type, opts) ⇒ Object

Raises:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pipe_drive/overall_source_base.rb', line 25

def search(type, opts)
  raise NotAllowSearchType.new(type) unless const_get('ALLOW_FOR_SEARCH_TERMS').include?(type)
  raise NotProvideAssignType.new(type) if opts[type].nil?
  allow_search_opts = const_get('ALLOW_FOR_ADDITION_SEARCH_OPTS') + [type]
  opts = opts.slice(*allow_search_opts)
  list.select do |resource|
    is_match = true
    opts.each_pair do |key, value|
      resource_value = resource.send(key)
      if resource_value.is_a?(String)
        (is_match = false) && break unless resource_value.include?(value)
      else
        (is_match = false) && break unless resource_value == value
      end
    end
    is_match
  end
end

Instance Method Details

#deals(start_from = 0, per_page = DEFAULT_PER_PAGE, options = {}, &block) ⇒ Object



4
5
6
7
8
9
# File 'lib/pipe_drive/overall_source_base.rb', line 4

def deals(start_from=0, per_page=DEFAULT_PER_PAGE, options={}, &block)
  path = "/#{resource_name}s/#{id}/deals"
  params = {start: start_from, limit: per_page}
  params.merge!(options)
  pagination(path, params, &block)
end