Class: Hubspot::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/hubspot/collection.rb

Direct Known Subclasses

PagedCollection

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}, &block) ⇒ Collection

Returns a new instance of Collection.



2
3
4
5
6
# File 'lib/hubspot/collection.rb', line 2

def initialize(opts = {}, &block)
  @options = opts
  @fetch_proc = block
  fetch
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (protected)



38
39
40
# File 'lib/hubspot/collection.rb', line 38

def method_missing(method, *args, &block)
  @resources.public_send(method, *args, &block)
end

Instance Method Details

#refreshObject



8
9
10
11
# File 'lib/hubspot/collection.rb', line 8

def refresh
  fetch
  self
end

#resourcesObject



13
14
15
# File 'lib/hubspot/collection.rb', line 13

def resources
  @resources
end

#update_all(opts = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hubspot/collection.rb', line 17

def update_all(opts = {})
  return true if empty?

  # This assumes that all resources are the same type
  resource_class = resources.first.class
  unless resource_class.respond_to?(:batch_update)
    raise "#{resource_class} does not support bulk update"
  end

  resource_class.batch_update(resources, opts)
end