Class: FacebookAds::ServerSide::EventRequest
- Inherits:
-
Object
- Object
- FacebookAds::ServerSide::EventRequest
- Defined in:
- lib/facebook_ads/ad_objects/server_side/event_request.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#events ⇒ Object
An array of Server Event objects.
-
#http_service_client ⇒ Object
The HttpServiceInterface client to use for executing the request.
-
#namespace_id ⇒ Object
Scope used to resolve extern_id or Third-party ID.
-
#partner_agent ⇒ Object
Platform from which the event is sent e.g.
-
#pixel_id ⇒ Object
Ad pixel id.
-
#test_event_code ⇒ Object
Code used to verify that your server events are received correctly by Facebook.
-
#upload_id ⇒ Object
Unique id used to denote the current set being uploaded.
-
#upload_source ⇒ Object
The origin/source of data for the dataset to be uploaded.
-
#upload_tag ⇒ Object
Tag string added to track your Offline event uploads.
Instance Method Summary collapse
-
#==(o) ⇒ Object
Checks equality by comparing each attribute.
-
#build(attributes = {}) ⇒ Object
build the object using the input hash.
- #eql?(o) ⇒ Boolean
-
#execute ⇒ Object
Execute request.
- #execute_with_client(http_client) ⇒ Object
- #get_params ⇒ Object
-
#hash ⇒ Fixnum
Calculates hash code according to all attributes.
-
#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, http_service_client: nil) ⇒ EventRequest
constructor
A new instance of EventRequest.
-
#list_invalid_properties ⇒ Object
Show invalid properties with the reasons.
- #normalize ⇒ Object
- #to_s ⇒ Object
-
#valid? ⇒ Boolean
Check to see if the all the properties in the model are valid.
Constructor Details
#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, http_service_client: nil) ⇒ EventRequest
Returns a new instance of EventRequest.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 66 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, http_service_client: nil) unless pixel_id.nil? self.pixel_id = pixel_id end unless events.nil? self.events = events end unless test_event_code.nil? self.test_event_code = test_event_code end unless partner_agent.nil? self.partner_agent = partner_agent end unless namespace_id.nil? self.namespace_id = namespace_id end unless upload_id.nil? self.upload_id = upload_id end unless upload_tag.nil? self.upload_tag = upload_tag end unless upload_source.nil? self.upload_source = upload_source end unless http_service_client.nil? self.http_service_client = http_service_client end end |
Instance Attribute Details
#events ⇒ Object
An array of Server Event objects
28 29 30 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 28 def events @events end |
#http_service_client ⇒ Object
The HttpServiceInterface client to use for executing the request.
55 56 57 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 55 def http_service_client @http_service_client end |
#namespace_id ⇒ Object
Scope used to resolve extern_id or Third-party ID. Can be another data set or data partner ID.
43 44 45 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 43 def namespace_id @namespace_id end |
#partner_agent ⇒ Object
Platform from which the event is sent e.g. wordpress
40 41 42 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 40 def partner_agent @partner_agent end |
#pixel_id ⇒ Object
Ad pixel id
37 38 39 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 37 def pixel_id @pixel_id end |
#test_event_code ⇒ Object
Code used to verify that your server events are received correctly by Facebook. Use this code to test your server events in the Test Events feature in Events Manager. See Test Events Tool (developers.facebook.com/docs/marketing-api/facebook-pixel/server-side-api/using-the-api#testEvents) for an example.
34 35 36 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 34 def test_event_code @test_event_code end |
#upload_id ⇒ Object
Unique id used to denote the current set being uploaded.
46 47 48 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 46 def upload_id @upload_id end |
#upload_source ⇒ Object
The origin/source of data for the dataset to be uploaded.
52 53 54 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 52 def upload_source @upload_source end |
#upload_tag ⇒ Object
Tag string added to track your Offline event uploads.
49 50 51 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 49 def upload_tag @upload_tag end |
Instance Method Details
#==(o) ⇒ Object
Checks equality by comparing each attribute.
231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 231 def ==(o) return true if self.equal?(o) self.class == o.class && pixel_id == o.pixel_id && events == o.events && test_event_code == o.test_event_code && partner_agent == o.partner_agent && namespace_id == o.namespace_id && upload_id == o.upload_id && upload_tag == o.upload_tag && upload_source == o.upload_source && http_service_client == o.http_service_client end |
#build(attributes = {}) ⇒ Object
build the object using the input hash
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 100 def build(attributes = {}) return unless attributes.is_a?(Hash) # convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } if attributes.has_key?(:'pixel_id') self.pixel_id = attributes[:'pixel_id'] end if attributes.has_key?(:'events') if (value = attributes[:'events']).is_a?(Array) self.events = value end end if attributes.has_key?(:'test_event_code') self.test_event_code = attributes[:'test_event_code'] end if attributes.has_key?(:'partner_agent') self.partner_agent = attributes[:'partner_agent'] end if attributes.has_key?(:'namespace_id') self.namespace_id = attributes[:'namespace_id'] end if attributes.has_key?(:'upload_id') self.upload_id = attributes[:'upload_id'] end if attributes.has_key?(:'upload_tag') self.upload_tag = attributes[:'upload_tag'] end if attributes.has_key?(:'upload_source') self.upload_source = attributes[:'upload_source'] end if attributes.has_key?(:'http_service_client') self.http_service_client = attributes[:'http_service_client'] end end |
#eql?(o) ⇒ Boolean
246 247 248 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 246 def eql?(o) self == o end |
#execute ⇒ Object
Execute request
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 146 def execute unless valid? raise list_invalid_properties end if http_service_client return execute_with_client(http_service_client) end params = get_params() params[:data] = normalize ads_pixel = FacebookAds::AdsPixel.get(pixel_id) response = ads_pixel.events.create(params) json_response_object = JSON.parse(JSON.generate(response), object_class: OpenStruct) FacebookAds::ServerSide::EventResponse.new( events_received: json_response_object.events_received, messages: json_response_object., fbtrace_id: json_response_object.fbtrace_id ) end |
#execute_with_client(http_client) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 185 def execute_with_client http_client url = [ "https://#{FacebookAds::DEFAULT_HOST}", FacebookAds::DEFAULT_API_VERSION, pixel_id, 'events', ].join('/') headers = { 'User-Agent' => "fbbizsdk-ruby-v#{FacebookAds::VERSION}" } params = get_params params[:data] = events.map(&:normalize) appsecret = FacebookAds.config.app_secret access_token = FacebookAds.config.access_token params[:access_token] = access_token if appsecret params[:appsecret_proof] = FacebookAds::ServerSide::HttpUtil.appsecret_proof(appsecret, access_token) end http_client.execute( url, FacebookAds::ServerSide::HttpMethod::POST, headers, params ) end |
#get_params ⇒ Object
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 174 def get_params params = {} params[:test_event_code] = test_event_code unless test_event_code.nil? params[:partner_agent] = partner_agent unless partner_agent.nil? params[:namespace_id] = namespace_id unless namespace_id.nil? params[:upload_id] = upload_id unless upload_id.nil? params[:upload_tag] = upload_tag unless upload_tag.nil? params[:upload_source] = upload_source unless upload_source.nil? params end |
#hash ⇒ Fixnum
Calculates hash code according to all attributes.
252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 252 def hash [ pixel_id, events, test_event_code, partner_agent, namespace_id, upload_id, upload_tag, upload_source, http_service_client, ].hash end |
#list_invalid_properties ⇒ Object
Show invalid properties with the reasons. Usually used together with valid?
214 215 216 217 218 219 220 221 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 214 def list_invalid_properties invalid_properties = Array.new if @events.nil? invalid_properties.push('invalid value for "data", data cannot be nil.') end invalid_properties end |
#normalize ⇒ Object
166 167 168 169 170 171 172 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 166 def normalize normalized_events = [] events.each do |event| normalized_events.push(JSON.generate(event.normalize)) end normalized_events end |
#to_s ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 266 def to_s hash = {} unless pixel_id.nil? hash['pixel_id'] = pixel_id end unless events.nil? hash['data'] = events end unless test_event_code.nil? hash['test_event_code'] = test_event_code end unless partner_agent.nil? hash['partner_agent'] = partner_agent end unless namespace_id.nil? hash['namespace_id'] = namespace_id end unless upload_id.nil? hash['upload_id'] = upload_id end unless upload_tag.nil? hash['upload_tag'] = upload_tag end unless upload_source.nil? hash['upload_source'] = upload_source end hash.to_s end |
#valid? ⇒ Boolean
Check to see if the all the properties in the model are valid
225 226 227 228 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 225 def valid? return false if @events.nil? true end |