Skip to content

Commit 1ace4f0

Browse files
authored
Merge pull request #69 from segment-integrations/bsneed/recursive_map
Make property mappings recursive
2 parents faabf3f + fd1399f commit 1ace4f0

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ version: 2
33
jobs:
44
build_and_test:
55
macos:
6-
xcode: "11.0"
6+
xcode: "12.0"
77
steps:
88
- checkout
99
- run: xcrun simctl list
1010
- run:
1111
name: Install build dependencies
1212
command: |
1313
sudo gem install xcpretty
14-
sudo gem install cocoapods -v 1.8.4
14+
sudo gem install cocoapods -v 1.10.0
1515
- run:
1616
name: Fetch Cocoapods specs
1717
command: curl https://cocoapods-specs.circleci.com/fetch-cocoapods-repo-from-s3.sh | bash -s cf

Example/Tests/Tests.m

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@
143143
@"currency" : @"USD",
144144
@"item_category" : @"Games",
145145
@"items" : @{
146-
@"product_id" : @"2013294",
147-
@"category" : @"Games",
148-
@"name" : @"Monopoly: 3rd Edition",
149-
@"brand" : @"Hasbros",
146+
@"item_id" : @"2013294",
147+
@"item_category" : @"Games",
148+
@"item_name" : @"Monopoly: 3rd Edition",
149+
@"item_brand" : @"Hasbros",
150150
@"price" : @"21.99",
151151
@"quantity" : @"1"
152152
}
@@ -178,7 +178,7 @@
178178
@"sku" : @"G-32",
179179
@"item_category" : @"Games",
180180
@"item_name" : @"Monopoly: 3rd Edition",
181-
@"brand" : @"Hasbro",
181+
@"item_brand" : @"Hasbro",
182182
@"variant" : @"200 pieces",
183183
@"price" : @18.99,
184184
@"quantity" : @1,
@@ -215,7 +215,7 @@
215215
@"sku" : @"G-32",
216216
@"item_category" : @"Games",
217217
@"item_name" : @"Monopoly 3rd Edition",
218-
@"brand" : @"Hasbro",
218+
@"item_brand" : @"Hasbro",
219219
@"variant" : @"200 pieces",
220220
@"price" : @18.99,
221221
@"quantity" : @1,
@@ -254,7 +254,7 @@
254254
@"sku" : @"G-32",
255255
@"item_category" : @"Games",
256256
@"item_name" : @"Monopoly: 3rd Edition",
257-
@"brand" : @"Hasbro",
257+
@"item_brand" : @"Hasbro",
258258
@"variant" : @"200 pieces",
259259
@"price" : @18.99,
260260
@"quantity" : @1,
@@ -292,7 +292,7 @@
292292
@"sku" : @"G-32",
293293
@"item_category" : @"Games",
294294
@"item_name" : @"Monopoly: 3rd Edition",
295-
@"brand" : @"Hasbro",
295+
@"item_brand" : @"Hasbro",
296296
@"variant" : @"200 pieces",
297297
@"price" : @18.99,
298298
@"quantity" : @1,
@@ -338,10 +338,10 @@
338338
@"currency" : @"USD",
339339
@"item_category" : @"Games",
340340
@"items" : @{
341-
@"product_id" : @"2013294",
342-
@"category" : @"Games",
343-
@"name" : @"Monopoly: 3rd Edition",
344-
@"brand" : @"Hasbros",
341+
@"item_id" : @"2013294",
342+
@"item_category" : @"Games",
343+
@"item_name" : @"Monopoly: 3rd Edition",
344+
@"item_brand" : @"Hasbros",
345345
@"price" : @"21.99",
346346
@"quantity" : @"1"
347347
}
@@ -431,10 +431,10 @@
431431
@"list_id" : @"hot_deals_1",
432432
@"item_category" : @"Deals",
433433
@"items" : @{
434-
@"product_id" : @"2013294",
435-
@"category" : @"Games",
436-
@"name" : @"Monopoly: 3rd Edition",
437-
@"brand" : @"Hasbros",
434+
@"item_id" : @"2013294",
435+
@"item_category" : @"Games",
436+
@"item_name" : @"Monopoly: 3rd Edition",
437+
@"item_brand" : @"Hasbros",
438438
@"price" : @"21.99",
439439
@"quantity" : @"1"
440440
}
@@ -471,7 +471,7 @@
471471
@"sku" : @"G-32",
472472
@"item_category" : @"Games",
473473
@"item_name" : @"Monopoly: 3rd Edition",
474-
@"brand" : @"Hasbro",
474+
@"item_brand" : @"Hasbro",
475475
@"variant" : @"200 pieces",
476476
@"price" : @18.99,
477477
@"quantity" : @1,
@@ -511,7 +511,7 @@
511511
@"sku" : @"G-32",
512512
@"item_category" : @"Games",
513513
@"item_name" : @"Monopoly: 3rd Edition",
514-
@"brand" : @"Hasbro",
514+
@"item_brand" : @"Hasbro",
515515
@"variant" : @"200 pieces",
516516
@"price" : @18.99,
517517
@"url" : @"https://www.company.com/product/path",
@@ -547,7 +547,7 @@
547547
@"sku" : @"G-32",
548548
@"item_category" : @"Games",
549549
@"item_name" : @"Monopoly: 3rd Edition",
550-
@"brand" : @"Hasbro",
550+
@"item_brand" : @"Hasbro",
551551
@"variant" : @"200 pieces",
552552
@"price" : @18.99,
553553
@"url" : @"https://www.company.com/product/path",
@@ -577,7 +577,7 @@
577577
integrations:@{}];
578578
[integration screen:payload];
579579
// screen is set async, so need to pump the runloop.
580-
[NSRunLoop.mainRunLoop runUntilDate:[NSDate distantPast]];
580+
[NSRunLoop.mainRunLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:5]];
581581
[verify(mockFirebase) logEventWithName:@"screen_view" parameters:@{
582582
kFIRParameterScreenName : @"Home screen"
583583
}];

Segment-Firebase/Classes/SEGFirebaseIntegration.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ - (NSDictionary *)returnMappedFirebaseParameters:(NSDictionary *)properties
147147
kFIRParameterItemCategory, @"category",
148148
kFIRParameterItemID, @"product_id",
149149
kFIRParameterItemName, @"name",
150+
kFIRParameterItemBrand, @"brand",
150151
kFIRParameterPrice, @"price",
151152
kFIRParameterQuantity, @"quantity",
152153
kFIRParameterSearchTerm, @"query",
@@ -168,6 +169,20 @@ + (NSDictionary *)mapToFirebaseParameters:(NSDictionary *)properties withMap:(NS
168169
id data = [properties objectForKey:original];
169170
if (data) {
170171
[mappedParams removeObjectForKey:original];
172+
if ([data isKindOfClass:[NSDictionary class]]) {
173+
data = [self mapToFirebaseParameters:data withMap:mapper];
174+
} else if ([data isKindOfClass: [NSArray class]]) {
175+
NSMutableArray *newArray = [NSMutableArray array];
176+
for (id entry in newArray) {
177+
if ([entry isKindOfClass:[NSDictionary class]]) {
178+
id newEntry = [self mapToFirebaseParameters:entry withMap:mapper];
179+
[newArray addObject:newEntry];
180+
} else {
181+
[newArray addObject:entry];
182+
}
183+
}
184+
data = newArray;
185+
}
171186
[mappedParams setObject:data forKey:new];
172187
}
173188
}];

0 commit comments

Comments
 (0)