Method: ZendeskAPI::Data#initialize

Defined in:
lib/zendesk_api/resource.rb

#initialize(client, attributes = {}) ⇒ Data

Create a new resource instance.

Parameters:

  • client (Client)

    The client to use

  • attributes (Hash) (defaults to: {})

    The optional attributes that describe the resource



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/zendesk_api/resource.rb', line 64

def initialize(client, attributes = {})
  raise "Expected a Hash for attributes, got #{attributes.inspect}" unless attributes.is_a?(Hash)

  @association = attributes.delete(:association) || Association.new(:class => self.class)
  @global_params = attributes.delete(:global) || {}
  @client = client
  @attributes = ZendeskAPI::Trackie.new(attributes)

  if self.class.associations.none? { |a| a[:name] == self.class.singular_resource_name }
    ZendeskAPI::Client.check_deprecated_namespace_usage @attributes, self.class.singular_resource_name
  end

  @attributes.clear_changes unless new_record?
end