Class: Zernio::TargetingSpec

Inherits:
ApiModelBase show all
Defined in:
lib/zernio-sdk/models/targeting_spec.rb

Overview

Normalized, platform-agnostic ad-targeting spec. Every field is optional, an empty object targets the platform's default broadest audience. Field names are camelCase and identical across POST /v1/ads/create (the targeting object), POST /v1/ads/targeting/reach-estimate, and saved_targeting audiences, so a spec resolved once can be reused verbatim. Entity ids (regions[].key, cities[].key, zips[].key, metros[].key, interests[].id, behaviors[].id) are the platform's opaque identifiers resolved via GET /v1/ads/targeting/search. A spec is therefore meaningful only for the platform it was built against, except the portable fields (countries, ageMin/ageMax, gender, incomeTier, languages) which carry across platforms. Fields a platform cannot honour are rejected at create time with INVALID_FIELD_VALUE naming the offending field (not silently dropped).

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiModelBase

_deserialize, #_to_hash, #to_body, #to_s

Constructor Details

#initialize(attributes = {}) ⇒ TargetingSpec

Initializes the object

Parameters:

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

    Model attributes in the form of hash



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 185

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `Zernio::TargetingSpec` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  acceptable_attribute_map = self.class.acceptable_attribute_map
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!acceptable_attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `Zernio::TargetingSpec`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'countries')
    if (value = attributes[:'countries']).is_a?(Array)
      self.countries = value
    end
  end

  if attributes.key?(:'regions')
    if (value = attributes[:'regions']).is_a?(Array)
      self.regions = value
    end
  end

  if attributes.key?(:'cities')
    if (value = attributes[:'cities']).is_a?(Array)
      self.cities = value
    end
  end

  if attributes.key?(:'zips')
    if (value = attributes[:'zips']).is_a?(Array)
      self.zips = value
    end
  end

  if attributes.key?(:'metros')
    if (value = attributes[:'metros']).is_a?(Array)
      self.metros = value
    end
  end

  if attributes.key?(:'custom_locations')
    if (value = attributes[:'custom_locations']).is_a?(Array)
      self.custom_locations = value
    end
  end

  if attributes.key?(:'excluded_locations')
    self.excluded_locations = attributes[:'excluded_locations']
  end

  if attributes.key?(:'age_min')
    self.age_min = attributes[:'age_min']
  end

  if attributes.key?(:'age_max')
    self.age_max = attributes[:'age_max']
  end

  if attributes.key?(:'gender')
    self.gender = attributes[:'gender']
  end

  if attributes.key?(:'income_tier')
    self.income_tier = attributes[:'income_tier']
  end

  if attributes.key?(:'languages')
    if (value = attributes[:'languages']).is_a?(Array)
      self.languages = value
    end
  end

  if attributes.key?(:'interests')
    if (value = attributes[:'interests']).is_a?(Array)
      self.interests = value
    end
  end

  if attributes.key?(:'behaviors')
    if (value = attributes[:'behaviors']).is_a?(Array)
      self.behaviors = value
    end
  end

  if attributes.key?(:'work_positions')
    if (value = attributes[:'work_positions']).is_a?(Array)
      self.work_positions = value
    end
  end

  if attributes.key?(:'work_employers')
    if (value = attributes[:'work_employers']).is_a?(Array)
      self.work_employers = value
    end
  end

  if attributes.key?(:'work_industries')
    if (value = attributes[:'work_industries']).is_a?(Array)
      self.work_industries = value
    end
  end

  if attributes.key?(:'industries')
    if (value = attributes[:'industries']).is_a?(Array)
      self.industries = value
    end
  end

  if attributes.key?(:'company_sizes')
    if (value = attributes[:'company_sizes']).is_a?(Array)
      self.company_sizes = value
    end
  end

  if attributes.key?(:'seniorities')
    if (value = attributes[:'seniorities']).is_a?(Array)
      self.seniorities = value
    end
  end

  if attributes.key?(:'job_functions')
    if (value = attributes[:'job_functions']).is_a?(Array)
      self.job_functions = value
    end
  end

  if attributes.key?(:'audience_include')
    if (value = attributes[:'audience_include']).is_a?(Array)
      self.audience_include = value
    end
  end

  if attributes.key?(:'audience_exclude')
    if (value = attributes[:'audience_exclude']).is_a?(Array)
      self.audience_exclude = value
    end
  end
