Skip to content

Commit e2e2524

Browse files
committed
SDK-479 initial latd implementation
1 parent a4be8ff commit e2e2524

22 files changed

+248
-51
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// BranchLastAttributedTouchDataTests.m
3+
// Branch-SDK-Tests
4+
//
5+
// Created by Ernest Cho on 9/18/19.
6+
// Copyright © 2019 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "BNCJsonLoader.h"
11+
#import "BranchLastAttributedTouchData.h"
12+
13+
@interface BranchLastAttributedTouchDataTests : XCTestCase
14+
15+
@end
16+
17+
@implementation BranchLastAttributedTouchDataTests
18+
19+
- (void)setUp {
20+
// Put setup code here. This method is called before the invocation of each test method in the class.
21+
}
22+
23+
- (void)tearDown {
24+
// Put teardown code here. This method is called after the invocation of each test method in the class.
25+
}
26+
27+
- (void)testBuildFromJSON {
28+
NSDictionary *json = [BNCJsonLoader dictionaryFromJSONFileNamed:@"latd"];
29+
XCTAssertNotNil(json);
30+
31+
BranchLastAttributedTouchData *latd = [BranchLastAttributedTouchData buildFromJSON:json];
32+
XCTAssertNotNil(latd);
33+
XCTAssertNotNil(latd.lastAttributedTouchJSON);
34+
XCTAssertNotNil(latd.attributionWindow);
35+
}
36+
37+
- (void)testBuildFromJSON_EmptyData {
38+
NSDictionary *json = [BNCJsonLoader dictionaryFromJSONFileNamed:@"latd_empty_data"];
39+
XCTAssertNotNil(json);
40+
41+
BranchLastAttributedTouchData *latd = [BranchLastAttributedTouchData buildFromJSON:json];
42+
XCTAssertNotNil(latd);
43+
XCTAssertTrue(latd.lastAttributedTouchJSON.count == 0);
44+
}
45+
46+
- (void)testBuildFromJSON_MissingData {
47+
NSDictionary *json = [BNCJsonLoader dictionaryFromJSONFileNamed:@"latd_missing_data"];
48+
XCTAssertNotNil(json);
49+
50+
BranchLastAttributedTouchData *latd = [BranchLastAttributedTouchData buildFromJSON:json];
51+
XCTAssertNil(latd);
52+
}
53+
54+
- (void)testBuildFromJSON_MissingWindow {
55+
NSDictionary *json = [BNCJsonLoader dictionaryFromJSONFileNamed:@"latd_missing_window"];
56+
XCTAssertNotNil(json);
57+
58+
BranchLastAttributedTouchData *latd = [BranchLastAttributedTouchData buildFromJSON:json];
59+
XCTAssertNotNil(latd);
60+
XCTAssertNil(latd.attributionWindow);
61+
}
62+
63+
@end

Branch-SDK/Branch-SDK/Branch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#import "BranchShareLink.h"
3636
#import "BranchUniversalObject.h"
3737
#import "BranchCrossPlatformID.h"
38-
#import "BranchLastTouchAttributionData.h"
38+
#import "BranchLastAttributedTouchData.h"
3939
#import "UIViewController+Branch.h"
4040

