Class: MarketoAPI::MObject
- Inherits:
-
Object
- Object
- MarketoAPI::MObject
- Defined in:
- lib/marketo_api/mobject.rb
Overview
A representation of Marketo object (MObject) records as well as key representations for getting, syncing, or deleting those records.
Defined Under Namespace
Classes: Association, Criteria
Constant Summary collapse
- DELETE_TYPES =
:nodoc:
MarketoAPI.freeze(:Opportunity, :OpportunityPersonRole)
- GET_TYPES =
:nodoc:
MarketoAPI.freeze(*DELETE_TYPES, :Program)
- DESCRIBE_TYPES =
:nodoc:
MarketoAPI.freeze(*DELETE_TYPES, :ActivityRecord, :LeadRecord )
- ALL_TYPES =
:nodoc:
MarketoAPI.freeze(*[ GET_TYPES, DESCRIBE_TYPES ].flatten.uniq)
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
Associated objects.
-
#attributes ⇒ Object
readonly
The detailed attributes of the Marketo object.
-
#id ⇒ Object
The ID of the Marketo object.
-
#stream_position ⇒ Object
The stream position for paged queries.
-
#type ⇒ Object
readonly
The type of Marketo object.
-
#types ⇒ Object
readonly
The detailed types of the Marketo object.
Class Method Summary collapse
-
.from_soap_hash(hash) ⇒ Object
Creates a new MObject from a SOAP response hash (from MObjects#get or MObjects#sync).
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#association(type, options = {}) ⇒ Object
Add association criteria for use with MarketoAPI::MObjects#get or MarketoAPI::MOBjects#sync (not yet implemented).
-
#criteria(name = nil, value = nil, comparison = nil) ⇒ Object
Adds query criteria for use with MarketoAPI::MObjects#get.
- #include_details ⇒ Object
-
#include_details=(value) ⇒ Object
:nodoc:.
-
#initialize(type, id = nil) {|_self| ... } ⇒ MObject
constructor
A new instance of MObject.
-
#params_for_delete ⇒ Object
:nodoc:.
-
#params_for_get ⇒ Object
:nodoc:.
Constructor Details
#initialize(type, id = nil) {|_self| ... } ⇒ MObject
Returns a new instance of MObject.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/marketo_api/mobject.rb', line 42 def initialize(type, id = nil) @type = ensure_valid_type!(type) @id = id @attributes = {} @criteria = [] @associations = [] @stream_position = nil @include_details = false @types = Hash.new { |h, k| h[k] = {} } yield self if block_given? end |
Instance Attribute Details
#associations ⇒ Object (readonly)
Associated objects.
28 29 30 |
# File 'lib/marketo_api/mobject.rb', line 28 def associations @associations end |
#attributes ⇒ Object (readonly)
The detailed attributes of the Marketo object.
38 39 40 |
# File 'lib/marketo_api/mobject.rb', line 38 def attributes @attributes end |
#id ⇒ Object
The ID of the Marketo object.
25 26 27 |
# File 'lib/marketo_api/mobject.rb', line 25 def id @id end |
#stream_position ⇒ Object
The stream position for paged queries.
30 31 32 |
# File 'lib/marketo_api/mobject.rb', line 30 def stream_position @stream_position end |
#type ⇒ Object (readonly)
The type of Marketo object. Will be one of:
-
Opportunity
-
OpportunityPersonRole
-
Program
-
ActivityRecord
-
LeadRecord
In general, only the first three can be interacted with through the SOAP API.
23 24 25 |
# File 'lib/marketo_api/mobject.rb', line 23 def type @type end |
#types ⇒ Object (readonly)
The detailed types of the Marketo object.
40 41 42 |
# File 'lib/marketo_api/mobject.rb', line 40 def types @types end |
Class Method Details
.from_soap_hash(hash) ⇒ Object
Creates a new MObject from a SOAP response hash (from MObjects#get or MObjects#sync).
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/marketo_api/mobject.rb', line 148 def from_soap_hash(hash) #:nodoc: new(hash[:type], hash[:id]) do |mobj| obj = hash[:attrib_list][:attrib] MarketoAPI.array(obj).each do |attrib| mobj.attributes[attrib[:name].to_sym] = attrib[:value] end obj = hash[:type_attrib_list][:type_attrib] MarketoAPI.array(obj).each do |type| MarketoAPI.array(type[:attr_list][:attrib]).each do |attrib| mobj.types[type[:attr_type].to_sym][attrib[:name].to_sym] = attrib[:value] end end end end |
Instance Method Details
#==(other) ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/marketo_api/mobject.rb', line 134 def ==(other) type == other.type && include_details == other.include_details && id == other.id && stream_position == other.stream_position && attributes == other.attributes && types == other.types && criteria == other.criteria && associations == other.associations end |
#association(type, options = {}) ⇒ Object
Add association criteria for use with MarketoAPI::MObjects#get or MarketoAPI::MOBjects#sync (not yet implemented).
Type type
must be one of Lead
, Company
, or Opportunity
. It must be accompanied with one of the following parameters:
- id
-
The Marketo ID of the associated object.
- external
-
The custom attribute value of the associated object. Can also be accessed as
external_key
.
110 111 112 113 |
# File 'lib/marketo_api/mobject.rb', line 110 def association(type, = {}) @associations << Association.new(type, ) @associations end |
#criteria(name = nil, value = nil, comparison = nil) ⇒ Object
Adds query criteria for use with MarketoAPI::MObjects#get.
Name
- Name
-
Name of the MObject
- Role
-
The role associated with an OpportunityPersonRole object
- Type
-
The type of an Opportunity object
- Stage
-
The stage of an Opportunity object
CRM Id: The CRM ID could refer to the ID of the
Salesforce campaign connected to a Marketo
program
- Created At
-
The date the MObject was created. Can be used with the comparisons EQ, NE, LT, LE, GT, and GE. Two “created dates” can be specified to create a date range.
- Updated At or Tag Type
-
(Only one can be specified) Can be used with the comparisons EQ, NE, LT, LE, GT, and GE. Two “updated dates” can be specified to create a date range.
Tag Value: (Only one can be specified) Workspace Name: (Only one can be specified) Workspace Id: (Only one can be specified) Include Archive: Applicable only with Program MObject. Set it to
true if you wish to include archived programs.
Comparison
- EQ
-
Equals
- NE
-
Not Equals
- LT
-
Less Than
- LE
-
Less Than or Equals
- GT
-
Greater Than
- GE
-
Greater Than or Equals
96 97 98 99 |
# File 'lib/marketo_api/mobject.rb', line 96 def criteria(name = nil, value = nil, comparison = nil) @criteria << Criteria.new(name, value, comparison) if name @criteria end |
#include_details ⇒ Object
54 55 56 |
# File 'lib/marketo_api/mobject.rb', line 54 def include_details @include_details end |
#include_details=(value) ⇒ Object
:nodoc:
58 59 60 |
# File 'lib/marketo_api/mobject.rb', line 58 def include_details=(value) #:nodoc: @include_details= !!value end |
#params_for_delete ⇒ Object
:nodoc:
115 116 117 118 119 |
# File 'lib/marketo_api/mobject.rb', line 115 def params_for_delete #:nodoc: ensure_valid_type!(type, DELETE_TYPES) raise ArgumentError, ":id cannot be nil" if id.nil? { type: type, id: id } end |
#params_for_get ⇒ Object
:nodoc:
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/marketo_api/mobject.rb', line 121 def params_for_get #:nodoc: ensure_valid_type!(type, GET_TYPES) { type: type, id: id, includeDetails: include_details, mObjCriteriaList: criteria.compact.uniq.map(&:to_h), mObjAssociationList: associations.compact.uniq.map(&:to_h), streamPosition: stream_position, externalKey: nil }.delete_if(&MarketoAPI::MINIMIZE_HASH) end |