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

LIB-35: Updated class names for Swift #902

Merged
merged 1 commit into from
Jun 11, 2020
Merged
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
1 change: 1 addition & 0 deletions Analytics/Classes/Crypto/SEGAES256Crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "SEGCrypto.h"


NS_SWIFT_NAME(AES256Crypto)
@interface SEGAES256Crypto : NSObject <SEGCrypto>

@property (nonatomic, readonly, nonnull) NSString *password;
Expand Down
2 changes: 1 addition & 1 deletion Analytics/Classes/Integrations/SEGAliasPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

NS_ASSUME_NONNULL_BEGIN


NS_SWIFT_NAME(AliasPayload)
@interface SEGAliasPayload : SEGPayload

@property (nonatomic, readonly) NSString *theNewId;
Expand Down
2 changes: 1 addition & 1 deletion Analytics/Classes/Integrations/SEGGroupPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

NS_ASSUME_NONNULL_BEGIN


NS_SWIFT_NAME(GroupPayload)
@interface SEGGroupPayload : SEGPayload

@property (nonatomic, readonly) NSString *groupId;
Expand Down
2 changes: 1 addition & 1 deletion Analytics/Classes/Integrations/SEGIdentifyPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

NS_ASSUME_NONNULL_BEGIN


NS_SWIFT_NAME(IdentifyPayload)
@interface SEGIdentifyPayload : SEGPayload

@property (nonatomic, readonly, nullable) NSString *userId;
Expand Down
1 change: 1 addition & 0 deletions Analytics/Classes/Integrations/SEGIntegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

NS_ASSUME_NONNULL_BEGIN

NS_SWIFT_NAME(Integration)
@protocol SEGIntegration <NSObject>

@optional
Expand Down
2 changes: 1 addition & 1 deletion Analytics/Classes/Integrations/SEGIntegrationsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern NSString *_Nonnull SEGAnalyticsIntegrationDidStart;

@class SEGAnalytics;


NS_SWIFT_NAME(IntegrationsManager)
@interface SEGIntegrationsManager : NSObject

// Exposed for testing.
Expand Down
7 changes: 5 additions & 2 deletions Analytics/Classes/Integrations/SEGPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

NS_ASSUME_NONNULL_BEGIN


NS_SWIFT_NAME(Payload)
@interface SEGPayload : NSObject

@property (nonatomic, readonly) JSON_DICT context;
Expand All @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
@end


NS_SWIFT_NAME(ApplicationLifecyclePayload)
@interface SEGApplicationLifecyclePayload : SEGPayload

@property (nonatomic, strong) NSString *notificationName;
Expand All @@ -25,13 +26,14 @@ NS_ASSUME_NONNULL_BEGIN
@end


NS_SWIFT_NAME(ContinueUserActivityPayload)
@interface SEGContinueUserActivityPayload : SEGPayload

@property (nonatomic, strong) NSUserActivity *activity;

@end


NS_SWIFT_NAME(OpenURLPayload)
@interface SEGOpenURLPayload : SEGPayload

@property (nonatomic, strong) NSURL *url;
Expand All @@ -42,6 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
NS_ASSUME_NONNULL_END


NS_SWIFT_NAME(RemoteNotificationPayload)
@interface SEGRemoteNotificationPayload : SEGPayload

// SEGEventTypeHandleActionWithForRemoteNotification
Expand Down
1 change: 1 addition & 0 deletions Analytics/Classes/Integrations/SEGScreenPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
NS_ASSUME_NONNULL_BEGIN


NS_SWIFT_NAME(ScreenPayload)
@interface SEGScreenPayload : SEGPayload

@property (nonatomic, readonly) NSString *name;
Expand Down
1 change: 1 addition & 0 deletions Analytics/Classes/Integrations/SEGTrackPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
NS_ASSUME_NONNULL_BEGIN


NS_SWIFT_NAME(TrackPayload)
@interface SEGTrackPayload : SEGPayload

@property (nonatomic, readonly) NSString *event;
Expand Down
1 change: 1 addition & 0 deletions Analytics/Classes/Internal/SEGFileStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "SEGStorage.h"


NS_SWIFT_NAME(FileStorage)
@interface SEGFileStorage : NSObject <SEGStorage>

@property (nonatomic, strong, nullable) id<SEGCrypto> crypto;
Expand Down
1 change: 1 addition & 0 deletions Analytics/Classes/Internal/SEGHTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
NS_ASSUME_NONNULL_BEGIN


NS_SWIFT_NAME(HTTPClient)
@interface SEGHTTPClient : NSObject