4141
/**

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,9 @@ - (void)requestCrossPlatformIdDataWithCompletion:(void(^) (BranchCrossPlatformID
13531353
}
13541354

13551355
- (void)requestLastTouchAttributedDataWithCompletion:(void(^) (NSDictionary *ltad, NSNumber *attributionWindow))completion {
1356-
1356+
[BranchLastAttributedTouchData requestLastTouchAttributedData:self.serverInterface key:self.class.branchKey completion:^(BranchLastAttributedTouchData * _Nonnull latd) {
1357+
1358+
}];
13571359
}
13581360

13591361
#pragma mark - ShortUrl methods
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// BranchLastTouchAttributionData.h
3+
// Branch
4+
//
5+
// Created by Ernest Cho on 9/13/19.
6+
// Copyright © 2019 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "BNCServerInterface.h"
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
@interface BranchLastAttributedTouchData : NSObject
15+
16+
// free-form JSON
17+
@property (nonatomic, strong, readonly) NSDictionary *lastAttributedTouchJSON;
18+
19+
@property (nonatomic, copy, readonly) NSNumber *attributionWindow;
20+
21+
+ (BranchLastAttributedTouchData *)buildFromJSON:(NSDictionary *)json;
22+
23+
+ (void)requestLastTouchAttributedData:(BNCServerInterface *)serverInterface key:(NSString *)key completion:(void(^) (BranchLastAttributedTouchData *latd))completion;
24+
25+
@end
26+
27+
NS_ASSUME_NONNULL_END
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// BranchLastAttributedTouchData.m
3+
// Branch
4+
//
5+
// Created by Ernest Cho on 9/13/19.
6+
// Copyright © 2019 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import "BranchLastAttributedTouchData.h"
10+
#import "BranchLATDRequest.h"
11+
#import "BNCJSONUtility.h"
12+
13+
@implementation BranchLastAttributedTouchData
14+
15+
+ (BranchLastAttributedTouchData *)buildFromJSON:(NSDictionary *)json {
16+
BranchLastAttributedTouchData *latd = [BranchLastAttributedTouchData new];
17+
18+
latd->_lastAttributedTouchJSON = [BNCJSONUtility dictionaryForKey:@"last_attributed_touch_data" json:json];
19+
latd->_attributionWindow = [BNCJSONUtility numberForKey:@"attribution_window" json:json];
20+
21+
// only the free form json is required
22+
if (latd.lastAttributedTouchJSON) {
23+
return latd;
24+
}
25+
return nil;
26+
}
27+
28+
+ (void)requestLastTouchAttributedData:(BNCServerInterface *)serverInterface key:(NSString *)key completion:(void(^) (BranchLastAttributedTouchData *ltad))completion {
29+
BranchLATDRequest *request = [BranchLATDRequest new];
30+
[request makeRequest:serverInterface key:key callback:^(BNCServerResponse *response, NSError *error) {
31+
32+
// error is logged by the network service, skip parsing on error
33+
if (error) {
34+
if (completion) {
35+
completion(nil);
36+
}
37+
return;
38+
}
39+
40+
BranchLastAttributedTouchData *latd = [self buildFromJSON:response.data];
41+
if (completion) {
42+
completion(latd);
43+
}
44+
}];
45+
}
46+
47+
@end

Branch-SDK/Branch-SDK/BranchLastTouchAttributionData.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

Branch-SDK/Branch-SDK/BranchLastTouchAttributionData.m

Lines changed: 0 additions & 13 deletions
This file was deleted.

Branch-SDK/Branch-SDK/Networking/Requests/BranchCPIDRequest.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
#import "BNCPreferenceHelper.h"
1111
#import "BranchConstants.h"
1212

13-
@interface BranchCPIDRequest()
14-
15-
@end
16-
1713
@implementation BranchCPIDRequest
1814

1915
- (NSString *)serverURL {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// BranchLATDRequest.h
3+
// Branch
4+
//
5+
// Created by Ernest Cho on 9/18/19.
6+
// Copyright © 2019 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#import "BNCServerRequest.h"
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
@interface BranchLATDRequest : BNCServerRequest
15+
16+
@end
17+
18+
NS_ASSUME_NONNULL_END
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// BranchLATDRequest.m
3+
// Branch
4+
//
5+
// Created by Ernest Cho on 9/18/19.
6+
// Copyright © 2019 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import "BranchLATDRequest.h"
10+
#import "BNCPreferenceHelper.h"
11+
#import "BranchConstants.h"
12+
13+
@implementation BranchLATDRequest
14+
15+
- (NSString *)serverURL {
16+
return [[BNCPreferenceHelper preferenceHelper] getAPIURL:BRANCH_REQUEST_ENDPOINT_LATD];
17+
}
18+
19+
// all required fields for this request is added by BNCServerInterface
20+
- (NSMutableDictionary *)buildRequestParams {
21+
NSMutableDictionary *params = [NSMutableDictionary new];
22+
return params;
23+
}
24+
25+
- (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key callback:(BNCServerCallback)callback {
26+
NSDictionary *params = [self buildRequestParams];
27+
[serverInterface postRequest:params url:[self serverURL] key:key callback:callback];
28+
}
29+
30+
// unused, callee handles parsing the json response
31+
- (void)processResponse:(BNCServerResponse *)response error:(NSError *)error { }
32+
33+
@end

0 commit comments

Comments
 (0)