facebookbusiness 0.8.0.2 → 0.8.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ec2c3003233735a142a752de0bb91e4119fa931d94c5c10c5a769a9c97110d6
4
- data.tar.gz: 7e7094b3c29f41afbab98f3d5d7faf0bec900cae1642d1e39ee17cf19ba8e7d7
3
+ metadata.gz: 4a33ca32c8748ade89d079a80d94c8b4e6c02a547db4bff11c03e1a2a7979dbc
4
+ data.tar.gz: 6414909aacd097b547c3ed836eddff3ae622ef2f6d31a5822d35f4d27201101d
5
5
  SHA512:
6
- metadata.gz: dd97d6ee27e4dea44ab8db1c47a5949b9429e0d67ad51517a20729851050f03ee66f1b35ef80fc1729991dd2cb0cb347aaae28f764be36c0893e014918939db0
7
- data.tar.gz: fb4e4a25f44130e2e61b5203ab248da4412c846e59912e736024eff096d8c57bae553423c5e2bccf15a0688d9a3503db1dedd0b2d43ad9ab08e9beb53ca8e4d9
6
+ metadata.gz: 1d1164b46627d07f5cd9ad5e70815a4617e31fcd5eea8cf80d54f655557ec9ce976550779f63f305f8d148e60cf179610ebe07cc7d2ff214f6dbb85755ebaa01
7
+ data.tar.gz: ee85a21d581897a5eb06001f0d654242d7b019ffef05870800ca750dcc730c4d3b4b4c075f7eac3a63a00c6f6d87aba9ea2286d9b1dd99be4d7cfe0d16212803
@@ -0,0 +1,73 @@
1
+ # Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
2
+ #
3
+ # You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
4
+ # copy, modify, and distribute this software in source code or binary form for use
5
+ # in connection with the web services and APIs provided by Facebook.
6
+ #
7
+ # As with any software that integrates with the Facebook platform, your use of
8
+ # this software is subject to the Facebook Platform Policy
9
+ # [http://developers.facebook.com/policy/]. This copyright notice shall be
10
+ # included in all copies or substantial portions of the software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
14
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
16
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
+
19
+ module FacebookAds::ServerSide
20
+ class BatchProcessor
21
+ attr_accessor :batch_size
22
+ attr_accessor :concurrent_requests
23
+
24
+ # Initializes the object
25
+ # @param [Integer] batch_size The number of events to send in each request
26
+ # @param [Integer] concurrent_requests The number of threads to use when making requests concurrently
27
+ def initialize(batch_size=50, concurrent_requests=4)
28
+ self.batch_size = batch_size
29
+ self.concurrent_requests = concurrent_requests
30
+ end
31
+
32
+ def process_event_requests(event_requests_async)
33
+ generator = self.process_event_requests_generator(event_requests_async)
34
+ generator.each do |batch|
35
+ Concurrent::Promise.zip(*batch).execute.value!
36
+ end
37
+ end
38
+
39
+ def process_events(event_request_async_to_clone, events)
40
+ generator = self.process_events_generator(event_request_async_to_clone, events)
41
+ generator.each do |batch|
42
+ Concurrent::Promise.zip(*batch).execute.value!
43
+ end
44
+ end
45
+
46
+ def process_event_requests_generator(event_requests_async)
47
+ index = 0
48
+ Enumerator.new do |generator|
49
+ while index < event_requests_async.size do
50
+ batch = event_requests_async[index, concurrent_requests].map(&:execute)
51
+ generator.yield *[batch]
52
+ index += concurrent_requests
53
+ end
54
+ end
55
+ end
56
+
57
+ def process_events_generator(event_request_async_to_clone, events)
58
+ index = 0
59
+ Enumerator.new do |generator|
60
+ while index < events.size do
61
+ batch = []
62
+ while index < events.size && batch.size < concurrent_requests do
63
+ event_request_async = event_request_async_to_clone.clone_without_events
64
+ event_request_async.events = events[index, batch_size]
65
+ batch << event_request_async
66
+ index += batch_size
67
+ end
68
+ generator.yield *[batch.map(&:execute)]
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -51,6 +51,9 @@ module FacebookAds
51
51
  # The origin/source of data for the dataset to be uploaded.
52
52
  attr_accessor :upload_source
53
53
 
54
+ # The HttpServiceInterface client to use for executing the request.
55
+ attr_accessor :http_service_client
56
+
54
57
  # @param [String] pixel_id
55
58
  # @param [Array(FacebookAds::ServerSide::Event)] events
56
59
  # @param [String] test_event_code
@@ -59,8 +62,10 @@ module FacebookAds
59
62
  # @param [String] upload_id
60
63
  # @param [String] upload_tag
61
64
  # @param [String] upload_source
