Skip to content

Commit

Permalink
fix: AdReportRun can't retain id with post insights
Browse files Browse the repository at this point in the history
  • Loading branch information
mktktmr committed Aug 13, 2021
1 parent 5dcb7be commit 18fbad6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/facebook_ads/ad_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,24 @@ def initialize(attributes, *args)
raise InvalidParameterError, 'Invalid attributes. Must include at least one attribute'
end

update_attributes(attributes)
# assume object with only id in the attributes as not loaded

# is next arg a list of fields?
fields = (args[0].is_a?(Array) || args[0].is_a?(String)) ? args.shift : []
fields = fields.split(',') if fields.is_a?(String)
session = args.shift

if attributes.has_key? "report_run_id"
# NOTE: POST <AD_OBJECT>/insights return `report_run_id`.
# SEE: https://developers.facebook.com/docs/marketing-api/insights/best-practices/#asynchronous

attributes.merge!({ "id" => attributes["report_run_id"] })
attributes.delete("report_run_id")

fields.delete("report_run_id")
end

update_attributes(attributes)
# assume object with only id in the attributes as not loaded

self.__all_fields = fields + attributes.keys
self.session = session
end
Expand Down

0 comments on commit 18fbad6

Please sign in to comment.