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.



4
5
6
7
8
# File 'lib/hubspot/collection.rb', line 4

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)



40
41
42
# File 'lib/hubspot/collection.rb', line 40

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

Instance Method Details

#refreshObject



10
11
12
13
# File 'lib/hubspot/collection.rb', line 10

def refresh
  fetch
  self
end

#resourcesObject



15
16
17
# File 'lib/hubspot/collection.rb', line 15

def resources
  @resources
end

#update_all(opts = {}) ⇒ Object



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

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