forked from fyber-engineering/mopub-ios-mediation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOguryAdapterConfiguration.m
154 lines (115 loc) · 5.77 KB
/
OguryAdapterConfiguration.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#import "OguryAdapterConfiguration.h"
#import <OguryAds/OguryAds.h>
#import <OguryChoiceManager/OguryChoiceManager.h>
#if __has_include("MoPub.h")
#import "MoPub.h"
#import "MPError.h"
#import "MPLogging.h"
#endif
#pragma mark - Constants
NSString * const kOguryConfigurationAdUnitId = @"ad_unit_id";
static NSString * const OguryErrorDomain = @"com.mopub.mopub-ios-sdk.mopub-ogury-adapters";
static NSString * const OguryConfigurationMediationName = @"MoPub";
static NSString * const OguryConfigurationKeyAssetKey = @"asset_key";
static NSString * const OguryConfigurationAdapterVersion = @"1.4.1.0";
static NSString * const OguryConfigurationNetworkName = @"ogury";
@implementation OguryAdapterConfiguration
#pragma mark - Properties
- (NSString *)adapterVersion {
return OguryConfigurationAdapterVersion;
}
- (NSString *)biddingToken {
return nil;
}
- (NSString *)moPubNetworkName {
return OguryConfigurationNetworkName;
}
- (NSString *)networkSdkVersion {
return [[OguryAds shared] sdkVersion];
}
#pragma mark - Methods
+ (void)updateInitializationParameters:(NSDictionary *)parameters {
NSString * assetKey = parameters[OguryConfigurationKeyAssetKey];
if (assetKey != nil && assetKey.length > 0) {
NSDictionary * configuration = @{ OguryConfigurationKeyAssetKey: assetKey };
[OguryAdapterConfiguration setCachedInitializationParameters:configuration];
}
}
- (void)initializeNetworkWithConfiguration:(NSDictionary<NSString *, id> * _Nullable)configuration complete:(void(^ _Nullable)(NSError * _Nullable))complete {
[[OguryAds shared] defineMediationName:OguryConfigurationMediationName];
if (!configuration || [configuration count] == 0) {
NSError *error = [NSError errorWithCode:MOPUBErrorAdapterInvalid localizedDescription:@"Ogury initialization skipped because the configuration dictionary is nil or empty."];
MPLogEvent([MPLogEvent error:error message:nil]);
if (complete != nil) {
complete(error);
}
return;
}
NSString *assetKey = configuration[OguryConfigurationKeyAssetKey];
if (!assetKey || [assetKey isEqualToString:@""]) {
NSError *error = [NSError errorWithDomain:OguryErrorDomain code:MOPUBErrorAdapterInvalid userInfo:@{
NSLocalizedDescriptionKey: @"Ogury initialization skipped because the asset key is missing or empty.",
NSLocalizedRecoverySuggestionErrorKey: @"Please input a valid asset key from the Ogury dashboard."
}];
MPLogEvent([MPLogEvent error:error message:nil]);
if (complete != nil) {
complete(error);
}
return;
}
[OguryAdapterConfiguration applyTransparencyAndConsentStatusWithParameters:configuration];
[[OguryAds shared] setupWithAssetKey:assetKey];
MPLogInfo(@"Ogury SDK successfully initialized.");
complete(nil);
}
+ (void)applyTransparencyAndConsentStatusWithParameters:(NSDictionary *)parameters {
NSString *assetKey = parameters[OguryConfigurationKeyAssetKey];
if (assetKey && [MoPub sharedInstance].currentConsentStatus != MPConsentStatusUnknown) {
[OguryChoiceManagerExternal setTransparencyAndConsentStatus:[[MoPub sharedInstance] canCollectPersonalInfo] origin:OguryConfigurationMediationName assetKey:assetKey];
}
}
+ (NSError *)MoPubErrorFromOguryError:(OguryAdsErrorType)oguryError {
NSNumber *mopubErrorCode;
NSString *localizedDescription;
switch (oguryError) {
case OguryAdsErrorLoadFailed:
mopubErrorCode = @(MOPUBErrorAdapterFailedToLoadAd);
localizedDescription = @"The ad failed to load for an unknown reason.";
break;
case OguryAdsErrorNoInternetConnection:
mopubErrorCode = @(MOPUBErrorAdapterFailedToLoadAd);
localizedDescription = @"The device has no Internet connection. Try again when the device is connected to Internet again.";
break;
case OguryAdsErrorAdDisable:
mopubErrorCode = @(MOPUBErrorAdapterFailedToLoadAd);
localizedDescription = @"Ad serving has been disabled for this placement/application.";
break;
case OguryAdsErrorProfigNotSynced:
mopubErrorCode = @(MOPUBErrorSDKNotInitialized);
localizedDescription = @"An internal SDK error occurred.";
break;
case OguryAdsErrorAdExpired:
mopubErrorCode = @(MOPUBErrorAdapterFailedToLoadAd);
localizedDescription = @"The loaded ad is expired. You must call the show method within 4 hours after the load";
break;
case OguryAdsErrorSdkInitNotCalled:
mopubErrorCode = @(MOPUBErrorSDKNotInitialized);
localizedDescription = @"The setup method has not been called before a call to the load or show methods.";
break;
case OguryAdsErrorAnotherAdAlreadyDisplayed:
mopubErrorCode = @(MOPUBErrorFullScreenAdAlreadyOnScreen);
localizedDescription = @"Another ad is already displayed on the screen.";
break;
case OguryAdsErrorCantShowAdsInPresentingViewController:
mopubErrorCode = @(MOPUBErrorFullScreenAdAlreadyOnScreen);
localizedDescription = @"Currently a ViewController is being presented and it is preventing the ad from displaying.";
break;
case OguryAdsErrorUnknown:
default:
mopubErrorCode = @(MOPUBErrorUnknown);
localizedDescription = @"Unkown error type.";
break;
}
return [NSError errorWithDomain:OguryErrorDomain code:mopubErrorCode.integerValue userInfo:@{NSLocalizedDescriptionKey:localizedDescription}];
}
@end