Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
runner authored and runner committed Mar 21, 2022
1 parent b3d4a74 commit dddce04
Show file tree
Hide file tree
Showing 269 changed files with 10,724 additions and 332 deletions.
13 changes: 9 additions & 4 deletions SourceCode/Private/Ads/Api/UADSApiToken.m
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
#import "UADSApiToken.h"
#import "USRVWebViewCallback.h"
#import "UADSTokenStorage.h"
#import "UADSHeaderBiddingTokenReaderBuilder.h"

@implementation UADSApiToken

+ (void)WebViewExposed_createTokens: (NSArray *)tokens callback: (USRVWebViewCallback *)callback {
[[UADSTokenStorage sharedInstance] createTokens: tokens];
[self.tokenStorage createTokens: tokens];
[callback invoke: nil];
}

+ (void)WebViewExposed_appendTokens: (NSArray *)tokens callback: (USRVWebViewCallback *)callback {
[[UADSTokenStorage sharedInstance] appendTokens: tokens];
[self.tokenStorage appendTokens: tokens];
[callback invoke: nil];
}

+ (void)WebViewExposed_deleteTokens: (USRVWebViewCallback *)callback {
[[UADSTokenStorage sharedInstance] deleteTokens];
[self.tokenStorage deleteTokens];
[callback invoke: nil];
}

+ (void)WebViewExposed_setPeekMode: (NSNumber *)value callback: (USRVWebViewCallback *)callback {
[[UADSTokenStorage sharedInstance] setPeekMode: [value boolValue]];
[self.tokenStorage setPeekMode: [value boolValue]];
[callback invoke: nil];
}

