facebook / facebook-ruby-business-sdk

Ruby SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
209 stars 160 forks source link

EventRequest Does Not Work if Using OJ.mimic_json #139

Open fiestacasey opened 3 years ago

fiestacasey commented 3 years ago

Which SDK version are you using?

What's the issue?

When using oj.mimic_json an FacebookAds::ServerSide::EventRequest raises an exception. The standard JSON library supports object_class and array_class when parsing JSON but OJ does not. Given the popularity of OJ I think that this gem should avoid using object_class. Here's the source that is raising the issue:

https://github.com/facebook/facebook-ruby-business-sdk/blob/8a49e6bc46ff825632a93cdfa9f0016f4825494b/lib/facebook_ads/ad_objects/server_side/event_request.rb#L158

Steps/Sample code to reproduce the issue

require 'facebookbusiness'
require 'oj_mimic_json'

# TODO: REPLACE WITH VALID ACCESS TOKEN AND PIXEL ID
access_token = 'TODO'
pixel_id = 'TODO'

FacebookAds.configure do |config|
  config.access_token = access_token
end

user_data = FacebookAds::ServerSide::UserData.new(
  email: 'casey@wantable.com'
)

custom_data = FacebookAds::ServerSide::CustomData.new(
  value: 100,
  currency: 'USD',
  content_name: 'Style Edit',
  content_ids: 'style-edit',
  content_type: 'product',
  order_id: '123456'
)

event = FacebookAds::ServerSide::Event.new(
  event_name: 'Purchase',
  action_source: 'website',
  event_id: '123456',
  event_time: Time.now.to_i,
  user_data: user_data,
  custom_data: custom_data
)

request = FacebookAds::ServerSide::EventRequest.new(
  pixel_id: pixel_id,
  events: [event]
)

print request.execute # where the exception is raised.

Observed Results:

This is raised:

ruby/gems/2.6.0/gems/facebookbusiness-0.10.0.0/lib/facebook_ads/ad_objects/server_side/event_request.rb:160:in `execute': undefined method `events_received' for #<Hash:0x00007fc1dc1dbc08> (NoMethodError)

Expected Results:

Execution without an exception

stale[bot] commented 2 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.