-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAspectManagerHelper.m
More file actions
225 lines (162 loc) · 5.92 KB
/
AspectManagerHelper.m
File metadata and controls
225 lines (162 loc) · 5.92 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//
// AspectManagerHelper.m
// Starbucks_iOS_Renewal
//
// Created by yunseok choi on 2017. 10. 10..
// Copyright © 2017년 Media Plus K2L App development Dept. All rights reserved.
//
#import "AspectManagerHelper.h"
@implementation AspectManagerHelper
+ (BOOL)isPrepareTesting {
NSArray *apis = [self getTestingAPIs];
if (apis) {
if (apis.count > 0) {
return YES;
}
else {
return NO;
}
}
else {
return NO;
}
}
+ (BOOL)isTestingAPI:(NSString *)url {
NSArray *apis = [self getTestingAPIs];
BOOL isTestingApi = NO;
for (NSDictionary *testingDict in apis) {
if ([url isEqualToString:[testingDict objectForKey:@"url"]]) {
if ([[testingDict objectForKey:@"isTest"] boolValue]) {
isTestingApi = YES;
}
}
}
return isTestingApi;
}
+ (NSDictionary *)getTestingAPI:(NSString *)url {
NSArray *apis = [self getTestingAPIs];
NSDictionary *api;
for (NSDictionary *testingDict in apis) {
if ([url isEqualToString:[testingDict objectForKey:@"url"]]) {
api = [NSDictionary dictionaryWithDictionary:testingDict];
}
}
return api;
}
+ (NSDictionary *)getConfig {
NSError *deserializingError;
NSString *configFilePath = [[NSBundle mainBundle] pathForResource:@"config"
ofType:@"json"];
NSDictionary *configDict;
if (configFilePath) {
NSURL *configFileUrl = [NSURL fileURLWithPath:configFilePath];
NSData *config = [NSData dataWithContentsOfURL:configFileUrl];
configDict = [NSJSONSerialization JSONObjectWithData:config
options:kNilOptions
error:&deserializingError];
}
else {
NSLog(@"Not found config.json file.");
return nil;
}
if (configDict) {
return configDict;
}
else {
NSLog(@"Error while parsing config.json file.");
return nil;
}
}
+ (NSArray *)getTestingAPIs {
NSDictionary *configDict = [self getConfig];
if (configDict) {
NSArray *apis = [[NSArray alloc]initWithArray:[configDict objectForKey:@"testing-routes"]];
return apis;
}
else {
return nil;
}
}
+ (NSDictionary *)getResponseDummyHeaderData:(NSString *)testingUrl {
NSArray *apis = [self getTestingAPIs];
NSDictionary *header = nil;
if (apis != nil && apis.count > 0) {
for (NSDictionary *dic in apis) {
if ([testingUrl isEqualToString:[dic objectForKey:@"url"]]) {
NSString *filename = [dic objectForKey:@"response-header"];
if (filename) {
header = [self getHeaderResponse:filename];
}
else {
header = [self getHeaderResponse:@""];
}
}
}
}
else {
NSLog(@"Not found testing APIs from testing-routes in config file.");
return nil;
}
return header;
}
+ (NSDictionary *)getHeaderResponse:(NSString *)filename {
NSArray *filenames = [filename componentsSeparatedByString:@"."];
NSDictionary *header = nil;
if (filenames.count > 1) {
NSString *path = [[NSBundle mainBundle] pathForResource:[filenames objectAtIndex:0]
ofType:[filenames objectAtIndex:1]];
NSURL *headerFileUrl = [NSURL fileURLWithPath:path];
if (headerFileUrl) {
NSData *headerData = [NSData dataWithContentsOfURL:headerFileUrl];
header = [NSJSONSerialization JSONObjectWithData:headerData
options:kNilOptions
error:nil];
}
}
if (header == nil) {
header = @{@"Connection" : @"keep-alive",
@"Content-Language" : @"ko-KR",
@"Content-Type" : @"application/json;charset-UTF-8"};
}
return header;
}
+ (NSString *)getResponseDummyBodyData:(NSString *)testingUrl {
NSArray *apis = [self getTestingAPIs];
NSString *responseData = @"";
if (apis != nil && apis.count > 0) {
for (NSDictionary *dic in apis) {
if ([testingUrl isEqualToString:[dic objectForKey:@"url"]]) {
responseData = [self getDataInFile:[dic objectForKey:@"response-body"]];
}
}
}
else {
NSLog(@"Not found testing APIs from testing-routes in config file.");
return nil;
}
return responseData;
}
+ (NSString *)getDataInFile:(NSString *)filename {
NSArray *filenames = [filename componentsSeparatedByString:@"."];
NSString *path = [[NSBundle mainBundle] pathForResource:[filenames objectAtIndex:0]
ofType:[filenames objectAtIndex:1]];
NSString *stringData = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:nil];
return stringData;
}
- (NSXMLParser *)getGeneralSettingsFileParser {
NSXMLParser *parser;
NSString *strPath = [[NSBundle mainBundle] pathForResource:@"GeneralSettings" ofType:@"xml"];
if (strPath) {
parser = [[NSXMLParser alloc]initWithContentsOfURL:[NSURL fileURLWithPath:strPath]];
}
else {
assert(@"Not found General Settings XML file");
}
if (parser == nil) {
assert(@"Error while parsing General Settings XML file");
}
return parser;
}
@end