Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magnitude separation try #375

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Amplitude.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "E98C05221A48E7FE00800C63"
BuildableName = "libAmplitude.a"
BlueprintName = "Amplitude"
ReferencedContainer = "container:Amplitude.xcodeproj">
BlueprintName = "Magnitude"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
Expand All @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -47,12 +45,10 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "E98C05221A48E7FE00800C63"
BuildableName = "libAmplitude.a"
BlueprintName = "Amplitude"
ReferencedContainer = "container:Amplitude.xcodeproj">
BlueprintName = "Magnitude"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand All @@ -65,8 +61,8 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "E98C05221A48E7FE00800C63"
BuildableName = "libAmplitude.a"
BlueprintName = "Amplitude"
ReferencedContainer = "container:Amplitude.xcodeproj">
BlueprintName = "Magnitude"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "343AB4161CC99F4F00962943"
BuildableName = "Amplitude.framework"
BlueprintName = "AmplitudeFramework"
ReferencedContainer = "container:Amplitude.xcodeproj">
BlueprintName = "MagnitudeFramework"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
Expand All @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -47,12 +45,10 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "343AB4161CC99F4F00962943"
BuildableName = "Amplitude.framework"
BlueprintName = "AmplitudeFramework"
ReferencedContainer = "container:Amplitude.xcodeproj">
BlueprintName = "MagnitudeFramework"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand All @@ -65,8 +61,8 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "343AB4161CC99F4F00962943"
BuildableName = "Amplitude.framework"
BlueprintName = "AmplitudeFramework"
ReferencedContainer = "container:Amplitude.xcodeproj">
BlueprintName = "MagnitudeFramework"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
BlueprintIdentifier = "60F36EE11E2EAC8C00BA4203"
BuildableName = "AmplitudeTVOS.framework"
BlueprintName = "AmplitudeTVOS"
ReferencedContainer = "container:Amplitude.xcodeproj">
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
Expand All @@ -27,29 +27,27 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "60F36EE11E2EAC8C00BA4203"
BuildableName = "AmplitudeTVOS.framework"
BlueprintName = "AmplitudeTVOS"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "600CBC5B1E2EF5B0001F58A9"
BuildableName = "AmplitudeTVOSTests.xctest"
BlueprintName = "AmplitudeTVOSTests"
ReferencedContainer = "container:Amplitude.xcodeproj">
BlueprintName = "MagnitudeTVOSTests"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "60F36EE11E2EAC8C00BA4203"
BuildableName = "AmplitudeTVOS.framework"
BlueprintName = "AmplitudeTVOS"
ReferencedContainer = "container:Amplitude.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -67,11 +65,9 @@
BlueprintIdentifier = "60F36EE11E2EAC8C00BA4203"
BuildableName = "AmplitudeTVOS.framework"
BlueprintName = "AmplitudeTVOS"
ReferencedContainer = "container:Amplitude.xcodeproj">
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand All @@ -85,7 +81,7 @@
BlueprintIdentifier = "60F36EE11E2EAC8C00BA4203"
BuildableName = "AmplitudeTVOS.framework"
BlueprintName = "AmplitudeTVOS"
ReferencedContainer = "container:Amplitude.xcodeproj">
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "E98C052D1A48E7FE00800C63"
BuildableName = "AmplitudeTests.xctest"
BlueprintName = "AmplitudeTests"
ReferencedContainer = "container:Amplitude.xcodeproj">
BlueprintName = "MagnitudeTests"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
Expand All @@ -27,29 +27,27 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E98C052D1A48E7FE00800C63"
BuildableName = "AmplitudeTests.xctest"
BlueprintName = "MagnitudeTests"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E98C052D1A48E7FE00800C63"
BuildableName = "AmplitudeTests.xctest"
BlueprintName = "AmplitudeTests"
ReferencedContainer = "container:Amplitude.xcodeproj">
BlueprintName = "MagnitudeTests"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E98C052D1A48E7FE00800C63"
BuildableName = "AmplitudeTests.xctest"
BlueprintName = "AmplitudeTests"
ReferencedContainer = "container:Amplitude.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -66,8 +64,8 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "E98C052D1A48E7FE00800C63"
BuildableName = "AmplitudeTests.xctest"
BlueprintName = "AmplitudeTests"
ReferencedContainer = "container:Amplitude.xcodeproj">
BlueprintName = "MagnitudeTests"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
Expand Down Expand Up @@ -116,8 +114,8 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "E98C052D1A48E7FE00800C63"
BuildableName = "AmplitudeTests.xctest"
BlueprintName = "AmplitudeTests"
ReferencedContainer = "container:Amplitude.xcodeproj">
BlueprintName = "MagnitudeTests"
ReferencedContainer = "container:Magnitude.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions Magnitude/AMPEventUploadRequest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// AMPEventUploadRequest.h
// Amplitude
//
// Created by Francesco Perrotti Garcia on 10/24/18.
// Copyright © 2018 Amplitude. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_SWIFT_NAME(EventUploadRequest)
@interface AMPEventUploadRequest : NSObject