65
+ # @param [HttpServiceInterface] http_service_client
62
66
  def initialize(pixel_id: nil, events: nil, test_event_code: nil, partner_agent: nil,
63
- namespace_id: nil, upload_id: nil, upload_tag: nil, upload_source: nil)
67
+ namespace_id: nil, upload_id: nil, upload_tag: nil, upload_source: nil,
68
+ http_service_client: nil)
64
69
  unless pixel_id.nil?
65
70
  self.pixel_id = pixel_id
66
71
  end
@@ -85,6 +90,9 @@ module FacebookAds
85
90
  unless upload_source.nil?
86
91
  self.upload_source = upload_source
87
92
  end
93
+ unless http_service_client.nil?
94
+ self.http_service_client = http_service_client
95
+ end
88
96
  end
89
97
 
90
98
  # build the object using the input hash
@@ -128,6 +136,10 @@ module FacebookAds
128
136
  if attributes.has_key?(:'upload_source')
129
137
  self.upload_source = attributes[:'upload_source']
130
138
  end
139
+
140
+ if attributes.has_key?(:'http_service_client')
141
+ self.http_service_client = attributes[:'http_service_client']
142
+ end
131
143
  end
132
144
 
133
145
  # Execute request
@@ -135,18 +147,13 @@ module FacebookAds
135
147
  unless valid?
136
148
  raise list_invalid_properties
137
149
  end
138
- normalized_events = normalize
139
- ads_pixel = FacebookAds::AdsPixel.get(pixel_id)
140
- params = {
141
- data: normalized_events
142
- }
143
- params[:test_event_code] = test_event_code unless test_event_code.nil?
144
- params[:partner_agent] = partner_agent unless partner_agent.nil?
145
- params[:namespace_id] = namespace_id unless namespace_id.nil?
146
- params[:upload_id] = upload_id unless upload_id.nil?
147
- params[:upload_tag] = upload_tag unless upload_tag.nil?
148
- params[:upload_source] = upload_source unless upload_source.nil?
149
150
 
151
+ if http_service_client
152
+ return execute_with_client(http_service_client)
153
+ end
154
+ params = get_params()
155
+ params[:data] = normalize
156
+ ads_pixel = FacebookAds::AdsPixel.get(pixel_id)
150
157
  response = ads_pixel.events.create(params)
151
158
  json_response_object = JSON.parse(JSON.generate(response), object_class: OpenStruct)
152
159
  FacebookAds::ServerSide::EventResponse.new(
@@ -164,6 +171,44 @@ module FacebookAds
164
171
  normalized_events
165
172
  end
166
173
 
174
+ def get_params
175
+ params = {}
176
+ params[:test_event_code] = test_event_code unless test_event_code.nil?
177
+ params[:partner_agent] = partner_agent unless partner_agent.nil?
178
+ params[:namespace_id] = namespace_id unless namespace_id.nil?
179
+ params[:upload_id] = upload_id unless upload_id.nil?
180
+ params[:upload_tag] = upload_tag unless upload_tag.nil?
181
+ params[:upload_source] = upload_source unless upload_source.nil?
182
+ params
183
+ end
184
+
185
+ def execute_with_client http_client
186
+ url = [
187
+ "https://#{FacebookAds::DEFAULT_HOST}",
188
+ FacebookAds::DEFAULT_API_VERSION,
189
+ pixel_id,
190
+ 'events',
191
+ ].join('/')
192
+ headers = {
193
+ 'User-Agent' => "fbbizsdk-ruby-v#{FacebookAds::API_VERSION}"
194
+ }
195
+ params = get_params
196
+ params[:data] = events.map(&:normalize)
197
+ appsecret = FacebookAds.config.app_secret
198
+ access_token = FacebookAds.config.access_token
199
+ params[:access_token] = access_token
200
+ if appsecret
201
+ params[:appsecret_proof] = FacebookAds::ServerSide::HttpUtil.appsecret_proof(appsecret, access_token)
202
+ end
203
+
204
+ http_client.execute(
205
+ url,
206
+ FacebookAds::ServerSide::HttpMethod::POST,
207
+ headers,
208
+ params
209
+ )
210
+ end
211
+
167
212
  # Show invalid properties with the reasons. Usually used together with valid?
168
213
  # @return Array for valid properties with the reasons
169
214
  def list_invalid_properties
@@ -193,7 +238,8 @@ module FacebookAds
193
238
  namespace_id == o.namespace_id &&
194
239
  upload_id == o.upload_id &&
195
240
  upload_tag == o.upload_tag &&
196
- upload_source == o.upload_source
241
+ upload_source == o.upload_source &&
242
+ http_service_client == o.http_service_client
197
243
  end
198
244
 
199
245
  # @see the `==` method
@@ -213,6 +259,7 @@ module FacebookAds
213
259
  upload_id,
214
260
  upload_tag,
215
261
  upload_source,
262
+ http_service_client,
216
263
  ].hash
217
264
  end
218
265
 
@@ -26,6 +26,18 @@ module FacebookAds
26
26
  super
