facebookbusiness 0.7.0.2 → 0.7.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/facebook_ads/ad_objects/ad_account.rb +5 -6
- data/lib/facebook_ads/ad_objects/ad_account_delivery_estimate.rb +1 -0
- data/lib/facebook_ads/ad_objects/ad_account_matched_search_applications_edge_data.rb +1 -0
- data/lib/facebook_ads/ad_objects/ad_account_targeting_unified.rb +1 -0
- data/lib/facebook_ads/ad_objects/ad_activity.rb +7 -0
- data/lib/facebook_ads/ad_objects/ad_asset_feed_spec.rb +1 -0
- data/lib/facebook_ads/ad_objects/ad_campaign_activity.rb +2 -2
- data/lib/facebook_ads/ad_objects/ad_campaign_delivery_estimate.rb +1 -0
- data/lib/facebook_ads/ad_objects/ad_creative.rb +1 -0
- data/lib/facebook_ads/ad_objects/ad_creative_link_data_call_to_action.rb +1 -0
- data/lib/facebook_ads/ad_objects/ad_preview.rb +0 -1
- data/lib/facebook_ads/ad_objects/ad_set.rb +2 -0
- data/lib/facebook_ads/ad_objects/ad_study.rb +1 -0
- data/lib/facebook_ads/ad_objects/ad_video.rb +5 -27
- data/lib/facebook_ads/ad_objects/adgroup_placement_specific_review_feedback.rb +4 -0
- data/lib/facebook_ads/ad_objects/{ads_interest.rb → adoptable_pet.rb} +18 -5
- data/lib/facebook_ads/ad_objects/ads_insights.rb +4 -0
- data/lib/facebook_ads/ad_objects/application.rb +4 -0
- data/lib/facebook_ads/ad_objects/atlas_campaign.rb +2 -2
- data/lib/facebook_ads/ad_objects/business.rb +1 -121
- data/lib/facebook_ads/ad_objects/business_asset_group.rb +0 -3
- data/lib/facebook_ads/ad_objects/business_role_request.rb +5 -0
- data/lib/facebook_ads/ad_objects/business_user.rb +5 -0
- data/lib/facebook_ads/ad_objects/campaign.rb +257 -0
- data/lib/facebook_ads/ad_objects/commerce_merchant_settings.rb +8 -0
- data/lib/facebook_ads/ad_objects/event.rb +11 -0
- data/lib/facebook_ads/ad_objects/external_event_source.rb +1 -0
- data/lib/facebook_ads/ad_objects/group.rb +5 -0
- data/lib/facebook_ads/ad_objects/ig_media.rb +1 -0
- data/lib/facebook_ads/ad_objects/media_fingerprint.rb +0 -1
- data/lib/facebook_ads/ad_objects/page.rb +5 -2
- data/lib/facebook_ads/ad_objects/page_admin_note.rb +1 -0
- data/lib/facebook_ads/ad_objects/page_call_to_action.rb +3 -0
- data/lib/facebook_ads/ad_objects/page_change_proposal.rb +2 -0
- data/lib/facebook_ads/ad_objects/{brand_audience.rb → payment_subscription.rb} +23 -9
- data/lib/facebook_ads/ad_objects/post.rb +1 -1
- data/lib/facebook_ads/ad_objects/product_catalog.rb +2 -0
- data/lib/facebook_ads/ad_objects/product_feed.rb +1 -0
- data/lib/facebook_ads/ad_objects/product_set.rb +3 -0
- data/lib/facebook_ads/ad_objects/{user_influence.rb → product_set_metadata.rb} +4 -4
- data/lib/facebook_ads/ad_objects/profile.rb +1 -0
- data/lib/facebook_ads/ad_objects/profile_picture_source.rb +4 -0
- data/lib/facebook_ads/ad_objects/saved_audience.rb +1 -0
- data/lib/facebook_ads/ad_objects/server_side/content.rb +75 -13
- data/lib/facebook_ads/ad_objects/server_side/custom_data.rb +24 -6
- data/lib/facebook_ads/ad_objects/server_side/event_request.rb +80 -6
- data/lib/facebook_ads/ad_objects/server_side/user_data.rb +126 -17
- data/lib/facebook_ads/ad_objects/server_side/util.rb +204 -150
- data/lib/facebook_ads/ad_objects/system_user.rb +5 -0
- data/lib/facebook_ads/ad_objects/targeting.rb +1 -0
- data/lib/facebook_ads/ad_objects/{creative_asset_tag.rb → targeting_relaxation.rb} +2 -2
- data/lib/facebook_ads/ad_objects/third_party_measurement_report_dataset.rb +1 -0
- data/lib/facebook_ads/ad_objects/user.rb +8 -4
- data/lib/facebook_ads/ad_objects/user_taggable_friend.rb +1 -0
- data/lib/facebook_ads/ad_objects/{whats_app_business_profile.rb → work_meeting_link.rb} +3 -3
- data/lib/facebook_ads/version.rb +1 -1
- metadata +36 -16
- data/lib/facebook_ads/ad_objects/business_creative.rb +0 -50
- data/lib/facebook_ads/ad_objects/business_creative_folder.rb +0 -79
- data/lib/facebook_ads/ad_objects/business_creative_folder_sharing_agreement.rb +0 -46
- data/lib/facebook_ads/ad_objects/business_image.rb +0 -95
- data/lib/facebook_ads/ad_objects/client_transparency_status.rb +0 -40
- data/lib/facebook_ads/ad_objects/messenger_platform_referral.rb +0 -39
- data/lib/facebook_ads/ad_objects/streaming_reaction.rb +0 -51
@@ -16,8 +16,6 @@
|
|
16
16
|
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
17
17
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
18
18
|
|
19
|
-
require_relative 'util'
|
20
|
-
|
21
19
|
module FacebookAds
|
22
20
|
module ServerSide
|
23
21
|
|
@@ -93,6 +91,24 @@ module FacebookAds
|
|
93
91
|
# The subscription ID for the user in this transaction. This is similar to the order ID for an individual product.
|
94
92
|
attr_accessor :subscription_id
|
95
93
|
|
94
|
+
# The first 5 letters of the first name.
|
95
|
+
attr_accessor :f5first
|
96
|
+
|
97
|
+
# The first 5 letters of the last name.
|
98
|
+
attr_accessor :f5last
|
99
|
+
|
100
|
+
# The first initial.
|
101
|
+
attr_accessor :fi
|
102
|
+
|
103
|
+
# The date of birth day.
|
104
|
+
attr_accessor :dobd
|
105
|
+
|
106
|
+
# The date of birth month.
|
107
|
+
attr_accessor :dobm
|
108
|
+
|
109
|
+
# THe date of birth year.
|
110
|
+
attr_accessor :doby
|
111
|
+
|
96
112
|
#UserData is a set of identifiers Facebook can use for targeted attribution
|
97
113
|
# @param [String] email
|
98
114
|
# @param [String] phone
|
@@ -110,10 +126,17 @@ module FacebookAds
|
|
110
126
|
# @param [String] fbc
|
111
127
|
# @param [String] fbp
|
112
128
|
# @param [String] subscription_id
|
129
|
+
# @param [String] f5first
|
130
|
+
# @param [String] f5last
|
131
|
+
# @param [String] fi
|
132
|
+
# @param [String] dobd
|
133
|
+
# @param [String] dobm
|
134
|
+
# @param [String] doby
|
113
135
|
def initialize(email: nil, phone: nil, gender: nil, date_of_birth: nil,
|
114
136
|
last_name: nil, first_name: nil, city: nil, state: nil,
|
115
137
|
country_code: nil, zip_code: nil, external_id: nil, client_ip_address: nil,
|
116
|
-
client_user_agent: nil, fbc: nil, fbp: nil, subscription_id: nil
|
138
|
+
client_user_agent: nil, fbc: nil, fbp: nil, subscription_id: nil,
|
139
|
+
f5first: nil, f5last: nil, fi: nil, dobd: nil, dobm: nil, doby: nil)
|
117
140
|
unless email.nil?
|
118
141
|
self.email = email
|
119
142
|
end
|
@@ -162,6 +185,24 @@ module FacebookAds
|
|
162
185
|
unless subscription_id.nil?
|
163
186
|
self.subscription_id = subscription_id
|
164
187
|
end
|
188
|
+
unless f5first.nil?
|
189
|
+
self.f5first = f5first
|
190
|
+
end
|
191
|
+
unless f5last.nil?
|
192
|
+
self.f5last = f5last
|
193
|
+
end
|
194
|
+
unless fi.nil?
|
195
|
+
self.fi = fi
|
196
|
+
end
|
197
|
+
unless dobd.nil?
|
198
|
+
self.dobd = dobd
|
199
|
+
end
|
200
|
+
unless dobm.nil?
|
201
|
+
self.dobm = dobm
|
202
|
+
end
|
203
|
+
unless doby.nil?
|
204
|
+
self.doby = doby
|
205
|
+
end
|
165
206
|
end
|
166
207
|
|
167
208
|
# build the object using the input hash
|
@@ -232,8 +273,28 @@ module FacebookAds
|
|
232
273
|
self.fbp = attributes[:'fbp']
|
233
274
|
end
|
234
275
|
|
235
|
-
if attributes.has_key?(:'
|
236
|
-
self.
|
276
|
+
if attributes.has_key?(:'f5first')
|
277
|
+
self.f5first = attributes[:'f5first']
|
278
|
+
end
|
279
|
+
|
280
|
+
if attributes.has_key?(:'f5last')
|
281
|
+
self.f5last = attributes[:'f5last']
|
282
|
+
end
|
283
|
+
|
284
|
+
if attributes.has_key?(:'fi')
|
285
|
+
self.fi = attributes[:'fi']
|
286
|
+
end
|
287
|
+
|
288
|
+
if attributes.has_key?(:'dobd')
|
289
|
+
self.dobd = attributes[:'dobd']
|
290
|
+
end
|
291
|
+
|
292
|
+
if attributes.has_key?(:'dobm')
|
293
|
+
self.dobm = attributes[:'dobm']
|
294
|
+
end
|
295
|
+
|
296
|
+
if attributes.has_key?(:'doby')
|
297
|
+
self.doby = attributes[:'doby']
|
237
298
|
end
|
238
299
|
end
|
239
300
|
|
@@ -256,7 +317,13 @@ module FacebookAds
|
|
256
317
|
client_user_agent == o.client_user_agent &&
|
257
318
|
fbc == o.fbc &&
|
258
319
|
fbp == o.fbp &&
|
259
|
-
subscription_id == o.subscription_id
|
320
|
+
subscription_id == o.subscription_id &&
|
321
|
+
f5first == o.f5first &&
|
322
|
+
f5last == o.f5last &&
|
323
|
+
fi == o.fi &&
|
324
|
+
dobd == o.dobd &&
|
325
|
+
dobm == o.dobm &&
|
326
|
+
doby == o.doby
|
260
327
|
end
|
261
328
|
|
262
329
|
# @see the `==` method
|
@@ -283,7 +350,13 @@ module FacebookAds
|
|
283
350
|
client_user_agent,
|
284
351
|
fbc,
|
285
352
|
fbp,
|
286
|
-
subscription_id
|
353
|
+
subscription_id,
|
354
|
+
f5first,
|
355
|
+
f5last,
|
356
|
+
fi,
|
357
|
+
dobd,
|
358
|
+
dobm,
|
359
|
+
doby,
|
287
360
|
].hash
|
288
361
|
|
289
362
|
end
|
@@ -340,6 +413,24 @@ module FacebookAds
|
|
340
413
|
unless subscription_id.nil?
|
341
414
|
hash['subscription_id'] = subscription_id
|
342
415
|
end
|
416
|
+
unless f5first.nil?
|
417
|
+
hash['f5first'] = f5first
|
418
|
+
end
|
419
|
+
unless f5last.nil?
|
420
|
+
hash['f5last'] = f5last
|
421
|
+
end
|
422
|
+
unless fi.nil?
|
423
|
+
hash['fi'] = fi
|
424
|
+
end
|
425
|
+
unless dobd.nil?
|
426
|
+
hash['dobd'] = dobd
|
427
|
+
end
|
428
|
+
unless dobm.nil?
|
429
|
+
hash['dobm'] = dobm
|
430
|
+
end
|
431
|
+
unless doby.nil?
|
432
|
+
hash['doby'] = doby
|
433
|
+
end
|
343
434
|
hash.to_s
|
344
435
|
end
|
345
436
|
|
@@ -348,34 +439,34 @@ module FacebookAds
|
|
348
439
|
def normalize
|
349
440
|
hash = {}
|
350
441
|
unless email.nil?
|
351
|
-
hash['em'] = FacebookAds::ServerSide::normalize(email, 'em')
|
442
|
+
hash['em'] = FacebookAds::ServerSide::Util.normalize(email, 'em')
|
352
443
|
end
|
353
444
|
unless phone.nil?
|
354
|
-
hash['ph'] = FacebookAds::ServerSide::normalize(phone, 'ph')
|
445
|
+
hash['ph'] = FacebookAds::ServerSide::Util.normalize(phone, 'ph')
|
355
446
|
end
|
356
447
|
unless gender.nil?
|
357
|
-
hash['ge'] = FacebookAds::ServerSide::normalize(gender, 'ge')
|
448
|
+
hash['ge'] = FacebookAds::ServerSide::Util.normalize(gender, 'ge')
|
358
449
|
end
|
359
450
|
unless date_of_birth.nil?
|
360
|
-
hash['db'] = FacebookAds::ServerSide::normalize(date_of_birth, 'db')
|
451
|
+
hash['db'] = FacebookAds::ServerSide::Util.normalize(date_of_birth, 'db')
|
361
452
|
end
|
362
453
|
unless last_name.nil?
|
363
|
-
hash['ln'] = FacebookAds::ServerSide::normalize(last_name, 'ln')
|
454
|
+
hash['ln'] = FacebookAds::ServerSide::Util.normalize(last_name, 'ln')
|
364
455
|
end
|
365
456
|
unless first_name.nil?
|
366
|
-
hash['fn'] = FacebookAds::ServerSide::normalize(first_name, 'fn')
|
457
|
+
hash['fn'] = FacebookAds::ServerSide::Util.normalize(first_name, 'fn')
|
367
458
|
end
|
368
459
|
unless city.nil?
|
369
|
-
hash['ct'] = FacebookAds::ServerSide::normalize(city, 'ct')
|
460
|
+
hash['ct'] = FacebookAds::ServerSide::Util.normalize(city, 'ct')
|
370
461
|
end
|
371
462
|
unless country_code.nil?
|
372
|
-
hash['country'] = FacebookAds::ServerSide::normalize(country_code, 'country')
|
463
|
+
hash['country'] = FacebookAds::ServerSide::Util.normalize(country_code, 'country')
|
373
464
|
end
|
374
465
|
unless state.nil?
|
375
|
-
hash['st'] = FacebookAds::ServerSide::normalize(state, 'st')
|
466
|
+
hash['st'] = FacebookAds::ServerSide::Util.normalize(state, 'st')
|
376
467
|
end
|
377
468
|
unless zip_code.nil?
|
378
|
-
hash['zp'] = FacebookAds::ServerSide::normalize(zip_code, 'zp')
|
469
|
+
hash['zp'] = FacebookAds::ServerSide::Util.normalize(zip_code, 'zp')
|
379
470
|
end
|
380
471
|
unless external_id.nil?
|
381
472
|
hash['external_id'] = external_id
|
@@ -395,6 +486,24 @@ module FacebookAds
|
|
395
486
|
unless subscription_id.nil?
|
396
487
|
hash['subscription_id'] = subscription_id
|
397
488
|
end
|
489
|
+
unless f5first.nil?
|
490
|
+
hash['f5first'] = FacebookAds::ServerSide::Util.normalize(f5first, 'f5first')
|
491
|
+
end
|
492
|
+
unless f5last.nil?
|
493
|
+
hash['f5last'] = FacebookAds::ServerSide::Util.normalize(f5last, 'f5last')
|
494
|
+
end
|
495
|
+
unless fi.nil?
|
496
|
+
hash['fi'] = FacebookAds::ServerSide::Util.normalize(fi, 'fi')
|
497
|
+
end
|
498
|
+
unless dobd.nil?
|
499
|
+
hash['dobd'] = FacebookAds::ServerSide::Util.normalize(dobd, 'dobd')
|
500
|
+
end
|
501
|
+
unless dobm.nil?
|
502
|
+
hash['dobm'] = FacebookAds::ServerSide::Util.normalize(dobm, 'dobm')
|
503
|
+
end
|
504
|
+
unless doby.nil?
|
505
|
+
hash['doby'] = FacebookAds::ServerSide::Util.normalize(doby, 'doby')
|
506
|
+
end
|
398
507
|
hash
|
399
508
|
end
|
400
509
|
end
|
@@ -19,210 +19,264 @@
|
|
19
19
|
require 'digest'
|
20
20
|
require 'countries'
|
21
21
|
require 'money'
|
22
|
+
require 'time'
|
22
23
|
|
23
24
|
module FacebookAds
|
24
25
|
module ServerSide
|
26
|
+
class Util
|
27
|
+
PHONE_NUMBER_IGNORE_CHAR_SET = /[\-\s\(\)]+/
|
28
|
+
PHONE_NUMBER_DROP_PREFIX_ZEROS = /^\+?0{0,2}/
|
29
|
+
US_PHONE_NUMBER_REGEX = /^1\(?\d{3}\)?\d{7}$/
|
30
|
+
INTL_PHONE_NUMBER_REGEX = /^\d{1,4}\(?\d{2,3}\)?\d{4,}$/
|
31
|
+
|
32
|
+
# RFC 2822 for email format
|
33
|
+
EMAIL_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
34
|
+
|
35
|
+
# Normalizes the input string given the field_type
|
36
|
+
# @param [String] input Input string that needs to be normalized
|
37
|
+
# @param [String] field_type Type/Key for the value provided
|
38
|
+
# @return [String] Normalized value for the input and field_type.
|
39
|
+
def self.normalize(input, field_type)
|
40
|
+
|
41
|
+
if input.nil? or field_type.nil?
|
42
|
+
return nil;
|
43
|
+
end
|
44
|
+
|
45
|
+
input = input.strip.downcase
|
46
|
+
|
47
|
+
# If the data is already hashed, we by-pass input normalization
|
48
|
+
if is_already_hashed?(input) == true
|
49
|
+
return input
|
50
|
+
end
|
51
|
+
|
52
|
+
normalized_input = input;
|
53
|
+
|
54
|
+
case field_type
|
55
|
+
when 'country'
|
56
|
+
normalized_input = normalize_country input
|
57
|
+
when 'ct'
|
58
|
+
normalized_input = normalize_city input
|
59
|
+
when 'currency'
|
60
|
+
return normalize_currency input
|
61
|
+
when 'em'
|
62
|
+
normalized_input = normalize_email input
|
63
|
+
when 'ge'
|
64
|
+
normalized_input = normalize_gender input
|
65
|
+
when 'ph'
|
66
|
+
normalized_input = normalize_phone input
|
67
|
+
when 'st'
|
68
|
+
normalized_input = normalize_state input
|
69
|
+
when 'zp'
|
70
|
+
normalized_input = normalize_zip input
|
71
|
+
when 'f5first'
|
72
|
+
normalized_input = normalize_f5 input
|
73
|
+
when 'f5last'
|
74
|
+
normalized_input = normalize_f5 input
|
75
|
+
when 'fi'
|
76
|
+
normalized_input = normalize_fi input
|
77
|
+
when 'dobd'
|
78
|
+
normalized_input = normalize_dobd input
|
79
|
+
when 'dobm'
|
80
|
+
normalized_input = normalize_dobm input
|
81
|
+
when 'doby'
|
82
|
+
normalized_input = normalize_doby input
|
83
|
+
end
|
84
|
+
|
85
|
+
normalized_input = sha256Hash normalized_input
|
86
|
+
|
87
|
+
return normalized_input
|
88
|
+
end
|
25
89
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# RFC 2822 for email format
|
32
|
-
EMAIL_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
33
|
-
|
34
|
-
# @return [String] SHA 256 hash of input string
|
35
|
-
def self.sha256Hash(input)
|
36
|
-
unless input.nil?
|
37
|
-
Digest::SHA256.hexdigest input
|
90
|
+
# @return [String] SHA 256 hash of input string
|
91
|
+
def self.sha256Hash(input)
|
92
|
+
unless input.nil?
|
93
|
+
Digest::SHA256.hexdigest input
|
94
|
+
end
|
38
95
|
end
|
39
|
-
end
|
40
96
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
def self.normalize(input, field_type)
|
46
|
-
|
47
|
-
if input.nil? or field_type.nil?
|
48
|
-
return nil;
|
49
|
-
end
|
50
|
-
|
51
|
-
input = input.strip.downcase
|
52
|
-
|
53
|
-
# If the data is already hashed, we by-pass input normalization
|
54
|
-
if FacebookAds::ServerSide::is_already_hashed?(input) == true
|
55
|
-
return input
|
56
|
-
end
|
57
|
-
|
58
|
-
normalized_input = input;
|
59
|
-
|
60
|
-
case field_type
|
61
|
-
when 'country'
|
62
|
-
normalized_input = FacebookAds::ServerSide::normalize_country input
|
63
|
-
when 'ct'
|
64
|
-
normalized_input = FacebookAds::ServerSide::normalize_city input
|
65
|
-
when 'currency'
|
66
|
-
return FacebookAds::ServerSide::normalize_currency input
|
67
|
-
when 'em'
|
68
|
-
normalized_input = FacebookAds::ServerSide::normalize_email input
|
69
|
-
when 'ge'
|
70
|
-
normalized_input = FacebookAds::ServerSide::normalize_gender input
|
71
|
-
when 'ph'
|
72
|
-
normalized_input = FacebookAds::ServerSide::normalize_phone input
|
73
|
-
when 'st'
|
74
|
-
normalized_input = FacebookAds::ServerSide::normalize_state input
|
75
|
-
when 'zp'
|
76
|
-
normalized_input = FacebookAds::ServerSide::normalize_zip input
|
77
|
-
end
|
78
|
-
|
79
|
-
normalized_input = FacebookAds::ServerSide::sha256Hash normalized_input
|
80
|
-
|
81
|
-
return normalized_input
|
82
|
-
end
|
97
|
+
# Boolean method which checks if a input is already hashed with MD5 or SHA256
|
98
|
+
# @param [String] input Input string that is to be validated
|
99
|
+
# @return [TrueClass|FalseClass] representing whether the value is hashed
|
100
|
+
def self.is_already_hashed?(input)
|
83
101
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
def self.is_already_hashed?(input)
|
102
|
+
# We support Md5 and SHA256, and highly recommend users to use SHA256 for hashing PII keys.
|
103
|
+
md5_match = /^[a-f0-9]{32}$/.match(input)
|
104
|
+
sha256_match = /^[a-f0-9]{64}$/.match(input)
|
88
105
|
|
89
|
-
|
90
|
-
|
91
|
-
|
106
|
+
if md5_match != nil or sha256_match != nil
|
107
|
+
return true
|
108
|
+
end
|
92
109
|
|
93
|
-
|
94
|
-
return true
|
110
|
+
return false
|
95
111
|
end
|
96
112
|
|
97
|
-
|
98
|
-
|
113
|
+
# Normalizes the given country code and returns acceptable hashed country ISO code
|
114
|
+
def self.normalize_country(country)
|
99
115
|
|
100
|
-
|
101
|
-
|
116
|
+
# Replace unwanted characters and retain only alpha characters bounded for ISO code.
|
117
|
+
country = country.gsub(/[^a-z]/,'')
|
118
|
+
iso_country = ISO3166::Country.search(country)
|
119
|
+
if iso_country == nil
|
120
|
+
raise ArgumentError, "Invalid format for country:'" + country + "'.Please follow ISO 2-letter ISO 3166-1 standard for representing country. eg: us"
|
121
|
+
end
|
102
122
|
|
103
|
-
|
104
|
-
country = country.gsub(/[^a-z]/,'')
|
105
|
-
iso_country = ISO3166::Country.search(country)
|
106
|
-
if iso_country == nil
|
107
|
-
raise ArgumentError, "Invalid format for country:'" + country + "'.Please follow ISO 2-letter ISO 3166-1 standard for representing country. eg: us"
|
123
|
+
return country
|
108
124
|
end
|
109
125
|
|
110
|
-
|
111
|
-
|
126
|
+
# Normalizes the given city and returns acceptable hashed city value
|
127
|
+
def self.normalize_city(city)
|
112
128
|
|
113
|
-
|
114
|
-
|
129
|
+
# Remove commonly occuring characters from city name.
|
130
|
+
city = city.gsub(/[0-9.\s\-()]/,'')
|
115
131
|
|
116
|
-
|
117
|
-
|
132
|
+
return city
|
133
|
+
end
|
118
134
|
|
119
|
-
|
120
|
-
|
135
|
+
# Normalizes the given currency code and returns acceptable hashed currency ISO code
|
136
|
+
def self.normalize_currency(currency)
|
121
137
|
|
122
|
-
|
123
|
-
|
138
|
+
# Retain only alpha characters bounded for ISO code.
|
139
|
+
currency = currency.gsub(/[^a-z]/,'')
|
124
140
|
|
125
|
-
|
126
|
-
|
141
|
+
iso_currency = Money::Currency.find(currency)
|
142
|
+
if iso_currency == nil
|
143
|
+
raise ArgumentError, "Invalid format for currency:'" + currency + "'.Please follow ISO 3-letter ISO 4217 standard for representing currency. Eg: usd"
|
144
|
+
end
|
127
145
|
|
128
|
-
|
129
|
-
|
130
|
-
raise ArgumentError, "Invalid format for currency:'" + currency + "'.Please follow ISO 3-letter ISO 4217 standard for representing currency. Eg: usd"
|
131
|
-
end
|
146
|
+
return currency;
|
147
|
+
end
|
132
148
|
|
133
|
-
|
134
|
-
|
149
|
+
# Normalizes the given email and returns acceptable hashed email value
|
150
|
+
def self.normalize_email(email)
|
135
151
|
|
136
|
-
|
137
|
-
|
152
|
+
if EMAIL_REGEX.match(email) == nil
|
153
|
+
return ArgumentError, "Invalid email format for the passed email:' + email + '.Please check the passed email format."
|
154
|
+
end
|
138
155
|
|
139
|
-
|
140
|
-
|
141
|
-
end
|
156
|
+
return email
|
157
|
+
end
|
142
158
|
|
143
|
-
|
144
|
-
|
159
|
+
# Normalizes the given gender and returns acceptable hashed gender value
|
160
|
+
def self.normalize_gender(gender)
|
145
161
|
|
146
|
-
|
147
|
-
|
162
|
+
# Replace extra characters with space, to bound under alpha characters set.
|
163
|
+
gender = gender.gsub(/[^a-z]/,'')
|
148
164
|
|
149
|
-
|
150
|
-
|
165
|
+
case gender
|
166
|
+
when 'female' , 'f'
|
167
|
+
gender = 'f'
|
168
|
+
when 'male' , 'm'
|
169
|
+
gender = 'm'
|
170
|
+
else
|
171
|
+
return nil
|
172
|
+
end
|
151
173
|
|
152
|
-
|
153
|
-
when 'female' , 'f'
|
154
|
-
gender = 'f'
|
155
|
-
when 'male' , 'm'
|
156
|
-
gender = 'm'
|
157
|
-
else
|
158
|
-
return nil
|
174
|
+
return gender
|
159
175
|
end
|
160
176
|
|
161
|
-
|
162
|
-
|
177
|
+
# Normalizes the given phone and returns acceptable hashed phone value
|
178
|
+
def self.normalize_phone(phone)
|
163
179
|
|
164
|
-
|
165
|
-
|
180
|
+
# Drop the spaces, hyphen and parenthesis from the Phone Number
|
181
|
+
normalized_phone = phone.gsub(PHONE_NUMBER_IGNORE_CHAR_SET, '')
|
166
182
|
|
167
|
-
|
168
|
-
|
183
|
+
if(is_international_number?(normalized_phone))
|
184
|
+
normalized_phone = normalized_phone.gsub(PHONE_NUMBER_DROP_PREFIX_ZEROS, '')
|
185
|
+
end
|
169
186
|
|
170
|
-
|
171
|
-
|
172
|
-
|
187
|
+
if normalized_phone.length < 7 || normalized_phone.length > 15
|
188
|
+
return nil;
|
189
|
+
end
|
173
190
|
|
174
|
-
|
175
|
-
return nil;
|
191
|
+
return normalized_phone
|
176
192
|
end
|
177
193
|
|
178
|
-
|
179
|
-
|
194
|
+
# Normalizes the given state and returns acceptable hashed state value
|
195
|
+
def self.normalize_state(state)
|
196
|
+
state = state.gsub(/[0-9.\s\-()]/,'')
|
180
197
|
|
181
|
-
|
182
|
-
|
183
|
-
state = state.gsub(/[0-9.\s\-()]/,'')
|
198
|
+
return state
|
199
|
+
end
|
184
200
|
|
185
|
-
|
186
|
-
|
201
|
+
# Normalizes the given zip and returns acceptable hashed zip code value
|
202
|
+
def self.normalize_zip(zip)
|
187
203
|
|
188
|
-
|
189
|
-
|
204
|
+
# Remove spaces from the Postal code
|
205
|
+
zip = zip.gsub(/[\s]/,'')
|
190
206
|
|
191
|
-
|
192
|
-
|
207
|
+
# If the zip code '-', we retain just the first part alone.
|
208
|
+
zip = zip.split('-')[0]
|
193
209
|
|
194
|
-
|
195
|
-
|
210
|
+
if zip.length < 2
|
211
|
+
return nil
|
212
|
+
end
|
196
213
|
|
197
|
-
|
198
|
-
return nil
|
214
|
+
return zip
|
199
215
|
end
|
200
216
|
|
201
|
-
|
202
|
-
|
217
|
+
# Boolean method which checks if a given number is represented in international format
|
218
|
+
# @param [String] phone_number that has to be tested.
|
219
|
+
# @return [TrueClass | FalseClass] boolean value representing if a number is international
|
220
|
+
def self.is_international_number?(phone_number)
|
221
|
+
|
222
|
+
# Drop upto 2 leading 0s from the number
|
223
|
+
phone_number = phone_number.gsub(PHONE_NUMBER_DROP_PREFIX_ZEROS, '')
|
203
224
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
def self.is_international_number?(phone_number)
|
225
|
+
if phone_number.start_with?('0')
|
226
|
+
return false;
|
227
|
+
end
|
208
228
|
|
209
|
-
|
210
|
-
|
229
|
+
if phone_number.start_with?('1') && US_PHONE_NUMBER_REGEX.match(phone_number) != nil
|
230
|
+
return false;
|
231
|
+
end
|
232
|
+
|
233
|
+
if INTL_PHONE_NUMBER_REGEX.match(phone_number) != nil
|
234
|
+
return true;
|
235
|
+
end
|
211
236
|
|
212
|
-
if phone_number.start_with?('0')
|
213
237
|
return false;
|
214
238
|
end
|
215
239
|
|
216
|
-
|
217
|
-
|
240
|
+
def self.normalize_f5(input)
|
241
|
+
input[0, 5]
|
218
242
|
end
|
219
243
|
|
220
|
-
|
221
|
-
|
244
|
+
def self.normalize_fi(fi)
|
245
|
+
fi[0, 1]
|
222
246
|
end
|
223
247
|
|
224
|
-
|
225
|
-
|
248
|
+
def self.normalize_dobd(dobd)
|
249
|
+
if dobd.length == 1
|
250
|
+
dobd = '0' + dobd
|
251
|
+
end
|
252
|
+
|
253
|
+
dobd_int = dobd.to_i
|
254
|
+
if dobd.length > 2 or dobd_int < 1 or dobd_int > 31
|
255
|
+
raise ArgumentError.new("Invalid dobd format: '#{dobd}'. Please pass in a valid date of birth day in 'DD' format.")
|
256
|
+
end
|
226
257
|
|
258
|
+
return dobd
|
259
|
+
end
|
260
|
+
|
261
|
+
def self.normalize_dobm(dobm)
|
262
|
+
if dobm.length == 1
|
263
|
+
dobm = '0' + dobm
|
264
|
+
end
|
265
|
+
|
266
|
+
dobm_int = dobm.to_i
|
267
|
+
if dobm.length > 2 or dobm_int < 1 or dobm_int > 12
|
268
|
+
raise ArgumentError.new("Invalid dobm format: '#{dobm}'. Please pass in a valid date of birth month in 'MM' format.")
|
269
|
+
end
|
270
|
+
|
271
|
+
return dobm
|
272
|
+
end
|
273
|
+
|
274
|
+
def self.normalize_doby(doby)
|
275
|
+
unless doby.match("^[0-9]{4}$")
|
276
|
+
raise ArgumentError.new("Invalid doby format: '#{doby}'. Please pass in a valid birth year in 'YYYY' format.")
|
277
|
+
end
|
278
|
+
doby
|
279
|
+
end
|
280
|
+
end
|
227
281
|
end
|
228
282
|
end
|