Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow faraday configuration #205

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/facebook_ads/ad_objects/server_side/event_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class EventRequest
# The HttpServiceInterface client to use for executing the request.
attr_accessor :http_service_client

# AdObject Session
attr_accessor :session

# @param [String] pixel_id
# @param [Array(FacebookAds::ServerSide::Event)] events
# @param [String] test_event_code
Expand All @@ -69,7 +72,7 @@ class EventRequest
# @param [HttpServiceInterface] http_service_client
def initialize(pixel_id: nil, events: nil, test_event_code: nil, partner_agent: nil,
namespace_id: nil, upload_id: nil, upload_tag: nil, upload_source: nil,
access_token: nil, http_service_client: nil)
access_token: nil, http_service_client: nil, session: nil)
unless pixel_id.nil?
self.pixel_id = pixel_id
end
Expand Down Expand Up @@ -100,6 +103,9 @@ def initialize(pixel_id: nil, events: nil, test_event_code: nil, partner_agent:
unless http_service_client.nil?
self.http_service_client = http_service_client
end
unless session.nil?
self.session = session
end
end

# build the object using the input hash
Expand Down Expand Up @@ -160,7 +166,7 @@ def execute
end
params = get_params()
params[:data] = normalize
session = FacebookAds::Session.new(access_token: access_token) if access_token
session = self.session || (access_token ? FacebookAds::Session.new(access_token: access_token) : nil)
ads_pixel = FacebookAds::AdsPixel.get(pixel_id, session)
response = ads_pixel.events.create(params)
json_response_object = JSON.parse(JSON.generate(response), object_class: OpenStruct)
Expand Down
8 changes: 5 additions & 3 deletions lib/facebook_ads/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@

module FacebookAds
class Session
attr_accessor :access_token, :app_secret, :api_version, :server_host
attr_accessor :access_token, :app_secret, :api_version, :server_host, :connection_setup

def initialize(access_token: nil,
app_secret: nil,
server_host: FacebookAds.config.server_host,
api_version: FacebookAds.config.api_version)
api_version: FacebookAds.config.api_version,
&connection_setup)
@access_token = access_token
@app_secret = app_secret
@server_host = server_host
@api_version = api_version
@connection_setup = connection_setup
end

def request(method, path, params = nil)
Expand Down Expand Up @@ -52,7 +54,7 @@ def api_conn
# TODO Json Request
# TODO URL Encode - stringify json
faraday.request :url_encoded

@connection_setup&.call(faraday)
faraday.response :logger, Utils.logger, bodies: FacebookAds.config.log_api_bodies
faraday.adapter Faraday.default_adapter
end
Expand Down