facebookbusiness 0.5.0.2 → 0.5.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/lib/facebook_ads.rb +7 -1
  3. data/lib/facebook_ads/ad_objects/ad_account.rb +0 -6
  4. data/lib/facebook_ads/ad_objects/ad_creative.rb +1 -0
  5. data/lib/facebook_ads/ad_objects/ad_creative_link_data_image_overlay_spec.rb +2 -0
  6. data/lib/facebook_ads/ad_objects/ad_preview.rb +2 -0
  7. data/lib/facebook_ads/ad_objects/ad_set.rb +19 -19
  8. data/lib/facebook_ads/ad_objects/ad_study.rb +0 -4
  9. data/lib/facebook_ads/ad_objects/ads_insights.rb +0 -1
  10. data/lib/facebook_ads/ad_objects/album.rb +1 -0
  11. data/lib/facebook_ads/ad_objects/business.rb +3 -7
  12. data/lib/facebook_ads/ad_objects/business_image.rb +1 -1
  13. data/lib/facebook_ads/ad_objects/business_unit.rb +10 -1
  14. data/lib/facebook_ads/ad_objects/event.rb +17 -6
  15. data/lib/facebook_ads/ad_objects/group.rb +4 -3
  16. data/lib/facebook_ads/ad_objects/live_video.rb +1 -0
  17. data/lib/facebook_ads/ad_objects/null_node.rb +36 -0
  18. data/lib/facebook_ads/ad_objects/page.rb +13 -6
  19. data/lib/facebook_ads/ad_objects/product_catalog.rb +1 -0
  20. data/lib/facebook_ads/ad_objects/product_feed.rb +8 -0
  21. data/lib/facebook_ads/ad_objects/product_feed_schedule.rb +1 -3
  22. data/lib/facebook_ads/ad_objects/reach_frequency_prediction.rb +0 -1
  23. data/lib/facebook_ads/ad_objects/server_side/content.rb +128 -0
  24. data/lib/facebook_ads/ad_objects/server_side/custom_data.rb +313 -0
  25. data/lib/facebook_ads/ad_objects/server_side/event.rb +236 -0
  26. data/lib/facebook_ads/ad_objects/server_side/event_request.rb +158 -0
  27. data/lib/facebook_ads/ad_objects/server_side/event_response.rb +106 -0
  28. data/lib/facebook_ads/ad_objects/server_side/user_data.rb +396 -0
  29. data/lib/facebook_ads/ad_objects/server_side/util.rb +225 -0
  30. data/lib/facebook_ads/ad_objects/user.rb +14 -0
  31. data/lib/facebook_ads/api_response.rb +4 -0
  32. data/lib/facebook_ads/errors.rb +6 -1
  33. data/lib/facebook_ads/version.rb +1 -1
  34. metadata +10 -3
  35. data/lib/facebook_ads/ad_objects/business_project.rb +0 -86
