class Adparlor::Facebook::GraphApi::AdTargetingSearch
Public Class Methods
new(access_token)
click to toggle source
# File lib/adparlor/facebook/graph_api/ad_targeting_search.rb, line 7 def initialize(access_token) @access_token = access_token end
Public Instance Methods
path()
click to toggle source
# File lib/adparlor/facebook/graph_api/ad_targeting_search.rb, line 11 def path '/search' end
search(query, type, options = {})
click to toggle source
# File lib/adparlor/facebook/graph_api/ad_targeting_search.rb, line 15 def search(query, type, options = {}) type_param = type.respond_to?(:type_param) ? type.type_param : type.name.split('::').last.downcase params = { q: query, type: type_param, access_token: @access_token } params.merge!(type::OPTIONS) if type.const_defined?('OPTIONS') params.merge!(options) response = get(path, params) if response.body['data'].is_a?(Hash) obj = type.new keys = response.body['data'].keys keys.each do |key| vals = [] response.body['data'][key].each do |val| vals << parse_value(key, val.last) end obj.send("#{key}=".to_sym, vals) end obj else response.body['data'].map do |data| obj = type.new data.each do |k, v| obj.send("#{k}=".to_sym, v) end obj end end end
Private Instance Methods
parse_value(key, value)
click to toggle source
# File lib/adparlor/facebook/graph_api/ad_targeting_search.rb, line 45 def parse_value(key, value) case key when 'countries' obj = AdTargetingTypes::AdGeolocations::AdCountry.new when 'cities' obj = AdTargetingTypes::AdGeolocations::AdCity.new when 'regions' obj = AdTargetingTypes::AdGeolocations::AdRegion.new when 'zips' obj = AdTargetingTypes::AdGeolocations::AdZipCode.new else return value.to_s end value.each { |k, v| obj.send("#{k}=".to_sym, v) } obj end