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



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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 200

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?(:'user_os')
    if (value = attributes[:'user_os']).is_a?(Array)
      self.user_os = value
    end
  end

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

  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?(:'country_groups')
    if (value = attributes[:'country_groups']).is_a?(Array)
      self.country_groups = 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_maxObject

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



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

def age_max
  @age_max
end

#age_minObject

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.



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

def age_min
  @age_min
end

#audience_excludeObject

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



94
95
96
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 94

def audience_exclude
  @audience_exclude
end

#audience_includeObject

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 (the platformAudienceId from GET /v1/ads/audiences; Zernio resolves it to the targetable LinkedIn ad segment, an unknown id returns 400), Google user list ids, X custom audience ids). Not supported on OpenAI (400).



91
92
93
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 91

def audience_include
  @audience_include
end

#behaviorsObject

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



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

def behaviors
  @behaviors
end

#citiesObject

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).



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

def cities
  @cities
end

#company_sizesObject

LinkedIn B2B only. Single-letter size codes (A to I), or the full urn:li:staffCountRange:* URN from /v1/ads/targeting/search?dimension=companySize.



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

def company_sizes
  @company_sizes
end

#countriesObject

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



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

def countries
  @countries
end

#country_groupsObject

Meta only. Continents and trade blocs (geo_locations.country_groups), for targeting a whole region without listing its countries. Combines with countries rather than replacing it, and is also accepted under excludedLocations. Discoverable via GET /v1/ads/targeting/search?dimension=geo&geoType=country_group.



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

def country_groups
  @country_groups
end

#custom_locationsObject

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



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

def custom_locations
  @custom_locations
end

#excluded_locationsObject

Returns the value of attribute excluded_locations.



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

def excluded_locations
  @excluded_locations
end

#genderObject

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



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

def gender
  @gender
end

#income_tierObject

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).



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

def income_tier
  @income_tier
end

#industriesObject

LinkedIn B2B only. Industry URN id fragments, or the full urn:li:industry:* URN from /v1/ads/targeting/search?dimension=industry.



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

def industries
  @industries
end

#interestsObject

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



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

def interests
  @interests
end

#job_functionsObject

LinkedIn B2B only. Function URN id fragments, or the full urn:li:function:* URN from /v1/ads/targeting/search?dimension=jobFunction.



88
89
90
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 88

def job_functions
  @job_functions
end

#languagesObject

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.



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

def languages
  @languages
end

#metrosObject

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



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

def metros
  @metros
end

#regionsObject

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



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

def regions
  @regions
end

#senioritiesObject

LinkedIn B2B only. Seniority URN id fragments, or the full urn:li:seniority:* URN from /v1/ads/targeting/search?dimension=seniority.



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

def seniorities
  @seniorities
end

#user_deviceObject

Meta only. Device models such as iPhone. Emitted as user_device. May also be supplied inside targeting.



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

def user_device
  @user_device
end

#user_osObject

Meta only. Operating systems and version ranges, such as iOS_ver_14.0_and_above or Android. Emitted as user_os. May also be supplied inside targeting.



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

def user_os
  @user_os
end

#work_employersObject

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



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

def work_employers
  @work_employers
end

#work_industriesObject

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



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

def work_industries
  @work_industries
end

#work_positionsObject

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



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

def work_positions
  @work_positions
end

#zipsObject

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



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

def zips
  @zips
end

Class Method Details

.acceptable_attribute_mapObject

Returns attribute mapping this model knows about



151
152
153
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 151

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



156
157
158
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 156

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

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



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 119

def self.attribute_map
  {
    :'user_os' => :'userOs',
    :'user_device' => :'userDevice',
    :'countries' => :'countries',
    :'regions' => :'regions',
    :'cities' => :'cities',
    :'zips' => :'zips',
    :'metros' => :'metros',
    :'country_groups' => :'countryGroups',
    :'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



542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 542

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_nullableObject

List of attributes with nullable: true



193
194
195
196
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 193

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

.openapi_typesObject

Attribute type mapping.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 161

def self.openapi_types
  {
    :'user_os' => :'Array<String>',
    :'user_device' => :'Array<String>',
    :'countries' => :'Array<String>',
    :'regions' => :'Array<UpdateCampaignTargetingRequestTargetingLocationsOneOfRegionsInner>',
    :'cities' => :'Array<TargetingSpecCitiesInner>',
    :'zips' => :'Array<UpdateCampaignTargetingRequestTargetingLocationsOneOfRegionsInner>',
    :'metros' => :'Array<UpdateCampaignTargetingRequestTargetingLocationsOneOfRegionsInner>',
    :'country_groups' => :'Array<String>',
    :'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



496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 496

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      user_os == o.user_os &&
      user_device == o.user_device &&
      countries == o.countries &&
      regions == o.regions &&
      cities == o.cities &&
      zips == o.zips &&
      metros == o.metros &&
      country_groups == o.country_groups &&
      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


529
530
531
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 529

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



535
536
537
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 535

def hash
  [user_os, user_device, countries, regions, cities, zips, metros, country_groups, 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_propertiesObject

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

Returns:

  • Array for valid properties with the reasons



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 363

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  if !@user_os.nil? && @user_os.length < 1
    invalid_properties.push('invalid value for "user_os", number of items must be greater than or equal to 1.')
  end

  if !@user_device.nil? && @user_device.length < 1
    invalid_properties.push('invalid value for "user_device", number of items must be greater than or equal to 1.')
  end

  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_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 564

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



395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 395

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  return false if !@user_os.nil? && @user_os.length < 1
  return false if !@user_device.nil? && @user_device.length < 1
  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