@@ -0,0 +1,225 @@
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
+ require 'digest'
20
+
21
+ module FacebookAds
22
+ module ServerSide
23
+
24
+ PHONE_NUMBER_IGNORE_CHAR_SET = /[\-\s\(\)]+/
25
+ PHONE_NUMBER_DROP_PREFIX_ZEROS = /^\+?0{0,2}/
26
+ US_PHONE_NUMBER_REGEX = /^1\(?\d{3}\)?\d{7}$/
27
+ INTL_PHONE_NUMBER_REGEX = /^\d{1,4}\(?\d{2,3}\)?\d{4,}$/
28
+
29
+ # RFC 2822 for email format
30
+ EMAIL_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
31
+
32
+ # @return [String] SHA 256 hash of input string
33
+ def self.sha256Hash(input)
34
+ unless input.nil?
35
+ Digest::SHA256.hexdigest input
36
+ end
37
+ end
38
+
39
+ # Normalizes the input string given the field_type
40
+ # @param [String] input Input string that needs to be normalized
41
+ # @param [String] field_type Type/Key for the value provided
42
+ # @return [String] Normalized value for the input and field_type.
43
+ def self.normalize(input, field_type)
44
+
45
+ if input.nil? or field_type.nil?
46
+ return nil;
47
+ end
48
+
49
+ input = input.strip.downcase
50
+
51
+ # If the data is already hashed, we by-pass input normalization
52
+ if FacebookAds::ServerSide::is_already_hashed?(input) == true
53
+ return input
54
+ end
55
+
56
+ normalized_input = input;
57
+
58
+ case field_type
59
+ when 'country'
60
+ normalized_input = FacebookAds::ServerSide::normalize_country input
61
+ when 'ct'
62
+ normalized_input = FacebookAds::ServerSide::normalize_city input
63
+ when 'currency'
64
+ return FacebookAds::ServerSide::normalize_currency input
65
+ when 'em'
66
+ normalized_input = FacebookAds::ServerSide::normalize_email input
67
+ when 'ge'
68
+ normalized_input = FacebookAds::ServerSide::normalize_gender input
69
+ when 'ph'
70
+ normalized_input = FacebookAds::ServerSide::normalize_phone input
71
+ when 'st'
72
+ normalized_input = FacebookAds::ServerSide::normalize_state input
73
+ when 'zp'
74
+ normalized_input = FacebookAds::ServerSide::normalize_zip input
75
+ end
76
+
77
+ normalized_input = FacebookAds::ServerSide::sha256Hash normalized_input
78
+
79
+ return normalized_input
80
+ end
81
+
82
+ # Boolean method which checks if a input is already hashed with MD5 or SHA256
83
+ # @param [String] input Input string that is to be validated
84
+ # @return [TrueClass|FalseClass] representing whether the value is hashed
85
+ def self.is_already_hashed?(input)
86
+
87
+ # We support Md5 and SHA256, and highly recommend users to use SHA256 for hashing PII keys.
88
+ md5_match = /^[a-f0-9]{32}$/.match(input)
89
+ sha256_match = /^[a-f0-9]{64}$/.match(input)
90
+
91
+ if md5_match != nil or sha256_match != nil
92
+ return true
93
+ end
94
+
95
+ return false
96
+ end
97
+
98
+ # Normalizes the given country code and returns acceptable hashed country ISO code
99
+ def self.normalize_country(country)
100
+
101
+ # Replace unwanted characters and retain only alpha characters bounded for ISO code.
102
+ country = country.gsub(/[^a-z]/,'')
103
+
104
+ if country.length != 2
105
+ raise ArgumentError, "Invalid format for country:'" + country + "'.Please follow ISO 2-letter ISO 3166-1 standard for representing country. eg: us"
106
+ end
107
+
108
+ return country
109
+ end
110
+
111
+ # Normalizes the given city and returns acceptable hashed city value
112
+ def self.normalize_city(city)
113
+
114
+ # Remove commonly occuring characters from city name.
115
+ city = city.gsub(/[0-9.\s\-()]/,'')
116
+
117
+ return city
118
+ end
119
+
120
+ # Normalizes the given currency code and returns acceptable hashed currency ISO code
121
+ def self.normalize_currency(currency)
122
+
123
+ # Retain only alpha characters bounded for ISO code.
124
+ currency = currency.gsub(/[^a-z]/,'')
125
+
126
+ if currency.length != 3
127
+ raise ArgumentError, "Invalid format for currency:'" + currency + "'.Please follow ISO 3-letter ISO 4217 standard for representing currency. Eg: usd"
128
+ end
129
+
130
+ return currency;
131
+ end
132
+
133
+ # Normalizes the given email and returns acceptable hashed email value
134
+ def self.normalize_email(email)
135
+
136
+ if EMAIL_REGEX.match(email) == nil
137
+ return ArgumentError, "Invalid email format for the passed email:' + email + '.Please check the passed email format."
138
+ end
139
+
140
+ return email
141
+ end
142
+
143
+ # Normalizes the given gender and returns acceptable hashed gender value
144
+ def self.normalize_gender(gender)
145
+
146
+ # Replace extra characters with space, to bound under alpha characters set.
147
+ gender = gender.gsub(/[^a-z]/,'')
148
+
149
+ case gender
150
+ when 'female' , 'f'
151
+ gender = 'f'
152
+ when 'male' , 'm'
153
+ gender = 'm'
154
+ else
155
+ return nil
156
+ end
157
+
158
+ return gender
159
+ end
160
+
161
+ # Normalizes the given phone and returns acceptable hashed phone value
162
+ def self.normalize_phone(phone)
163
+
164
+ # Drop the spaces, hyphen and parenthesis from the Phone Number
165
+ normalized_phone = phone.gsub(PHONE_NUMBER_IGNORE_CHAR_SET, '')
166
+
167
+ if(FacebookAds::ServerSide::is_international_number?(normalized_phone))
168
+ normalized_phone = normalized_phone.gsub(PHONE_NUMBER_DROP_PREFIX_ZEROS, '')
169
+ end
170
+
171
+ if normalized_phone.length < 7 || normalized_phone.length > 15
172
+ return nil;
173
+ end
174
+
175
+ return normalized_phone
176
+ end
177
+
178
+ # Normalizes the given city and returns acceptable hashed city value
179
+ def self.normalize_state(state)
180
+ state = state.gsub(/[0-9.\s\-()]/,'')
181
+
182
+ return state
183
+ end
184
+
185
+ # Normalizes the given zip and returns acceptable hashed zip code value
186
+ def self.normalize_zip(zip)
187
+
188
+ # Remove spaces from the Postal code
189
+ zip = zip.gsub(/[\s]/,'')
190
+
191
+ # If the zip code '-', we retain just the first part alone.
192
+ zip = zip.split('-')[0]
193
+
194
+ if zip.length < 2
195
+ return nil
196
+ end
197
+
198
+ return zip
199
+ end
200
+
201
+ # Boolean method which checks if a given number is represented in international format
202
+ # @param [String] phone_number that has to be tested.
203
+ # @return [TrueClass | FalseClass] boolean value representing if a number is international
204
+ def self.is_international_number?(phone_number)
205
+
206
+ # Drop upto 2 leading 0s from the number
207
+ phone_number = phone_number.gsub(PHONE_NUMBER_DROP_PREFIX_ZEROS, '')
208
+
209
+ if phone_number.start_with?('0')
210
+ return false;
211
+ end
212
+
213
+ if phone_number.start_with?('1') && US_PHONE_NUMBER_REGEX.match(phone_number) != nil
214
+ return false;
215
+ end
216
+
217
+ if INTL_PHONE_NUMBER_REGEX.match(phone_number) != nil
218
+ return true;
219
+ end
220
+
221
+ return false;
222
+ end
223
+
224
+ end
225
+ end
@@ -79,6 +79,7 @@ module FacebookAds
79
79
  "MSN",