end

Instance Attribute Details

#age_max ⇒ Object

Maximum age. Same per-platform application and clamping as ageMin.



43
44
45
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 43

def age_max
  @age_max
end

#age_min ⇒ Object

Minimum age. Applied on Meta, TikTok and Pinterest; ignored on Google, LinkedIn and X. Each platform clamps to its own range: Meta and Pinterest effectively cap at 65 (65 = 65+), TikTok maps up to 100. Pinterest has no under-18 bucket, so an ageMin below 18 starts at 18 there.



40
41
42
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 40

def age_min
  @age_min
end

#audience_exclude ⇒ Object

Platform audience IDs to exclude; same ID formats as audienceInclude. Not supported on OpenAI (400).



85
86
87
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 85

def audience_exclude
  @audience_exclude
end

#audience_include ⇒ Object

Platform audience IDs to include, as returned by GET /v1/ads/audiences (Meta custom audience ids, TikTok audience ids, Pinterest customer list ids, LinkedIn segment ids (bare, urn:li:adSegment or urn:li:dmpSegment forms accepted), Google user list ids, X custom audience ids). Not supported on OpenAI (400).



82
83
84
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 82

def audience_include
  @audience_include
end

#behaviors ⇒ Object

Behaviour entities from /v1/ads/targeting/search?dimension=behavior. Supported on Meta and TikTok.



58
59
60
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 58

def behaviors
  @behaviors
end

#cities ⇒ Object

City targeting. Optional radius + distanceUnit extend beyond the city limits; both must be set together or both omitted. radius is only honoured on platforms whose capability map allows city radius (Meta).



26
27
28
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 26

def cities
  @cities
end

#company_sizes ⇒ Object

LinkedIn B2B only.



73
74
75
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 73

def company_sizes
  @company_sizes
end

#countries ⇒ Object

ISO 3166-1 alpha-2 country codes (e.g. ['US']).



20
21
22
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 20

def countries
  @countries
end

#custom_locations ⇒ Object

Point-radius (lat/lng) targeting (Meta custom_locations / Google proximity). Honoured on Meta and Google; ignored on platforms without radius support.



35
36
37
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 35

def custom_locations
  @custom_locations
end

#excluded_locations ⇒ Object

Returns the value of attribute excluded_locations.



37
38
39
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 37

def excluded_locations
  @excluded_locations
end

#gender ⇒ Object

Restrict by gender. 'all' (default) targets everyone. Applied on Meta, TikTok and Pinterest. Ignored on Google, LinkedIn and X.



46
47
48
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 46

def gender
  @gender
end

#income_tier ⇒ Object

Normalized household-income tier (ZIP/percentile based). Meta and TikTok express all four. Google maps only top_10 (its INCOME_RANGE_90_UP); other tiers on Google, and any income tier on LinkedIn / X / Pinterest, are rejected. On Meta, income/zip targeting requires the relevant specialAdCategories to be unset (housing/employment/credit ads cannot use it).



49
50
51
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 49

def income_tier
  @income_tier
end

#industries ⇒ Object

LinkedIn B2B only. Industry URN id fragments.



70
71
72
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 70

def industries
  @industries
end

#interests ⇒ Object

Interest entities from /v1/ads/targeting/search?dimension=interest. Each carries the platform's opaque id.



55
56
57
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 55

def interests
  @interests
end

#job_functions ⇒ Object

LinkedIn B2B only.



