Module: ZendeskAPI::Sideloading

Included in:
Collection, Read
Defined in:
lib/zendesk_api/sideloading.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
# File 'lib/zendesk_api/sideloading.rb', line 4

def self.included(klass)
  klass.send(:attr_reader, :included)
end

Instance Method Details

#set_includes(resource_or_resources, includes, body) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/zendesk_api/sideloading.rb', line 8

def set_includes(resource_or_resources, includes, body)
  @included = {}

  includes.each do |side_load|
    unless body.key?(side_load.to_s)
      @client.config.logger.warn "Missing #{side_load} key in response -- cannot side load"
    end
  end

  resources = to_array(resource_or_resources)
  resource_class = resources.first.class

  return if resources.empty?

  body.keys.each do |name|
    @included[name] = body[name]
    _side_load(name, resource_class, resources)
  end
end