Class: MarketoAPI::MObject::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/marketo_api/mobject.rb

Overview

:nodoc:

Constant Summary collapse

TYPES =

:nodoc:

[ #:nodoc:
  :Lead, :Company, :Opportunity
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, options = {}) ⇒ Association

Returns a new instance of Association.



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/marketo_api/mobject.rb', line 233

def initialize(type, options = {})
  unless TYPES.include?(type.to_s.capitalize.to_sym)
    raise ArgumentError, "Invalid type #{type}"
  end

  @type = TYPES[TYPES.index(type.to_s.capitalize.to_sym)]

  options.fetch(:id) {
    options.fetch(:external) {
      options.fetch(:external_key) {
        raise KeyError, "Must have one of :id or :external"
      }
    }
  }

  @id = options[:id]
  @external_key = options[:external] || options[:external_key]
end

Instance Attribute Details

#external_keyObject (readonly) Also known as: external

Returns the value of attribute external_key.



230
231
232
# File 'lib/marketo_api/mobject.rb', line 230

def external_key
  @external_key
end

#idObject (readonly)

Returns the value of attribute id.



230
231
232
# File 'lib/marketo_api/mobject.rb', line 230

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



230
231
232
# File 'lib/marketo_api/mobject.rb', line 230

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



252
253
254
255
# File 'lib/marketo_api/mobject.rb', line 252

def ==(other)
  type.equal?(other.type) && id == other.id &&
    external_key == other.external_key
end

#to_hObject



257
258
259
260
261
262
263
# File 'lib/marketo_api/mobject.rb', line 257

def to_h
  {
    mObjType:    type,
    id:          id,
    externalKey: external_key,
  }
end