My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*

AdNetwork.m

Copyright 2009 AdMob, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

#import "AdWhirlAdNetworkConfig.h"
#import "AdWhirlConfig.h"
#import "AdWhirlAdNetworkRegistry.h"
#import "AdWhirlLog.h"
#import "AdWhirlError.h"
#import "AdWhirlClassWrapper.h"

#define kAdWhirlPubIdKey @"pubid"

@implementation AdWhirlAdNetworkConfig

@synthesize networkType;
@synthesize nid;
@synthesize networkName;
@synthesize trafficPercentage;
@synthesize priority;
@synthesize credentials;
@synthesize adapterClass;

- (id)initWithDictionary:(NSDictionary *)adNetConfigDict
adNetworkRegistry:(AdWhirlAdNetworkRegistry *)registry
error:(AdWhirlError **)error {
self = [super init];

if (self != nil) {
NSInteger temp;
id ntype = [adNetConfigDict objectForKey:AWAdNetworkConfigKeyType];
id netId = [adNetConfigDict objectForKey:AWAdNetworkConfigKeyNID];
id netName = [adNetConfigDict objectForKey:AWAdNetworkConfigKeyName];
id weight = [adNetConfigDict objectForKey:AWAdNetworkConfigKeyWeight];
id pri = [adNetConfigDict objectForKey:AWAdNetworkConfigKeyPriority];

if (ntype == nil || netId == nil || netName == nil || pri == nil) {
NSString *errorMsg =
@"Ad network config has no network type, network id, network name, or priority";
if (error != nil) {
*error = [AdWhirlError errorWithCode:AdWhirlConfigDataError
description:errorMsg];
}
else {
AWLogWarn(errorMsg);
}

[self release];
return nil;
}

if (awIntVal(&temp, ntype)) {
networkType = temp;
}
if ([netId isKindOfClass:[NSString class]]) {
nid = [[NSString alloc] initWithString:netId];
}
if ([netName isKindOfClass:[NSString class]]) {
networkName = [[NSString alloc] initWithString:netName];
}

double tempDouble;
if (weight == nil) {
trafficPercentage = 0.0;
}
else if (awDoubleVal(&tempDouble, weight)) {
trafficPercentage = tempDouble;
}

if (awIntVal(&temp, pri)) {
priority = temp;
}

if (networkType == 0 || nid == nil || networkName == nil || priority == 0) {
NSString *errorMsg =
@"Ad network config has invalid network type, network id, network name or priority";
if (error != nil) {
*error = [AdWhirlError errorWithCode:AdWhirlConfigDataError
description:errorMsg];
}
else {
AWLogWarn(errorMsg);
}

[self release];
return nil;
}

id cred = [adNetConfigDict objectForKey:AWAdNetworkConfigKeyCred];
if (cred == nil) {
credentials = nil;
}
else {
if ([cred isKindOfClass:[NSDictionary class]]) {
credentials = [[NSDictionary alloc] initWithDictionary:cred copyItems:YES];
}
else if ([cred isKindOfClass:[NSString class]]) {
credentials = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSString stringWithString:cred], kAdWhirlPubIdKey,
nil];
}
}

adapterClass = [registry adapterClassFor:networkType].theClass;
if (adapterClass == nil) {
NSString *errorMsg =
[NSString stringWithFormat:@"Ad network type %d not supported, no adapter found",
networkType];
if (error != nil) {
*error = [AdWhirlError errorWithCode:AdWhirlConfigDataError
description:errorMsg];
}
else {
AWLogWarn(errorMsg);
}

[self release];
return nil;
}
}

return self;
}

- (NSString *)pubId {
if (credentials == nil) return nil;
return [credentials objectForKey:kAdWhirlPubIdKey];
}

- (NSString *)description {
NSString *creds = [self pubId];
if (creds == nil) {
creds = @"{";
for (NSString *k in [credentials keyEnumerator]) {
creds = [creds stringByAppendingFormat:@"%@:%@ ",
k, [credentials objectForKey:k]];
}
creds = [creds stringByAppendingString:@"}"];
}
return [NSString stringWithFormat:
@"name:%@ type:%d nid:%@ weight:%lf priority:%d creds:%@",
networkName, networkType, nid, trafficPercentage, priority, creds];
}

- (void)dealloc {
[nid release], nid = nil;
[networkName release], networkName = nil;
[credentials release], credentials = nil;

[super dealloc];
}

@end

Change log

5ecbb898fa1e by Nigel Choi <nigelc...@google.com> on Aug 6, 2010   Diff
Get the adapter class last in
AdWhirlAdNetworkConfig, after checking
validity of networkType .
Go to: 
Project members, sign in to write a code review

Older revisions

7855cea2d6d8 by Nigel Choi <nigelc...@google.com> on Aug 6, 2010   Diff
Added a test framework for iPhone SDK,
using AdWhirlAdNetworkConfig as guinea
pig. Some minimal refactoring needed
to be done for this.
b4d58897b1b6 by Nigel Choi <nigelc...@google.com> on Jul 26, 2010   Diff
Changed ration/weight/trafficPercent
to be doubles.
e52196fd8d92 by Justin Pincar <jpin...@admob.com> on Jan 15, 2010   Diff
Adding ALPHA android SDK.
All revisions of this file

File info

Size: 4874 bytes, 169 lines
Powered by Google Project Hosting