80
80
  "MYSPACE",
81
81
  "NATEON",
82
+ "OCULUS",
82
83
  "OK",
83
84
  "ORKUT",
84
85
  "OTHERS",
@@ -126,6 +127,7 @@ module FacebookAds
126
127
  field :installed, 'bool'
127
128
  field :interested_in, { list: 'string' }
128
129
  field :is_famedeeplinkinguser, 'bool'
130
+ field :is_guest_user, 'bool'
129
131
  field :is_shared_login, 'bool'
130
132
  field :is_verified, 'bool'
131
133
  field :languages, { list: 'Experience' }
@@ -305,6 +307,17 @@ module FacebookAds
305
307
  api.has_param :business, 'string'
306
308
  end
307
309
  edge.get 'Business'
310
+ edge.post 'Business' do |api|
311
+ api.has_param :email, 'string'
312
+ api.has_param :name, 'string'
313
+ api.has_param :primary_page, 'string'
314
+ api.has_param :sales_rep_email, 'string'
315
+ api.has_param :survey_business_type, { enum: -> { Business::SURVEY_BUSINESS_TYPE }}
316
+ api.has_param :survey_num_assets, 'int'
317
+ api.has_param :survey_num_people, 'int'
318
+ api.has_param :timezone_id, 'int'
319
+ api.has_param :vertical, { enum: -> { Business::VERTICAL }}
320
+ end
308
321
  end
309
322
 
310
323
  has_edge :conversations do |edge|
@@ -722,6 +735,7 @@ module FacebookAds
722
735
  api.has_param :ios_bundle_id, 'string'
723
736
  api.has_param :is_explicit_location, 'bool'
724
737
  api.has_param :is_explicit_place, 'bool'
738
+ api.has_param :is_visual_search, 'bool'
725
739
  api.has_param :manual_privacy, 'bool'
726
740
  api.has_param :message, 'string'
727
741
  api.has_param :name, 'string'
@@ -38,6 +38,10 @@ module FacebookAds
38
38
  @body
39
39
  end
40
40
 
41
+ def headers
42
+ @headers
43
+ end
44
+
41
45
  private
42
46
  def is_json_response?
43
47
  headers[:content_type] =~ /application\/json/ ||
@@ -24,7 +24,7 @@ module FacebookAds
24
24
 
25
25
  class APIError < Error
26
26
  ERROR_ATTRS = [
27
- :fb_message, :type, :code,
27
+ :headers, :fb_message, :type, :code,
28
28
  :error_subcode, :is_transient, :error_user_title,
29
29
  :error_user_msg, :fbtrace_id,
30
30
  ]
@@ -32,6 +32,7 @@ module FacebookAds
32
32
  attr_accessor *ERROR_ATTRS
33
33
 
34
34
  def initialize(api_response)
35
+ send("headers=", api_response.headers)
35
36
  error_obj = api_response.result
36
37
  @api_response = api_response
37
38
 
@@ -47,6 +48,10 @@ module FacebookAds
47
48
  super(error_obj)
48
49
  end
49
50
  end
51
+
52
+ def getHeaders
53
+ self.headers
54
+ end
50
55
  end
51
56
 
52
57
  class ServerError < APIError; end
@@ -19,6 +19,6 @@
19
19
  # FB:AUTOGEN
20
20
 
