Skip to content

Commit

Permalink
Merge pull request #18 from qonversion/release/1.0.0
Browse files Browse the repository at this point in the history
Debug mode
  • Loading branch information
smejl authored Apr 20, 2020
2 parents 13ab2b0 + b575504 commit 2335c3f
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Qonversion.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Qonversion'
s.version = '1.0.0-beta.3'
s.version = '1.0.0-beta.4'
s.summary = 'qonversion.io'
s.description = <<-DESC
Deep Analytics for iOS Subscriptions
Expand Down
10 changes: 7 additions & 3 deletions Qonversion.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
45202189244DD02F00C1A928 /* QonversionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 45202188244DD02F00C1A928 /* QonversionTests.m */; };
459DAB73243E329F0011ECF3 /* Qonversion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 459DAB69243E329F0011ECF3 /* Qonversion.framework */; };
459DAB9A243E333C0011ECF3 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 459DAB97243E333C0011ECF3 /* README.md */; };
459DAB9B243E333C0011ECF3 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 459DAB98243E333C0011ECF3 /* LICENSE */; };
Expand Down Expand Up @@ -52,6 +53,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
45202188244DD02F00C1A928 /* QonversionTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QonversionTests.m; sourceTree = "<group>"; };
459DAB69243E329F0011ECF3 /* Qonversion.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Qonversion.framework; sourceTree = BUILT_PRODUCTS_DIR; };
459DAB72243E329F0011ECF3 /* QonversionTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = QonversionTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
459DAB79243E329F0011ECF3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -151,6 +153,7 @@
459DAC0A243E4D420011ECF3 /* Helpers */,
459DAC07243E4AF20011ECF3 /* Resources */,
459DAC05243E49C20011ECF3 /* QonversionMapperTests.m */,
45202188244DD02F00C1A928 /* QonversionTests.m */,
459DAB79243E329F0011ECF3 /* Info.plist */,
);
path = QonversionTests;
Expand Down Expand Up @@ -232,7 +235,7 @@
459DABEC243E35BC0011ECF3 /* Models */ = {
isa = PBXGroup;
children = (
459DAC12243E61BF0011ECF3 /* QonversionCheckResult */,
45BA20412444BA490046E6C9 /* QonversionCheckResult */,
459DAC11243E61A80011ECF3 /* RenewalProductDetails */,
);
path = Models;
Expand Down Expand Up @@ -275,14 +278,14 @@
name = RenewalProductDetails;
sourceTree = "<group>";
};
459DAC12243E61BF0011ECF3 /* QonversionCheckResult */ = {
45BA20412444BA490046E6C9 /* QonversionCheckResult */ = {
isa = PBXGroup;
children = (
459DABF0243E35BC0011ECF3 /* QonversionCheckResult.h */,
459DABF2243E35BC0011ECF3 /* QonversionCheckResult+Protected.h */,
459DABED243E35BC0011ECF3 /* QonversionCheckResult.m */,
);
path = QonversionCheckResult;
name = QonversionCheckResult;
sourceTree = "<group>";
};
45CC2EF1244085E4005CD107 /* .github */ = {
Expand Down Expand Up @@ -444,6 +447,7 @@
buildActionMask = 2147483647;
files = (
459DAC0D243E4D610011ECF3 /* XCTestCase+TestJSON.m in Sources */,
45202189244DD02F00C1A928 /* QonversionTests.m in Sources */,
459DAC06243E49C20011ECF3 /* QonversionMapperTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
1 change: 1 addition & 0 deletions QonversionTests/Helpers/XCTestCase+TestJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

- (id)JSONObjectFromContentsOfFile:(NSString *)filePath;
- (id)fileDataFromContentsOfFile:(NSString *)filePath;
- (id)JSONObjectFromData:(NSData *)data;

@end
8 changes: 6 additions & 2 deletions QonversionTests/Helpers/XCTestCase+TestJSON.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ @implementation XCTestCase (TestJSON)

- (id)JSONObjectFromContentsOfFile:(NSString *)filePath {
NSData *fileData = [self fileDataFromContentsOfFile:filePath];
NSDictionary *object = [NSJSONSerialization JSONObjectWithData:fileData options:kNilOptions error:nil];
return object;

return [NSJSONSerialization JSONObjectWithData:fileData options:kNilOptions error:nil];
}

- (id)fileDataFromContentsOfFile:(NSString *)filePath {
Expand All @@ -18,4 +18,8 @@ - (id)fileDataFromContentsOfFile:(NSString *)filePath {
return [NSData dataWithContentsOfFile:pathToFile];
}

- (id)JSONObjectFromData:(NSData *)data {
return [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
}

@end
45 changes: 45 additions & 0 deletions QonversionTests/QonversionTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#import <XCTest/XCTest.h>
#import "Qonversion.h"
#import "XCTestCase+TestJSON.h"

@interface Qonversion (Tests)
+ (NSURLRequest *)makePostRequestWithEndpoint:(NSString *)endpoint andBody:(NSDictionary *)body;
@end

@interface QonversionTests : XCTestCase

@end

@implementation QonversionTests

- (void)setUp {
[super setUp];

// Set default value before
[Qonversion setDebugMode:NO];
}

- (void)testThatDebugModeSetDefaultValueAsNoCorrectly {
[Qonversion launchWithKey:@"key" userID:@"user"];
NSURLRequest *request = [Qonversion makePostRequestWithEndpoint:@"dummy" andBody:@{}];
XCTAssertNotNil(request);
NSDictionary *body = [self JSONObjectFromData:request.HTTPBody];
XCTAssertNotNil(body);

NSNumber *debugMode = body[@"debug_mode"];
XCTAssertEqual(debugMode.copy, @NO);
}

- (void)testThatDebugModeSetCorrectly {
[Qonversion setDebugMode:YES];
[Qonversion launchWithKey:@"key" userID:@"user"];
NSURLRequest *request = [Qonversion makePostRequestWithEndpoint:@"dummy" andBody:@{}];
XCTAssertNotNil(request);
NSDictionary *body = [self JSONObjectFromData:request.HTTPBody];
XCTAssertNotNil(body);

NSNumber *debugMode = body[@"debug_mode"];
XCTAssertEqual(debugMode, @YES);
}

@end
9 changes: 7 additions & 2 deletions Sources/Qonversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ typedef NS_ENUM(NSInteger, QAttributionProvider) {

@interface Qonversion : NSObject

+ (void)launchWithKey:(nonnull NSString *)key autoTrackPurchases:(BOOL)autoTrack
DEPRECATED_MSG_ATTRIBUTE("Use `launchWithKey:completion:` or `launchWithKey:autoTrackPurchases:completion:` method instead.");
/**
Sets the environment for receipt.
@param debugMode true If your app run under debug mode, default: false
@see [Setting Debug Mode](https://docs.qonversion.io/getting-started/debug-mode)
*/

+ (void)setDebugMode:(BOOL) debugMode;

/**
Launches Qonversion SDK with the given project key, you can get one in your account on qonversion.io.
Expand Down
23 changes: 16 additions & 7 deletions Sources/Qonversion.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#import "UserInfo.h"
#import "QonversionMapper.h"

static NSString * const kBaseURL = @"https://apib.qonversion.io/";
static NSString * const kBaseURL = @"https://api.qonversion.io/";
static NSString * const kInitEndpoint = @"init";
static NSString * const kPurchaseEndpoint = @"purchase";
static NSString * const kCheckEndpoint = @"check";
Expand All @@ -21,15 +21,10 @@ @implementation Qonversion

static NSString* apiKey;
static BOOL autoTrackPurchases;
static BOOL _debugMode = NO;

// MARK: - Public

+ (void)launchWithKey:(nonnull NSString *)key autoTrackPurchases:(BOOL)autoTrack {
[self launchWithKey:key autoTrackPurchases:autoTrack completion:^(NSString * _Nonnull uid) {
// dummy
}];
}

+ (void)launchWithKey:(nonnull NSString *)key completion:(nullable void (^)(NSString *uid))completion {
[self launchWithKey:key autoTrackPurchases:YES completion:completion];
}
Expand Down Expand Up @@ -162,6 +157,14 @@ + (void)serviceLogPurchase:(SKProduct *)product transaction:(SKPaymentTransactio

}

if (@available(iOS 13.0, *)) {
NSString *countryCode = SKPaymentQueue.defaultQueue.storefront.countryCode ?: @"";

if (countryCode.length > 0) {
inappDict[@"country"] = countryCode;
}
}

NSDictionary *body = @{@"inapp": inappDict, @"d": UserInfo.overallData};

NSURLRequest *request = [self makePostRequestWithEndpoint:kPurchaseEndpoint andBody:body];
Expand Down Expand Up @@ -196,6 +199,8 @@ + (NSURLRequest *)makePostRequestWithEndpoint:(NSString *)endpoint andBody:(NSDi

NSMutableDictionary *mutableBody = body.mutableCopy;

[mutableBody setObject:[[NSNumber alloc] initWithBool:_debugMode] forKey:@"debug_mode"];

[mutableBody setObject:apiKey forKey:@"access_token"];
[mutableBody setObject:kSDKVersion forKey:@"v"];
if (Keeper.userID && Keeper.userID.length > 2) {
Expand Down Expand Up @@ -298,4 +303,8 @@ + (NSURLSession *)session {
return [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.defaultSessionConfiguration];;
}

+ (void)setDebugMode:(BOOL) debugMode {
_debugMode = debugMode;
}

@end

0 comments on commit 2335c3f

Please sign in to comment.