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



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 168

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?(:'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

Returns the value of attribute age_max.



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

def age_max
  @age_max
end

#age_minObject

Returns the value of attribute age_min.



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

def age_min
  @age_min
end

#audience_excludeObject

Platform audience IDs to exclude.



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

def audience_exclude
  @audience_exclude
end

#audience_includeObject

Platform audience IDs to include.



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

def audience_include
  @audience_include
end

#behaviorsObject

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



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

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



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

def cities
  @cities
end

#company_sizesObject

LinkedIn B2B only.



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

def company_sizes
  @company_sizes
end

#countriesObject

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_locationsObject

Point-radius (lat/lng) targeting (Meta custom_locations / Google proximity). Honoured only where the capability map allows radius (Meta).



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

def custom_locations
  @custom_locations
end

#excluded_locationsObject

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

#genderObject

Restrict by gender. 'all' (default) targets everyone.



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

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



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

def income_tier
  @income_tier
end

#industriesObject

LinkedIn B2B only. Industry URN id fragments.



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

def industries
  @industries
end

#interestsObject

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



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

def interests
  @interests
end

#job_functionsObject

LinkedIn B2B only.



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

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.



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

def languages
  @languages
end

#metrosObject

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

#regionsObject

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

#senioritiesObject

LinkedIn B2B only.



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

def seniorities
  @seniorities
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.



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

def zips
  @zips
end

Class Method Details

.acceptable_attribute_mapObject

Returns attribute mapping this model knows about



125
126
127
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 125

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



130
131
132
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 130

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

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



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 99

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',
    :'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



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

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



161
162
163
164
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 161

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

.openapi_typesObject

Attribute type mapping.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 135

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



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 390

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 &&
      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


417
418
419
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 417

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



423
424
425
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 423

def hash
  [countries, regions, cities, zips, metros, custom_locations, excluded_locations, age_min, age_max, gender, income_tier, languages, interests, behaviors, 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



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 295

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_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 452

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



319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/zernio-sdk/models/targeting_spec.rb', line 319

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