-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Renemari Padillo
committed
Aug 9, 2016
1 parent
132bb7b
commit dd4fc65
Showing
19 changed files
with
493 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Created by Ahmed Nawar on 2/24/16. | ||
// Copyright © 2016 Ahmed Nawar. All rights reserved. | ||
// Umbrella header file | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import "Branch.h" | ||
#import "BNCConfig.h" | ||
#import "BranchView.h" | ||
#import "BranchViewHandler.h" | ||
#import "BranchLinkProperties.h" | ||
#import "BranchUniversalObject.h" | ||
#import "BranchActivityItemProvider.h" | ||
#import "BranchDeepLinkingController.h" | ||
#import "BranchCSSearchableItemAttributeSet.h" |
16 changes: 16 additions & 0 deletions
16
src/ios/dependencies/Branch-SDK/Requests/BranchApplyPromoCodeRequest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// BranchApplyPromoCodeRequest.h | ||
// Branch-TestBed | ||
// | ||
// Created by Graham Mueller on 5/26/15. | ||
// Copyright (c) 2015 Branch Metrics. All rights reserved. | ||
// | ||
|
||
#import "BNCServerRequest.h" | ||
#import "Branch.h" | ||
|
||
@interface BranchApplyPromoCodeRequest : BNCServerRequest | ||
|
||
- (id)initWithCode:(NSString *)code useOld:(BOOL)useOld callback:(callbackWithParams)callback; | ||
|
||
@end |
83 changes: 83 additions & 0 deletions
83
src/ios/dependencies/Branch-SDK/Requests/BranchApplyPromoCodeRequest.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// BranchApplyPromoCodeRequest.m | ||
// Branch-TestBed | ||
// | ||
// Created by Graham Mueller on 5/26/15. | ||
// Copyright (c) 2015 Branch Metrics. All rights reserved. | ||
// | ||
|
||
#import "BranchApplyPromoCodeRequest.h" | ||
#import "BNCPreferenceHelper.h" | ||
#import "BNCError.h" | ||
#import "BranchConstants.h" | ||
|
||
@interface BranchApplyPromoCodeRequest () | ||
|
||
@property (strong, nonatomic) NSString *code; | ||
@property (strong, nonatomic) callbackWithParams callback; | ||
@property (assign, nonatomic) BOOL useOld; | ||
|
||
@end | ||
|
||
@implementation BranchApplyPromoCodeRequest | ||
|
||
- (id)initWithCode:(NSString *)code useOld:(BOOL)useOld callback:(callbackWithParams)callback { | ||
if (self = [super init]) { | ||
_code = code; | ||
_callback = callback; | ||
_useOld = useOld; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key callback:(BNCServerCallback)callback { | ||
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper]; | ||
NSDictionary *params = @{ | ||
BRANCH_REQUEST_KEY_BRANCH_IDENTITY: preferenceHelper.identityID, | ||
BRANCH_REQUEST_KEY_DEVICE_FINGERPRINT_ID: preferenceHelper.deviceFingerprintID, | ||
BRANCH_REQUEST_KEY_SESSION_ID: preferenceHelper.sessionID | ||
}; | ||
|
||
NSString *endpoint = self.useOld ? BRANCH_REQUEST_ENDPOINT_APPLY_REFERRAL_CODE : BRANCH_REQUEST_ENDPOINT_APPLY_PROMO_CODE; | ||
NSString *url = [NSString stringWithFormat:@"%@/%@", [preferenceHelper getAPIURL:endpoint], self.code]; | ||
[serverInterface postRequest:params url:url key:key callback:callback]; | ||
} | ||
|
||
- (void)processResponse:(BNCServerResponse *)response error:(NSError *)error { | ||
if (error) { | ||
if (self.callback) { | ||
self.callback(nil, error); | ||
} | ||
return; | ||
} | ||
|
||
NSString *codeKey = self.useOld ? BRANCH_RESPONSE_KEY_REFERRAL_CODE : BRANCH_RESPONSE_KEY_PROMO_CODE; | ||
if (!response.data[codeKey]) { | ||
error = [NSError errorWithDomain:BNCErrorDomain code:BNCInvalidPromoCodeError userInfo:@{ NSLocalizedDescriptionKey: @"Promo code is invalid - it may have already been used or the code might not exist" }]; | ||
} | ||
|
||
if (self.callback) { | ||
self.callback(response.data, error); | ||
} | ||
} | ||
|
||
#pragma mark - NSCoding methods | ||
|
||
- (id)initWithCoder:(NSCoder *)decoder { | ||
if (self = [super initWithCoder:decoder]) { | ||
_code = [decoder decodeObjectForKey:@"code"]; | ||
_useOld = [decoder decodeBoolForKey:@"useOld"]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)encodeWithCoder:(NSCoder *)coder { | ||
[super encodeWithCoder:coder]; | ||
|
||
[coder encodeObject:self.code forKey:@"code"]; | ||
[coder encodeBool:self.useOld forKey:@"useOld"]; | ||
} | ||
|
||
@end |
16 changes: 16 additions & 0 deletions
16
src/ios/dependencies/Branch-SDK/Requests/BranchGetPromoCodeRequest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// BranchGetPromoCodeRequest.h | ||
// Branch-TestBed | ||
// | ||
// Created by Graham Mueller on 5/26/15. | ||
// Copyright (c) 2015 Branch Metrics. All rights reserved. | ||
// | ||
|
||
#import "BNCServerRequest.h" | ||
#import "Branch.h" | ||
|
||
@interface BranchGetPromoCodeRequest : BNCServerRequest | ||
|
||
- (id)initWithUsageType:(BranchPromoCodeUsageType)usageType rewardLocation:(BranchPromoCodeRewardLocation)rewardLocation amount:(NSInteger)amount bucket:(NSString *)bucket prefix:(NSString *)prefix expiration:(NSDate *)expiration useOld:(BOOL)useOld callback:(callbackWithParams)callback; | ||
|
||
@end |
Oops, something went wrong.