Class: FacebookAds::AdTargeting
- Inherits:
-
Object
- Object
- FacebookAds::AdTargeting
- Defined in:
- lib/facebook_ads/ad_targeting.rb
Overview
Constant Summary collapse
- MEN =
1
- WOMEN =
2
- GENDERS =
[MEN, WOMEN].freeze
- ANDROID_OS =
'Android'
- APPLE_OS =
'iOS'
- OSES =
[ANDROID_OS, APPLE_OS].freeze
- ANDROID_DEVICES =
%w[Android_Smartphone Android_Tablet].freeze
- APPLE_DEVICES =
%w[iPhone iPad iPod].freeze
- DEVICES =
ANDROID_DEVICES + APPLE_DEVICES
- INSTALLED =
'installed'
- NOT_INSTALLED =
'not_installed'
- APP_INSTALL_STATES =
[INSTALLED, NOT_INSTALLED].freeze
Instance Attribute Summary collapse
-
#age_max ⇒ Object
Returns the value of attribute age_max.
-
#age_min ⇒ Object
Returns the value of attribute age_min.
-
#app_install_state ⇒ Object
Returns the value of attribute app_install_state.
-
#countries ⇒ Object
Returns the value of attribute countries.
-
#custom_locations ⇒ Object
Returns the value of attribute custom_locations.
-
#genders ⇒ Object
Returns the value of attribute genders.
-
#income ⇒ Object
Returns the value of attribute income.
-
#user_device ⇒ Object
Returns the value of attribute user_device.
-
#user_os ⇒ Object
Returns the value of attribute user_os.
Instance Method Summary collapse
- #geo_locations ⇒ Object
-
#initialize ⇒ AdTargeting
constructor
A new instance of AdTargeting.
- #to_hash ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ AdTargeting
Returns a new instance of AdTargeting.
21 22 23 24 25 26 27 28 29 |
# File 'lib/facebook_ads/ad_targeting.rb', line 21 def initialize # self.genders = [WOMEN] # If nil, defaults to all genders. # self.age_min = 18 # If nil, defaults to 18. # self.age_max = 65 # If nil, defaults to 65+. # self.user_os = [ANDROID_OS] # self.user_device = ANDROID_DEVICES # self.app_install_state = NOT_INSTALLED self.income = [] # An a rray of objects with 'id' and optional 'name' end |
Instance Attribute Details
#age_max ⇒ Object
Returns the value of attribute age_max.
19 20 21 |
# File 'lib/facebook_ads/ad_targeting.rb', line 19 def age_max @age_max end |
#age_min ⇒ Object
Returns the value of attribute age_min.
19 20 21 |
# File 'lib/facebook_ads/ad_targeting.rb', line 19 def age_min @age_min end |
#app_install_state ⇒ Object
Returns the value of attribute app_install_state.
19 20 21 |
# File 'lib/facebook_ads/ad_targeting.rb', line 19 def app_install_state @app_install_state end |
#countries ⇒ Object
Returns the value of attribute countries.
19 20 21 |
# File 'lib/facebook_ads/ad_targeting.rb', line 19 def countries @countries end |
#custom_locations ⇒ Object
Returns the value of attribute custom_locations.
19 20 21 |
# File 'lib/facebook_ads/ad_targeting.rb', line 19 def custom_locations @custom_locations end |
#genders ⇒ Object
Returns the value of attribute genders.
19 20 21 |
# File 'lib/facebook_ads/ad_targeting.rb', line 19 def genders @genders end |
#income ⇒ Object
Returns the value of attribute income.
19 20 21 |
# File 'lib/facebook_ads/ad_targeting.rb', line 19 def income @income end |
#user_device ⇒ Object
Returns the value of attribute user_device.
19 20 21 |
# File 'lib/facebook_ads/ad_targeting.rb', line 19 def user_device @user_device end |
#user_os ⇒ Object
Returns the value of attribute user_os.
19 20 21 |
# File 'lib/facebook_ads/ad_targeting.rb', line 19 def user_os @user_os end |
Instance Method Details
#geo_locations ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/facebook_ads/ad_targeting.rb', line 31 def geo_locations if custom_locations { custom_locations: custom_locations } elsif countries { countries: countries } else { countries: ['US'] } end end |
#to_hash ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/facebook_ads/ad_targeting.rb', line 59 def to_hash { genders: genders, age_min: age_min, age_max: age_max, geo_locations: geo_locations, user_os: user_os, user_device: user_device, app_install_state: app_install_state, income: income }.reject { |_k, v| v.nil? } end |
#validate! ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/facebook_ads/ad_targeting.rb', line 41 def validate! { gender: genders, countries: countries, user_os: user_os, user_device: user_device, custom_locations: custom_locations }.each_pair do |key, array| if !array.nil? && !array.is_a?(Array) raise Exception, "#{self.class.name}: #{key} must be an array" end end { genders: [genders, GENDERS], user_os: [user_os, OSES], user_device: [user_device, DEVICES] }.each_pair do |key, provided_and_acceptable| provided, acceptable = provided_and_acceptable if !provided.nil? && !(invalid = provided.detect { |value| !acceptable.include?(value) }).nil? raise Exception, "#{self.class.name}: #{invalid} is an invalid #{key}" end end true end |