21
21
  module FacebookAds
22
- VERSION = '0.5.0.2'
22
+ VERSION = '0.5.0.3'
23
23
  API_VERSION = '5.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.5.0.2
4
+ version: 0.5.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: 2019-11-11 00:00:00.000000000 Z
11
+ date: 2019-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -344,7 +344,6 @@ files:
344
344
  - lib/facebook_ads/ad_objects/business_owned_object_on_behalf_of_request.rb
345
345
  - lib/facebook_ads/ad_objects/business_page_request.rb
346
346
  - lib/facebook_ads/ad_objects/business_pixel_tos.rb
347
- - lib/facebook_ads/ad_objects/business_project.rb
348
347
  - lib/facebook_ads/ad_objects/business_role_request.rb
349
348
  - lib/facebook_ads/ad_objects/business_unit.rb
350
349
  - lib/facebook_ads/ad_objects/business_user.rb
@@ -464,6 +463,7 @@ files:
464
463
  - lib/facebook_ads/ad_objects/native_offer.rb
465
464
  - lib/facebook_ads/ad_objects/native_offer_discount.rb
466
465
  - lib/facebook_ads/ad_objects/native_offer_view.rb
466
+ - lib/facebook_ads/ad_objects/null_node.rb
467
467
  - lib/facebook_ads/ad_objects/offline_conversion_data_set.rb
468
468
  - lib/facebook_ads/ad_objects/offline_terms_of_service.rb
469
469
  - lib/facebook_ads/ad_objects/offsite_pixel.rb
@@ -549,6 +549,13 @@ files:
549
549
  - lib/facebook_ads/ad_objects/saved_audience.rb
550
550
  - lib/facebook_ads/ad_objects/saved_message_response.rb
551
551
  - lib/facebook_ads/ad_objects/security_settings.rb
552
+ - lib/facebook_ads/ad_objects/server_side/content.rb
553
+ - lib/facebook_ads/ad_objects/server_side/custom_data.rb
554
+ - lib/facebook_ads/ad_objects/server_side/event.rb
555
+ - lib/facebook_ads/ad_objects/server_side/event_request.rb
556
+ - lib/facebook_ads/ad_objects/server_side/event_response.rb
557
+ - lib/facebook_ads/ad_objects/server_side/user_data.rb
558
+ - lib/facebook_ads/ad_objects/server_side/util.rb
552
559
  - lib/facebook_ads/ad_objects/split_test_config.rb
553
560
  - lib/facebook_ads/ad_objects/split_test_winner.rb
554
561
  - lib/facebook_ads/ad_objects/store_catalog_settings.rb
@@ -1,86 +0,0 @@
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
- # FB:AUTOGEN
20
-
21
- module FacebookAds
22
- # This class is auto-generated.
23
-
24
- # For any issues or feature requests related to this class, please let us know
25
- # on github and we'll fix in our codegen framework. We'll not be able to accept
26
- # pull request for this class.
27
-
28
- class BusinessProject < AdObject
29
-
30
- field :business, 'Business'
31
- field :created_time, 'datetime'
32
- field :creator, 'object'
33
- field :id, 'string'
34
- field :name, 'string'
35
-
36
- has_edge :adaccounts do |edge|
37
- edge.delete do |api|
38
- api.has_param :adaccount_id, 'string'
39
- end
40
- edge.get 'AdAccount'
41
- edge.post 'BusinessProject' do |api|
42
- api.has_param :adaccount_id, 'string'
43
- end
44
- end
45
-
46
- has_edge :apps do |edge|
47
- edge.delete do |api|
48
- api.has_param :app_id, 'string'
49
- end
50
- edge.get 'Application'
51
- edge.post 'BusinessProject' do |api|
52
- api.has_param :app_id, 'string'
53
- end
54
- end
55
-
56
- has_edge :assets do |edge|
57
- edge.delete do |api|
58
- api.has_param :asset_id, 'string'
59
- end
60
- edge.post 'BusinessProject' do |api|
61
- api.has_param :asset_id, 'string'
62
- end
63
- end
64
-
65
- has_edge :pages do |edge|
66
- edge.delete do |api|
67
- api.has_param :page_id, 'int'
68
- end
69
- edge.get 'Page'
70
- edge.post 'BusinessProject' do |api|
71
- api.has_param :page_id, 'int'
72
- end
73
- end
74
-
75
- has_edge :product_catalogs do |edge|
76
- edge.delete do |api|
77
- api.has_param :product_catalog_id, 'string'
78
- end
79
- edge.get 'ProductCatalog'
80
- edge.post 'BusinessProject' do |api|
81
- api.has_param :product_catalog_id, 'string'
82
- end
83
- end
84
-
85
- end
86
- end