79
80
81
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 79

def job_functions
  @job_functions
end

#languages ⇒ Object

Language codes restricting the audience by language. On Meta, ISO 639-1 codes (e.g. ['en']); a bare code targets all regional variants ("en" = all English), or use a region-qualified code ("en_GB", "pt_BR") for a specific one. Unknown codes are rejected.



52
53
54
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 52

def languages
  @languages
end

#metros ⇒ Object

DMA / metro-area targeting. key is the platform's metro ID (e.g. Meta DMA:807).



32
33
34
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 32

def metros
  @metros
end

#regions ⇒ Object

Region/state targeting. key is the platform location ID from /v1/ads/targeting/search?dimension=geo&geoType=region.



23
24
25
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 23

def regions
  @regions
end

#seniorities ⇒ Object

LinkedIn B2B only.



76
77
78
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 76

def seniorities
  @seniorities
end

#work_employers ⇒ Object

Meta only. Employer entities from /v1/ads/targeting/search?dimension=workEmployer.



64
65
66
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 64

def work_employers
  @work_employers
end

#work_industries ⇒ Object

Meta only. Work-industry entities from /v1/ads/targeting/search?dimension=workIndustry. Not interchangeable with the LinkedIn industries URN fragments.



67
68
69
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 67

def work_industries
  @work_industries
end

#work_positions ⇒ Object

Meta only. Job title entities from /v1/ads/targeting/search?dimension=workPosition. Not interchangeable with the LinkedIn jobTitles URN fragments.



61
62
63
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 61

def work_positions
  @work_positions
end

#zips ⇒ Object

Postal/ZIP targeting. key is the platform's postal location ID (e.g. Meta US:94304). Supported on Meta, Google, TikTok, Pinterest, X.



29
30
31
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 29

def zips
  @zips
end

Class Method Details

.acceptable_attribute_map ⇒ Object

Returns attribute mapping this model knows about



139
140
141
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 139

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributes ⇒ Object

Returns all the JSON keys this model knows about



144
145
146
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 144

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_map ⇒ Object

Attribute mapping from ruby-style variable name to JSON key.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 110

def self.attribute_map
  {
    :'countries' => :'countries',
    :'regions' => :'regions',
    :'cities' => :'cities',
    :'zips' => :'zips',
    :'metros' => :'metros',
    :'custom_locations' => :'customLocations',
    :'excluded_locations' => :'excludedLocations',
    :'age_min' => :'ageMin',
    :'age_max' => :'ageMax',
    :'gender' => :'gender',
    :'income_tier' => :'incomeTier',
    :'languages' => :'languages',
    :'interests' => :'interests',
    :'behaviors' => :'behaviors',
    :'work_positions' => :'workPositions',
    :'work_employers' => :'workEmployers',
    :'work_industries' => :'workIndustries',
    :'industries' => :'industries',
    :'company_sizes' => :'companySizes',
    :'seniorities' => :'seniorities',
    :'job_functions' => :'jobFunctions',
    :'audience_include' => :'audienceInclude',
    :'audience_exclude' => :'audienceExclude'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash) —

    Model attributes in the form of hash

Returns:

  • (Object) —

    Returns the model itself



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 468

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullable ⇒ Object

List of attributes with nullable: true



178
179
180
181
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 178

def self.openapi_nullable
  Set.new([
  ])
end

.openapi_types ⇒ Object

Attribute type mapping.



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 149