@property (nonatomic, assign) int apiVersion;
@property (nonatomic, strong) NSString *apiKey;
@property (nonatomic, strong) NSString *events;
@property (nonatomic, assign) long long uploadTime;
@property (nonatomic, strong) NSString *checksum;
@property (nonatomic, strong) NSURL *url;

- (instancetype)initWithApiVersion: (int) apiVersion
apiKey: (NSString *) apiKey
events: (NSString *) events
uploadTime: (long long) uploadTime
checksum: (NSString *)checksum
url: (NSURL *)url;
@end
43 changes: 43 additions & 0 deletions Magnitude/AMPEventUploadRequest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// AMPEventUploadRequest.m
// Amplitude
//
// Created by Francesco Perrotti Garcia on 10/24/18.
// Copyright © 2018 Amplitude. All rights reserved.
//

#import "AMPEventUploadRequest.h"
#import "AMPARCMacros.h"

@implementation AMPEventUploadRequest

@synthesize apiKey = _apiKey;
@synthesize events = _events;
@synthesize checksum = _checksum;
@synthesize url = _url;

- (instancetype)initWithApiVersion: (int) apiVersion
apiKey: (NSString *) apiKey
events: (NSString *) events
uploadTime: (long long) uploadTime
checksum: (NSString *)checksum
url: (NSURL *)url {
self = [super init];
_apiVersion = apiVersion;
_apiKey = apiKey;
_events = events;
_uploadTime = uploadTime;
_checksum = checksum;
_url = url;
return self;
}

- (void) dealloc {
SAFE_ARC_RELEASE(_apiKey);
SAFE_ARC_RELEASE(_events);
SAFE_ARC_RELEASE(_checksum);
SAFE_ARC_RELEASE(_url);
SAFE_ARC_SUPER_DEALLOC();
}

@end
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions Magnitude/AMPNSURLSessionNetworkClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// AMPNSURLSessionNetworkClient.h
// Amplitude
//
// Created by Francesco Perrotti Garcia on 10/24/18.
// Copyright © 2018 Amplitude. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AMPNetworkClient.h"

@interface AMPNSURLSessionNetworkClient : NSObject <AMPNetworkClient>

- (instancetype) init;

@end
60 changes: 60 additions & 0 deletions Magnitude/AMPNSURLSessionNetworkClient.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// AMPNSURLSessionNetworkClient.m
// Amplitude
//
// Created by Francesco Perrotti Garcia on 10/24/18.
// Copyright © 2018 Amplitude. All rights reserved.
//

#import "AMPNSURLSessionNetworkClient.h"
#import "AMPARCMacros.h"
#import "AMPEventUploadRequest.h"

@interface AMPNSURLSessionNetworkClient()
@property (nonatomic, strong) NSURLSession *session;
@end

@implementation AMPNSURLSessionNetworkClient
- (instancetype) init {
return [super init];
}

- (void) uploadEvents: (AMPEventUploadRequest *) uploadRequest using: (NSURLSession *) session completionHandler: (void (^)(NSData * data, NSURLResponse *response, NSError *error)) completionHandler {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:uploadRequest.url];
[request setTimeoutInterval:60.0];

NSString *apiVersionString = [[NSNumber numberWithInt:uploadRequest.apiVersion] stringValue];

NSMutableData *postData = [[NSMutableData alloc] init];
[postData appendData:[@"v=" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[apiVersionString dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&client=" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[uploadRequest.apiKey dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&e=" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[[self urlEncodeString:uploadRequest.events] dataUsingEncoding:NSUTF8StringEncoding]];

// Add timestamp of upload
[postData appendData:[@"&upload_time=" dataUsingEncoding:NSUTF8StringEncoding]];
NSString *timestampString = [[NSNumber numberWithLongLong: uploadRequest.uploadTime] stringValue];
[postData appendData:[timestampString dataUsingEncoding:NSUTF8StringEncoding]];

[postData appendData:[@"&checksum=" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[uploadRequest.checksum dataUsingEncoding:NSUTF8StringEncoding]];

[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[postData length]] forHTTPHeaderField:@"Content-Length"];

[request setHTTPBody:postData];

SAFE_ARC_RELEASE(postData);

[[session dataTaskWithRequest:request completionHandler:completionHandler] resume];
}

- (NSString*)urlEncodeString:(NSString*) string {
NSCharacterSet * allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:@":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"] invertedSet];
return [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
}

@end
Loading