+ (id<UADSHeaderBiddingTokenCRUD>)tokenStorage {
return UADSHeaderBiddingTokenReaderBuilder.sharedInstance.defaultReader;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#import "UADSWebViewShowOperation.H"
#import "UADSTokenStorage.h"
#import "UADSAbstractModule.h"
#import "UADSHeaderBiddingTokenReaderBuilder.h"

@implementation UADSAdsModuleConfiguration

- (NSArray<NSString *> *)getWebAppApiClassList {
Expand Down Expand Up @@ -29,6 +31,9 @@ - (BOOL)initModuleState: (USRVConfiguration *)configuration {
}

- (BOOL)initErrorState: (USRVConfiguration *)configuration state: (NSString *)state message: (NSString *)message {
[UADSHeaderBiddingTokenReaderBuilder.sharedInstance.defaultReader setInitToken: nil];
[UADSHeaderBiddingTokenReaderBuilder.sharedInstance.defaultReader deleteTokens];

return true;
}

Expand Down
20 changes: 17 additions & 3 deletions SourceCode/Private/Ads/Token/UADSTokenStorage.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
#import "UADSTokenStorageEventProtocol.h"
#import "UADSHeaderBiddingTokenReaderBase.h"
NS_ASSUME_NONNULL_BEGIN

@protocol UADSHeaderBiddingTokenCRUD <NSObject>
- (void)createTokens: (NSArray<NSString *> *)tokens;
- (void)appendTokens: (NSArray<NSString *> *)tokens;
- (NSString *) getToken;
- (void) deleteTokens;
- (void)setPeekMode: (BOOL)mode;
- (void)setInitToken: (nullable NSString *)token;

@end

@interface UADSTokenStorage : NSObject<UADSHeaderBiddingTokenCRUD>

@interface UADSTokenStorage : NSObject

+ (instancetype)sharedInstance;

- (instancetype)initWithEventHandler: (id<UADSTokenStorageEventProtocol>)eventHandler;

- (void)createTokens: (NSArray<NSString *> *)tokens;
- (void)appendTokens: (NSArray<NSString *> *)tokens;
- (NSString *) getToken;
- (void) deleteTokens;
- (void)setPeekMode: (BOOL)mode;

- (void)setInitToken: (nullable NSString *)token;
@end

NS_ASSUME_NONNULL_END
32 changes: 29 additions & 3 deletions SourceCode/Private/Ads/Token/UADSTokenStorage.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "UADSTokenStorage.h"
#import "UADSTokenStorageEventHandler.h"
#import "UADSInitializeEventsMetricSender.h"

@interface UADSTokenStorage ()

Expand All @@ -8,7 +9,7 @@ @interface UADSTokenStorage ()
@property int accessCounter;
@property (nonatomic) BOOL peekMode;
@property dispatch_queue_t dispatchQueue;

@property (nonatomic, copy) NSString *firstToken;
@property NSObject *lockObject;

@end
Expand Down Expand Up @@ -42,6 +43,7 @@ - (void)createTokens: (NSArray<NSString *> *)tokens {
self.accessCounter = 0;
self.queue = [[NSMutableArray alloc] initWithCapacity: tokens.count];
[self.queue addObjectsFromArray: tokens];
[self sendWebViewTokenAvailabilityMetricsIfRequired];
}
}

Expand All @@ -50,6 +52,7 @@ - (void)appendTokens: (NSArray<NSString *> *)tokens {
if (self.queue == nil) {
self.accessCounter = 0;
self.queue = [[NSMutableArray alloc] initWithCapacity: tokens.count];
[self sendWebViewTokenAvailabilityMetricsIfRequired];
}

[self.queue addObjectsFromArray: tokens];
Expand All @@ -65,12 +68,12 @@ - (void)setPeekMode: (BOOL)mode {
- (NSString *)getToken {
@synchronized (_lockObject) {
if (self.queue == nil) {
return nil;
return self.firstToken;
}

if (self.queue.count == 0) {
[self.eventHandler sendQueueEmpty];
return nil;
return self.firstToken;
}

[self.eventHandler sendTokenAccessIndex: [NSNumber numberWithInt: self.accessCounter++]];
Expand All @@ -92,4 +95,27 @@ - (void)deleteTokens {
}
}

- (void)setInitToken: (NSString *)token {
@synchronized (_lockObject) {
self.firstToken = token;
}
[self sendFirstInitTokenAvailabilityMetricsIfRequired];
}

- (void)sendFirstInitTokenAvailabilityMetricsIfRequired {
if (_firstToken) {
[self.metricsSender sendTokenAvailabilityLatencyOnceOfType: kUADSTokenAvailabilityTypeFirstToken];
}
}

- (void)sendWebViewTokenAvailabilityMetricsIfRequired {
if (_queue.count > 0) {
[self.metricsSender sendTokenAvailabilityLatencyOnceOfType: kUADSTokenAvailabilityTypeWeb];
}
}

- (UADSInitializeEventsMetricSender *)metricsSender {
return UADSInitializeEventsMetricSender.sharedInstance;
}

@end
1 change: 1 addition & 0 deletions SourceCode/Private/Core/Api/USRVApiSdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ + (void)WebViewExposed_loadComplete: (USRVWebViewCallback *)callback {
[NSNumber numberWithBool: YES], // placement load enabled
[NSNumber numberWithBool: [USRVSdkProperties getLatestConfiguration] != nil],
[USRVDevice getElapsedRealtime],
[[[USRVWebViewApp getCurrentApp] configuration] stateId] ? : @"",
nil];
} /* WebViewExposed_loadComplete */

Expand Down
17 changes: 17 additions & 0 deletions SourceCode/Private/Core/Categories/NSBundle + TypecastGet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@protocol UADSPlistReader <NSObject>

- (NSString *)getStringValueForKey: (NSString *)key;

@end

@interface NSBundle (TypecastGet)<UADSPlistReader>
- (NSString *)getStringValueForKey: (NSString *)key;
+ (NSString *)getBuiltSDKVersion;
+ (NSString *)getFromMainBundleValueForKey: (NSString *)key;
@end

NS_ASSUME_NONNULL_END
19 changes: 19 additions & 0 deletions SourceCode/Private/Core/Categories/NSBundle + TypecastGet.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#import "NSBundle + TypecastGet.h"
#import "UADSTools.h"

@implementation NSBundle (TypecastGet)
- (NSString *)getStringValueForKey: (NSString *)key {
id obj = [self objectForInfoDictionaryKey: key];

return typecast(obj, [NSString class]);
}

+ (NSString *)getFromMainBundleValueForKey: (NSString *)key {
return [[self mainBundle] getStringValueForKey: key];
}

+ (NSString *)getBuiltSDKVersion {
return [self getFromMainBundleValueForKey: @"DTSDKName"];
}

@end
5 changes: 0 additions & 5 deletions SourceCode/Private/Core/Categories/NSDictionary+Merge.h

This file was deleted.

32 changes: 0 additions & 32 deletions SourceCode/Private/Core/Categories/NSDictionary+Merge.m

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSDictionary<__covariant KeyType, __covariant ObjectType> (Filter)

- (NSDictionary *)uads_filter: (BOOL(NS_NOESCAPE ^)(KeyType key, ObjectType obj))block;
- (NSDictionary *)uads_mapKeys: (KeyType(NS_NOESCAPE ^)(KeyType key))block;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#import "NSDictionary+Filter.h"

@implementation NSDictionary (Filter)
- (NSDictionary *)uads_filter: (BOOL(NS_NOESCAPE ^)(id key, id obj))block; {
NSMutableDictionary *newDictionary = [NSMutableDictionary new];

[self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL *_Nonnull stop) {
if (block(key, obj)) {
newDictionary[key] = obj;
}
}];

return newDictionary;
}

- (NSDictionary *)uads_mapKeys: (id(NS_NOESCAPE ^)(id key))block {
NSMutableDictionary *newDictionary = [NSMutableDictionary new];

[self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL *_Nonnull stop) {
newDictionary[block(key)] = obj;
}];

return newDictionary;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSDictionary (JSONString)
- (NSString *) jsonEncodedString;
- (NSData *_Nullable)jsonData;
- (NSString *) queryString;
- (BOOL) isEmpty;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#import "NSDictionary+JSONString.h"

@implementation NSDictionary (JSONString)
- (NSString *)jsonEncodedString {
NSData *jsonData = [self jsonData];

if (!jsonData) {
return @"";
}

return [[NSString alloc] initWithData: jsonData
encoding: NSUTF8StringEncoding];
}

- (NSData *)jsonData {
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject: self
options: 0
error: &err];

if (err) {
return nil;
}

GUARD_OR_NIL(jsonData)
return jsonData;
}

- (NSString *)queryString {
__block NSString *queryString = @"";
__block BOOL first = true;

[self enumerateKeysAndObjectsUsingBlock: ^(id _Nonnull key, id _Nonnull obj, BOOL *_Nonnull stop) {
if (first) {
queryString = [NSString stringWithFormat: @"?%@%@=%@", queryString, key, obj];
first = false;
} else {
queryString = [NSString stringWithFormat: @"%@&%@=%@", queryString, key, obj];
}
}];

return queryString;
}

- (BOOL)isEmpty {
return self.count <= 0;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@interface NSDictionary (Merge)

+ (NSDictionary *)unityads_dictionaryByMerging: (NSDictionary *)primary secondary: (NSDictionary *)secondary;

- (NSDictionary *)uads_newdictionaryByMergingWith: (NSDictionary *)dictionary;

- (NSDictionary *)uads_flatUsingSeparator: (NSString *)separator
includeTopLevelKeys: (NSArray<NSString *> *)topLevelToInclude
andReduceKeys: (NSArray<NSString *> *)reduceKeys
andSkipKeys: (NSArray<NSString *> *)keysToSkip;
@end
Loading

0 comments on commit dddce04

Please sign in to comment.