Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed BS3Response to an actual NSHTTPURLResponse subclass; not sure…

… if it is worth it...
  • Loading branch information...
commit e657d15f585e79ead89d44ce00a28dbebc1fff20 1 parent 5dd0f91
@brcosm authored
Showing with 30 additions and 33 deletions.
  1. +6 −6 S3Kit/S3Kit/BS3Response.h
  2. +24 −27 S3Kit/S3Kit/BS3Response.m
View
12 S3Kit/S3Kit/BS3Response.h
@@ -10,14 +10,14 @@
@class BS3Parser;
-@interface BS3Response : NSObject
+@interface BS3Response : NSHTTPURLResponse
-@property (nonatomic, strong) NSHTTPURLResponse *httpResponse;
-@property (nonatomic, readonly) NSDictionary *responseDictionary;
-@property (nonatomic, strong) NSError *responseError;
-@property (nonatomic, readonly) NSString *responseType;
+@property (nonatomic, readonly) NSData *data;
+@property (nonatomic, readonly) NSDictionary *dataDictionary;
+@property (nonatomic, readonly) NSError *error;
+@property (nonatomic, readonly) NSString *type;
@property (nonatomic, strong) BS3Parser *parser;
-- (id)initWithHTTPResponse:(NSHTTPURLResponse *)httpResponse data:(NSData *)responseData error:(NSError *)error;
+- (id)initWithHTTPResponse:(NSHTTPURLResponse *)response data:(NSData *)data error:(NSError *)error;
@end
View
51 S3Kit/S3Kit/BS3Response.m
@@ -11,12 +11,10 @@
static NSDateFormatter *_s3DateFormat;
-@implementation BS3Response {
- NSData *_responseData;
-}
+@implementation BS3Response
@synthesize parser;
-@synthesize httpResponse = _httpResponse, responseError = _responseError;
-@synthesize responseDictionary = _responseDictionary, responseType = _responseType;
+@synthesize data = _data, error = _error;
+@synthesize dataDictionary = _dataDictionary, type = _type;
+ (NSDictionary *)parseBucket:(NSDictionary *)rawDict {
NSDate *creationDate = [_s3DateFormat dateFromString:[rawDict objectForKey:@"CreationDate"]];
@@ -79,39 +77,38 @@ + (NSDictionary *)formattedDictionaryWithParsedDictionary:(NSDictionary *)parsed
return formattedDict;
}
-- (id)initWithHTTPResponse:(NSHTTPURLResponse *)httpResponse data:(NSData *)responseData error:(NSError *)error {
- self = [super init];
+- (id)initWithHTTPResponse:(NSHTTPURLResponse *)response data:(NSData *)data error:(NSError *)error {
+ self = [super initWithURL:response.URL statusCode:response.statusCode HTTPVersion:@"1.1" headerFields:response.allHeaderFields];
if (self) {
- if(!_s3DateFormat) {
- static dispatch_once_t oncePredicate;
- dispatch_once(&oncePredicate, ^{
- _s3DateFormat = [[NSDateFormatter alloc] init];
- _s3DateFormat.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
- _s3DateFormat.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
- _s3DateFormat.dateFormat = @"yyyy-MM-dd'T'HH':'mm':'ss'.000Z'";
- });
- }
- self.httpResponse = httpResponse;
- _responseData = responseData;
- self.responseError = error;
+ _data = data;
+ _error = error;
self.parser = [[BS3Parser alloc] init];
}
return self;
}
-- (NSDictionary *)responseDictionary {
- if (!_responseDictionary && _responseData) {
- NSDictionary *rawDictionary = [self.parser dictionaryWithData:_responseData];
- _responseDictionary = [BS3Response formattedDictionaryWithParsedDictionary:rawDictionary];
+- (NSDictionary *)dataDictionary {
+ if(!_s3DateFormat) {
+ static dispatch_once_t oncePredicate;
+ dispatch_once(&oncePredicate, ^{
+ _s3DateFormat = [[NSDateFormatter alloc] init];
+ _s3DateFormat.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
+ _s3DateFormat.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
+ _s3DateFormat.dateFormat = @"yyyy-MM-dd'T'HH':'mm':'ss'.000Z'";
+ });
+ }
+ if (!_dataDictionary && _data) {
+ NSDictionary *rawDictionary = [self.parser dictionaryWithData:_data];
+ _dataDictionary = [BS3Response formattedDictionaryWithParsedDictionary:rawDictionary];
}
- return _responseDictionary;
+ return _dataDictionary;
}
- (NSString *)responseType {
- if (!_responseType) {
- _responseType = [self.responseDictionary objectForKey:@"type"];
+ if (!_type) {
+ _type = [self.dataDictionary objectForKey:@"type"];
}
- return _responseType;
+ return _type;
}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.