27
27
  end
28
28
  end
29
+
30
+ def clone_without_events
31
+ FacebookAds::ServerSide::EventRequestAsync.new(
32
+ pixel_id: pixel_id,
33
+ test_event_code: test_event_code,
34
+ partner_agent: partner_agent,
35
+ namespace_id: namespace_id,
36
+ upload_id: upload_id,
37
+ upload_tag: upload_tag,
38
+ upload_source: upload_source,
39
+ )
40
+ end
29
41
  end
30
42
  end
31
43
  end
@@ -0,0 +1,28 @@
1
+ # Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
2
+ #
3
+ # You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
4
+ # copy, modify, and distribute this software in source code or binary form for use
5
+ # in connection with the web services and APIs provided by Facebook.
6
+ #
7
+ # As with any software that integrates with the Facebook platform, your use of
8
+ # this software is subject to the Facebook Platform Policy
9
+ # [http://developers.facebook.com/policy/]. This copyright notice shall be
10
+ # included in all copies or substantial portions of the software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
14
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
16
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
+
19
+ module FacebookAds
20
+ module ServerSide
21
+ class HttpMethod
22
+ POST = 'POST'
23
+ PUT = 'PUT'
24
+ GET = 'GET'
25
+ DELETE = 'DELETE'
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ # Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
2
+ #
3
+ # You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
4
+ # copy, modify, and distribute this software in source code or binary form for use
5
+ # in connection with the web services and APIs provided by Facebook.
6
+ #
7
+ # As with any software that integrates with the Facebook platform, your use of
8
+ # this software is subject to the Facebook Platform Policy
9
+ # [http://developers.facebook.com/policy/]. This copyright notice shall be
10
+ # included in all copies or substantial portions of the software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
14
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
16
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
+
19
+
20
+ module FacebookAds
21
+ module ServerSide
22
+ class HttpServiceInterface
23
+
24
+ # String url | The graph API endpoint that will be requested
25
+ # String request_method | The HTTP request method
26
+ # Hash headers | Contains HTTP request headers including User-Agent and Accept-Encoding
27
+ # Hash params | Contains request parameters including access_token, data, test_event_code, etc.
28
+ def execute(url, request_method, headers, params)
29
+ raise Exception.new("Method 'execute' not implemented")
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ # Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
2
+ #
3
+ # You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
4
+ # copy, modify, and distribute this software in source code or binary form for use
5
+ # in connection with the web services and APIs provided by Facebook.
6
+ #
7
+ # As with any software that integrates with the Facebook platform, your use of
8
+ # this software is subject to the Facebook Platform Policy
9
+ # [http://developers.facebook.com/policy/]. This copyright notice shall be
10
+ # included in all copies or substantial portions of the software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
14
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
16
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
+
19
+ module FacebookAds
20
+ module ServerSide
21
+ class HttpUtil
22
+ def self.appsecret_proof(app_secret, access_token)
23
+ OpenSSL::HMAC.hexdigest(
24
+ OpenSSL::Digest.new('sha256'),
25
+ app_secret,
26
+ access_token
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -19,6 +19,6 @@
19
19
  # FB:AUTOGEN
20
20
 
21
21
  module FacebookAds
22
- VERSION = '0.8.0.2'
22
+ VERSION = '0.8.0.3'
23
23
  API_VERSION = '8.0'
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebookbusiness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0.2
4
+ version: 0.8.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Facebook
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-18 00:00:00.000000000 Z
11
+ date: 2020-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -610,6 +610,7 @@ files:
610
610
  - lib/facebook_ads/ad_objects/saved_audience.rb
611
611
  - lib/facebook_ads/ad_objects/saved_message_response.rb
612
612
  - lib/facebook_ads/ad_objects/security_settings.rb
613
+ - lib/facebook_ads/ad_objects/server_side/batch_processor.rb
613
614
  - lib/facebook_ads/ad_objects/server_side/content.rb
614
615
  - lib/facebook_ads/ad_objects/server_side/custom_data.rb
615
616
  - lib/facebook_ads/ad_objects/server_side/delivery_category.rb
@@ -617,6 +618,9 @@ files:
617
618
  - lib/facebook_ads/ad_objects/server_side/event_request.rb
618
619
  - lib/facebook_ads/ad_objects/server_side/event_request_async.rb
619
620
  - lib/facebook_ads/ad_objects/server_side/event_response.rb
621
+ - lib/facebook_ads/ad_objects/server_side/http_method.rb
622
+ - lib/facebook_ads/ad_objects/server_side/http_service_interface.rb
623
+ - lib/facebook_ads/ad_objects/server_side/http_util.rb
620
624
  - lib/facebook_ads/ad_objects/server_side/user_data.rb
621
625
  - lib/facebook_ads/ad_objects/server_side/util.rb
622
626
  - lib/facebook_ads/ad_objects/split_test_winner.rb