@property (nonatomic, strong) SEGRequestFactory requestFactory;
Expand Down
1 change: 1 addition & 0 deletions Analytics/Classes/Internal/SEGSegmentIntegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern NSString *const kSEGQueueFilename;
extern NSString *const kSEGTraitsFilename;


NS_SWIFT_NAME(SegmentIntegration)
@interface SEGSegmentIntegration : NSObject <SEGIntegration>

- (id)initWithAnalytics:(SEGAnalytics *)analytics httpClient:(SEGHTTPClient *)httpClient fileStorage:(id<SEGStorage>)fileStorage userDefaultsStorage:(id<SEGStorage>)userDefaultsStorage;
Expand Down
1 change: 1 addition & 0 deletions Analytics/Classes/Internal/SEGSegmentIntegrationFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
NS_ASSUME_NONNULL_BEGIN


NS_SWIFT_NAME(SegmentIntegrationFactory)
@interface SEGSegmentIntegrationFactory : NSObject <SEGIntegrationFactory>

@property (nonatomic, strong) SEGHTTPClient *client;
Expand Down
1 change: 1 addition & 0 deletions Analytics/Classes/Internal/SEGStoreKitTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
NS_ASSUME_NONNULL_BEGIN


NS_SWIFT_NAME(StoreKitTracker)
@interface SEGStoreKitTracker : NSObject <SKPaymentTransactionObserver, SKProductsRequestDelegate>

+ (instancetype)trackTransactionsForAnalytics:(SEGAnalytics *)analytics;
Expand Down
1 change: 1 addition & 0 deletions Analytics/Classes/Internal/SEGUserDefaultsStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "SEGStorage.h"


NS_SWIFT_NAME(UserDefaultsStorage)
@interface SEGUserDefaultsStorage : NSObject <SEGStorage>

@property (nonatomic, strong, nullable) id<SEGCrypto> crypto;
Expand Down
1 change: 1 addition & 0 deletions Analytics/Classes/Internal/SEGUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#import "SEGAnalyticsUtils.h"


NS_SWIFT_NAME(Utilities)
@interface SEGUtils : NSObject

+ (NSData *_Nullable)dataFromPlist:(nonnull id)plist;
Expand Down
3 changes: 2 additions & 1 deletion Analytics/Classes/Middlewares/SEGContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ typedef NS_ENUM(NSInteger, SEGEventType) {
SEGEventTypeContinueUserActivity,
SEGEventTypeOpenURL,

};
} NS_SWIFT_NAME(EventType);

@class SEGAnalytics;
@protocol SEGMutableContext;


NS_SWIFT_NAME(Context)
@interface SEGContext : NSObject <NSCopying>

// Loopback reference to the top level SEGAnalytics object.
Expand Down
4 changes: 4 additions & 0 deletions Analytics/Classes/Middlewares/SEGMiddleware.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

typedef void (^SEGMiddlewareNext)(SEGContext *_Nullable newContext);

NS_SWIFT_NAME(Middleware)
@protocol SEGMiddleware
@required

Expand All @@ -33,6 +34,7 @@ typedef void (^SEGMiddlewareNext)(SEGContext *_Nullable newContext);
typedef void (^SEGMiddlewareBlock)(SEGContext *_Nonnull context, SEGMiddlewareNext _Nonnull next);


NS_SWIFT_NAME(BlockMiddleware)
@interface SEGBlockMiddleware : NSObject <SEGMiddleware>

