This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
forked from eczarny/xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 29
/
XMLRPCResponse.m
101 lines (73 loc) · 1.71 KB
/
XMLRPCResponse.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
#import "XMLRPCResponse.h"
#import "XMLRPCEventBasedParser.h"
@implementation XMLRPCResponse
- (id)initWithData: (NSData *)data {
if (!data) {
return nil;
}
self = [super init];
if (self) {
XMLRPCEventBasedParser *parser = [[XMLRPCEventBasedParser alloc] initWithData: data];
if (!parser) {
#if ! __has_feature(objc_arc)
[self release];
#endif
return nil;
}
myBody = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
myObject = [parser parse];
#if ! __has_feature(objc_arc)
[myObject retain];
#endif
isFault = [parser isFault];
#if ! __has_feature(objc_arc)
[parser release];
#endif
}
return self;
}
#pragma mark -
- (BOOL)isFault {
return isFault;
}
- (NSNumber *)faultCode {
if (isFault) {
return [myObject objectForKey: @"faultCode"];
}
return nil;
}
- (NSString *)faultString {
if (isFault) {
return [myObject objectForKey: @"faultString"];
}
return nil;
}
#pragma mark -
- (id)object {
return myObject;
}
#pragma mark -
- (NSString *)body {
return myBody;
}
#pragma mark -
- (NSString *)description {
NSMutableString *result = [NSMutableString stringWithCapacity:128];
[result appendFormat:@"[body=%@", myBody];
if (isFault) {
[result appendFormat:@", fault[%@]='%@'", [self faultCode], [self faultString]];
} else {
[result appendFormat:@", object=%@", myObject];
}
[result appendString:@"]"];
return result;
}
#pragma mark -
- (void)dealloc {
#if ! __has_feature(objc_arc)
[myBody release];
[myObject release];
[super dealloc];
#endif
}
@end