def self.openapi_types
  {
    :'countries' => :'Array<String>',
    :'regions' => :'Array<UpdateCampaignTargetingRequestTargetingLocationsOneOfRegionsInner>',
    :'cities' => :'Array<TargetingSpecCitiesInner>',
    :'zips' => :'Array<UpdateCampaignTargetingRequestTargetingLocationsOneOfRegionsInner>',
    :'metros' => :'Array<UpdateCampaignTargetingRequestTargetingLocationsOneOfRegionsInner>',
    :'custom_locations' => :'Array<TargetingSpecCustomLocationsInner>',
    :'excluded_locations' => :'TargetingSpecExcludedLocations',
    :'age_min' => :'Integer',
    :'age_max' => :'Integer',
    :'gender' => :'String',
    :'income_tier' => :'String',
    :'languages' => :'Array<String>',
    :'interests' => :'Array<CreateStandaloneAdRequestBehaviorsInner>',
    :'behaviors' => :'Array<CreateStandaloneAdRequestBehaviorsInner>',
    :'work_positions' => :'Array<CreateStandaloneAdRequestBehaviorsInner>',
    :'work_employers' => :'Array<CreateStandaloneAdRequestBehaviorsInner>',
    :'work_industries' => :'Array<CreateStandaloneAdRequestBehaviorsInner>',
    :'industries' => :'Array<String>',
    :'company_sizes' => :'Array<String>',
    :'seniorities' => :'Array<String>',
    :'job_functions' => :'Array<String>',
    :'audience_include' => :'Array<String>',
    :'audience_exclude' => :'Array<String>'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object) —

    to be compared



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 425

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      countries == o.countries &&
      regions == o.regions &&
      cities == o.cities &&
      zips == o.zips &&
      metros == o.metros &&
      custom_locations == o.custom_locations &&
      excluded_locations == o.excluded_locations &&
      age_min == o.age_min &&
      age_max == o.age_max &&
      gender == o.gender &&
      income_tier == o.income_tier &&
      languages == o.languages &&
      interests == o.interests &&
      behaviors == o.behaviors &&
      work_positions == o.work_positions &&
      work_employers == o.work_employers &&
      work_industries == o.work_industries &&
      industries == o.industries &&
      company_sizes == o.company_sizes &&
      seniorities == o.seniorities &&
      job_functions == o.job_functions &&
      audience_include == o.audience_include &&
      audience_exclude == o.audience_exclude
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object) —

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


455
456
457
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 455

def eql?(o)
  self == o
end

#hash ⇒ Integer

Calculates hash code according to all attributes.

Returns:

  • (Integer) —

    Hash code



461
462
463
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 461

def hash
  [countries, regions, cities, zips, metros, custom_locations, excluded_locations, age_min, age_max, gender, income_tier, languages, interests, behaviors, work_positions, work_employers, work_industries, industries, company_sizes, seniorities, job_functions, audience_include, audience_exclude].hash
end

#list_invalid_properties ⇒ Object

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 330

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  if !@age_min.nil? && @age_min > 100
    invalid_properties.push('invalid value for "age_min", must be smaller than or equal to 100.')
  end

  if !@age_min.nil? && @age_min < 13
    invalid_properties.push('invalid value for "age_min", must be greater than or equal to 13.')
  end

  if !@age_max.nil? && @age_max > 100
    invalid_properties.push('invalid value for "age_max", must be smaller than or equal to 100.')
  end

  if !@age_max.nil? && @age_max < 13
    invalid_properties.push('invalid value for "age_max", must be greater than or equal to 13.')
  end

  invalid_properties
end

#to_hash ⇒ Hash

Returns the object in the form of hash

Returns:

  • (Hash) —

    Returns the object in the form of hash



490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 490

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#valid? ⇒ Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean) —

    true if the model is valid



354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 354

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  return false if !@age_min.nil? && @age_min > 100
  return false if !@age_min.nil? && @age_min < 13
  return false if !@age_max.nil? && @age_max > 100
  return false if !@age_max.nil? && @age_max < 13
  gender_validator = EnumAttributeValidator.new('String', ["all", "male", "female"])
  return false unless gender_validator.valid?(@gender)
  income_tier_validator = EnumAttributeValidator.new('String', ["top_5", "top_10", "top_10_25", "top_25_50"])
  return false unless income_tier_validator.valid?(@income_tier)
  true
end