@property (nonnull, nonatomic, readonly) SEGMiddlewareBlock block;
Expand All @@ -45,6 +47,7 @@ typedef void (^SEGMiddlewareBlock)(SEGContext *_Nonnull context, SEGMiddlewareNe
typedef void (^RunMiddlewaresCallback)(BOOL earlyExit, NSArray<id<SEGMiddleware>> *_Nonnull remainingMiddlewares);

// XXX TODO: Add some tests for SEGMiddlewareRunner
NS_SWIFT_NAME(MiddlewareRunner)
@interface SEGMiddlewareRunner : NSObject

// While it is certainly technically possible to change middlewares dynamically on the fly. we're explicitly NOT
Expand All @@ -58,6 +61,7 @@ typedef void (^RunMiddlewaresCallback)(BOOL earlyExit, NSArray<id<SEGMiddleware>
@end

// Container object for middlewares for a specific destination.
NS_SWIFT_NAME(DestinationMiddleware)
@interface SEGDestinationMiddleware : NSObject
@property (nonatomic, strong, nonnull, readonly) NSString *integrationKey;
@property (nonatomic, strong, nullable, readonly) NSArray<id<SEGMiddleware>> *middleware;
Expand Down
4 changes: 2 additions & 2 deletions Analytics/Classes/SEGAnalytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@class SEGAnalyticsConfiguration;


NS_SWIFT_NAME(Analytics)
@interface SEGAnalytics : NSObject

/**
Expand Down Expand Up @@ -45,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @see -setupWithConfiguration:
*/
+ (instancetype _Nullable)sharedAnalytics;
+ (instancetype)sharedAnalytics;

/*!
@method
Expand Down
3 changes: 3 additions & 0 deletions Analytics/Classes/SEGAnalyticsConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_SWIFT_NAME(ApplicationProtocol)
@protocol SEGApplicationProtocol <NSObject>
@property (nullable, nonatomic, assign) id<UIApplicationDelegate> delegate;
- (UIBackgroundTaskIdentifier)seg_beginBackgroundTaskWithName:(nullable NSString *)taskName expirationHandler:(void (^__nullable)(void))handler;
Expand All @@ -32,6 +33,7 @@ typedef NSString *_Nonnull (^SEGAdSupportBlock)(void);
/**
* This object provides a set of properties to control various policies of the analytics client. Other than `writeKey`, these properties can be changed at any time.
*/
NS_SWIFT_NAME(AnalyticsConfiguration)
@interface SEGAnalyticsConfiguration : NSObject

/**
Expand Down Expand Up @@ -216,6 +218,7 @@ typedef NSString *_Nonnull (^SEGAdSupportBlock)(void);

typedef NSDictionary * _Nonnull (^SEGRawModificationBlock)( NSDictionary * _Nonnull rawPayload);

NS_SWIFT_NAME(AnalyticsExperimental)
@interface SEGAnalyticsExperimental : NSObject
/**
Experimental support for nanosecond timestamps. While the segment pipeline doesn't support this yet
Expand Down
1 change: 1 addition & 0 deletions Analytics/Vendor/SEGReachability.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typedef void (^SEGNetworkReachable)(SEGReachability *reachability);
typedef void (^SEGNetworkUnreachable)(SEGReachability *reachability);


NS_SWIFT_NAME(Reachability)
@interface SEGReachability : NSObject

@property (nonatomic, copy, nullable) SEGNetworkReachable reachableBlock;
Expand Down
20 changes: 10 additions & 10 deletions AnalyticsTests/AnalyticsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import Analytics

class AnalyticsTests: QuickSpec {
override func spec() {
let config = SEGAnalyticsConfiguration(writeKey: "QUI5ydwIGeFFTa1IvCBUhxL9PyW5B0jE")
let config = AnalyticsConfiguration(writeKey: "QUI5ydwIGeFFTa1IvCBUhxL9PyW5B0jE")
let cachedSettings = [
"integrations": [
"Segment.io": ["apiKey": "QUI5ydwIGeFFTa1IvCBUhxL9PyW5B0jE"]
],
"plan": ["track": [:]],
] as NSDictionary
var analytics: SEGAnalytics!
var analytics: Analytics!
var testMiddleware: TestMiddleware!
var testApplication: TestApplication!

Expand All @@ -34,7 +34,7 @@ class AnalyticsTests: QuickSpec {
UserDefaults.standard.set("test SEGQueue should be removed", forKey: "SEGQueue")
expect(UserDefaults.standard.string(forKey: "SEGQueue")).toNot(beNil())

analytics = SEGAnalytics(configuration: config)
analytics = Analytics(configuration: config)
analytics.test_integrationsManager()?.test_setCachedSettings(settings: cachedSettings)
}

Expand Down Expand Up @@ -73,14 +73,14 @@ class AnalyticsTests: QuickSpec {
}*/

it("persists anonymousId") {
let analytics2 = SEGAnalytics(configuration: config)
let analytics2 = Analytics(configuration: config)
expect(analytics.getAnonymousId()) == analytics2.getAnonymousId()
}

it("persists userId") {
analytics.identify("testUserId1")

let analytics2 = SEGAnalytics(configuration: config)
let analytics2 = Analytics(configuration: config)
analytics2.test_integrationsManager()?.test_setCachedSettings(settings: cachedSettings)

expect(analytics.test_integrationsManager()?.test_segmentIntegration()?.test_userId()) == "testUserId1"
Expand Down Expand Up @@ -110,7 +110,7 @@ class AnalyticsTests: QuickSpec {
UIApplicationLaunchOptionsKey.sourceApplication: "testApp",
UIApplicationLaunchOptionsKey.url: "test://test",
])
let event = testMiddleware.lastContext?.payload as? SEGTrackPayload
let event = testMiddleware.lastContext?.payload as? TrackPayload
expect(event?.event) == "Application Opened"
expect(event?.properties?["from_background"] as? Bool) == false
expect(event?.properties?["referring_application"] as? String) == "testApp"
Expand All @@ -120,15 +120,15 @@ class AnalyticsTests: QuickSpec {
it("fires Application Opened during UIApplicationWillEnterForeground") {
testMiddleware.swallowEvent = true
NotificationCenter.default.post(name: .UIApplicationWillEnterForeground, object: testApplication)
let event = testMiddleware.lastContext?.payload as? SEGTrackPayload
let event = testMiddleware.lastContext?.payload as? TrackPayload
expect(event?.event) == "Application Opened"
expect(event?.properties?["from_background"] as? Bool) == true
}

it("fires Application Backgrounded during UIApplicationDidEnterBackground") {
testMiddleware.swallowEvent = true
NotificationCenter.default.post(name: .UIApplicationDidEnterBackground, object: testApplication)
let event = testMiddleware.lastContext?.payload as? SEGTrackPayload
let event = testMiddleware.lastContext?.payload as? TrackPayload
expect(event?.event) == "Application Backgrounded"
}

Expand Down Expand Up @@ -206,7 +206,7 @@ class AnalyticsTests: QuickSpec {
analytics.open(URL(string: "fb123456789://authorize#access_token=hastoberedacted")!, options: [:])


let event = testMiddleware.lastContext?.payload as? SEGTrackPayload
let event = testMiddleware.lastContext?.payload as? TrackPayload
expect(event?.event) == "Deep Link Opened"
expect(event?.properties?["url"] as? String) == "fb123456789://authorize#access_token=((redacted/fb-auth-token))"
}
Expand All @@ -218,7 +218,7 @@ class AnalyticsTests: QuickSpec {
analytics.open(URL(string: "myapp://auth?token=hastoberedacted&other=stuff")!, options: [:])


let event = testMiddleware.lastContext?.payload as? SEGTrackPayload
let event = testMiddleware.lastContext?.payload as? TrackPayload
expect(event?.event) == "Deep Link Opened"
expect(event?.properties?["url"] as? String) == "myapp://auth?token=((redacted/my-auth))&other=stuff"
}
Expand Down
8 changes: 4 additions & 4 deletions AnalyticsTests/AnalyticsUtilTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ class AnalyticsUtilTests: QuickSpec {
}

it("works with strings") {
expect(SEGUtils.traverseJSON("a b foo c", andReplaceWithFilters: filters) as? String) == "a b foo-bar c"
expect(Utilities.traverseJSON("a b foo c", andReplaceWithFilters: filters) as? String) == "a b foo-bar c"
}

it("works recursively") {
expect(SEGUtils.traverseJSON("a b foo foo c", andReplaceWithFilters: filters) as? String) == "a b foo-bar foo-bar c"
expect(Utilities.traverseJSON("a b foo foo c", andReplaceWithFilters: filters) as? String) == "a b foo-bar foo-bar c"
}

it("works with nested dictionaries") {
Expand All @@ -109,7 +109,7 @@ class AnalyticsUtilTests: QuickSpec {
"bar": "foo"
] as [String: Any]

guard let input = SEGUtils.traverseJSON(data, andReplaceWithFilters: filters) as? [String: Any] else {
guard let input = Utilities.traverseJSON(data, andReplaceWithFilters: filters) as? [String: Any] else {
XCTFail("Failed to create actual result from traversed JSON replace")
return
}
Expand All @@ -127,7 +127,7 @@ class AnalyticsUtilTests: QuickSpec {
[1, nil, "qfoob", ["baz": "foo"]],
"foo"
] as [Any]
let input = SEGUtils.traverseJSON(data, andReplaceWithFilters: filters)
let input = Utilities.traverseJSON(data, andReplaceWithFilters: filters)
let output = [
[1, nil, "qfoo-barb", ["baz": "foo-bar"]],
"foo-bar"
Expand Down
2 changes: 1 addition & 1 deletion AnalyticsTests/AutoScreenReportingTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AutoScreenReportingTests: QuickSpec {
var rootVC: UIViewController!

beforeEach {
let config = SEGAnalyticsConfiguration(writeKey: "foobar")
let config = AnalyticsConfiguration(writeKey: "foobar")
config.trackApplicationLifecycleEvents = true
config.recordScreenViews = true

Expand Down
Loading