Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ARC compatiblity #2

Merged
merged 1 commit into from

2 participants

@dhilipsiva

No description provided.

@jallen jallen merged commit 6c6cd74 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 22, 2013
  1. @dhilipsiva

    Enable arc

    dhilipsiva authored
This page is out of date. Refresh to see the latest.
Showing with 45 additions and 49 deletions.
  1. +20 −20 AFS3Client.h
  2. +25 −29 AFS3Client.m
View
40 AFS3Client.h 100644 → 100755
@@ -11,10 +11,10 @@
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
-//
+//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
-//
+//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -47,7 +47,7 @@ extern NSString *const AFIS3AccessPolicyBucketOwnerFullControl;
@property (nonatomic, retain) NSString *accessPolicy;
/**
- Initializes an `AFS3Client` object with the specified base URL.
+ Initializes an `AFS3Client` object with the specified base URL.
@param accessKey Your S3 access key.
@param secretKey Your S3 secret key.
@@ -59,12 +59,12 @@ extern NSString *const AFIS3AccessPolicyBucketOwnerFullControl;
@return The newly-initialized HTTP client
*/
-- (id)initWithAccessKey:(NSString *)accessKey
- secretAccessKey:(NSString *)secretKey
- sessionToken:(NSString *)sessionToken;
+- (id)initWithAccessKey:(NSString *)accessKey
+ secretAccessKey:(NSString *)secretKey
+ sessionToken:(NSString *)sessionToken;
/**
- Initializes an `AFS3Client` object with the specified base URL.
+ Initializes an `AFS3Client` object with the specified base URL.
@param accessKey Your S3 access key.
@param secretKey Your S3 secret key.
@@ -76,8 +76,8 @@ extern NSString *const AFIS3AccessPolicyBucketOwnerFullControl;
@return The newly-initialized HTTP client
*/
-- (id)initWithAccessKey:(NSString *)accessKey
- secretAccessKey:(NSString *)secretKey;
+- (id)initWithAccessKey:(NSString *)accessKey
+ secretAccessKey:(NSString *)secretKey;
/**
PUT a new S3 object with the specified bucket and key
@@ -86,22 +86,22 @@ extern NSString *const AFIS3AccessPolicyBucketOwnerFullControl;
@param key Path to new object ex. '/path/to/your/object.jpg'
*/
-- (void)putObjectForData:(NSData *)data
- withBucket:(NSString *)bucket
- key:(NSString *)key
- success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
- failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
+- (void)putObjectForData:(NSData *)data
+ withBucket:(NSString *)bucket
+ key:(NSString *)key
+ success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
/**
Overrides AFHTTPClient putPath function so we can post the data in the body of the request without using parameters
- @param path The path to be appended to the HTTP client's base URL and used as the request URL.
+ @param path The path to be appended to the HTTP client's base URL and used as the request URL.
@param data Data for the object.
@param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request.
@param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred.
*/
-- (void)putPath:(NSString *)path
+- (void)putPath:(NSString *)path
data:(NSData *)data
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
@@ -115,11 +115,11 @@ extern NSString *const AFIS3AccessPolicyBucketOwnerFullControl;
@param path The path to be appended to the HTTP client's base URL and used as the request URL.
@param data The data to be sent in the body of the HTTP Request.
- @return An `NSMutableURLRequest` object
+ @return An `NSMutableURLRequest` object
*/
-- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
- path:(NSString *)path
- data:(NSData *)data;
+- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
+ path:(NSString *)path
+ data:(NSData *)data;
/**
View
54 AFS3Client.m 100644 → 100755
@@ -11,10 +11,10 @@
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
-//
+//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
-//
+//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -61,18 +61,13 @@ - (id)initWithAccessKey:(NSString *)accessKey secretAccessKey:(NSString *)secret
}
- (void)dealloc {
- [_accessKey release];
- [_secretAccessKey release];
- [_sessionToken release];
- [_accessPolicy release];
- [super dealloc];
}
-- (void)putObjectForData:(NSData *)data
- withBucket:(NSString *)bucket
- key:(NSString *)key
- success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
- failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
+- (void)putObjectForData:(NSData *)data
+ withBucket:(NSString *)bucket
+ key:(NSString *)key
+ success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
{
NSString *path = [NSString stringWithFormat:@"%@%@", bucket, key];
@@ -88,9 +83,9 @@ - (void)putObjectForData:(NSData *)data
}];
}
-#pragma mark - AFHTTPClient
+#pragma mark - AFHTTPClient
-- (void)putPath:(NSString *)path
+- (void)putPath:(NSString *)path
data:(NSData *)data
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
@@ -100,9 +95,9 @@ - (void)putPath:(NSString *)path
[self enqueueHTTPRequestOperation:operation];
}
-- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
- path:(NSString *)path
- data:(NSData *)data
+- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
+ path:(NSString *)path
+ data:(NSData *)data
{
NSMutableURLRequest *request = [super requestWithMethod:method path:path parameters:nil];
[request setHTTPBody:data];
@@ -133,8 +128,8 @@ - (void)buildRequestHeadersForBucket:(NSString *)bucket key:(NSString *)key {
NSString *authorizationString = [NSString stringWithFormat:@"AWS %@:%@", _accessKey, signature];
[self setDefaultHeader:@"Authorization" value:authorizationString];
}
-
-
+
+
- (NSMutableDictionary *)S3Headers {
NSMutableDictionary *headers = [NSMutableDictionary dictionary];
if (_accessPolicy) {
@@ -145,14 +140,14 @@ - (NSMutableDictionary *)S3Headers {
}
return headers;
}
-
+
#pragma mark - Helper Methods
+ (NSString *)stringByURLEncodingForS3Path:(NSString *)key {
if (!key) {
return @"/";
}
- NSString *path = [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)key, NULL, CFSTR(":?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)) autorelease];
+ NSString *path = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)key, NULL, CFSTR(":?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)));
if (![[path substringWithRange:NSMakeRange(0, 1)] isEqualToString:@"/"]) {
path = [@"/" stringByAppendingString:path];
}
@@ -167,8 +162,8 @@ + (NSDateFormatter *)S3ResponseDateFormatter {
NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
NSDateFormatter *dateFormatter = [threadDict objectForKey:@"ASIS3ResponseDateFormatter"];
if (dateFormatter == nil) {
- dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
- [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
+ dateFormatter = [[NSDateFormatter alloc] init];
+ [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] ];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'.000Z'"];
[threadDict setObject:dateFormatter forKey:@"ASIS3ResponseDateFormatter"];
@@ -180,9 +175,9 @@ + (NSDateFormatter *)S3RequestDateFormatter {
NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
NSDateFormatter *dateFormatter = [threadDict objectForKey:@"ASIS3RequestHeaderDateFormatter"];
if (dateFormatter == nil) {
- dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
+ dateFormatter = [[NSDateFormatter alloc] init];
// Prevent problems with dates generated by other locales (tip from: http://rel.me/t/date/)
- [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
+ [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] ];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss Z"];
[threadDict setObject:dateFormatter forKey:@"ASIS3RequestHeaderDateFormatter"];
@@ -219,7 +214,7 @@ + (NSString *)base64forData:(NSData *)theData {
output[theIndex + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '=';
}
- return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
+ return [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
}
// From: http://stackoverflow.com/questions/476455/is-there-a-library-for-iphone-to-work-with-hmac-sha-1-encoding
@@ -239,17 +234,18 @@ + (NSData *)HMACSHA1withKey:(NSString *)key forString:(NSString *)string {
}
+ (NSString *)mimeTypeForFileAtPath:(NSString *)path {
- if (![[[[NSFileManager alloc] init] autorelease] fileExistsAtPath:path]) {
+ if (![[[NSFileManager alloc] init]fileExistsAtPath:path]) {
return nil;
}
// Borrowed from http://stackoverflow.com/questions/2439020/wheres-the-iphone-mime-type-database
- CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)[path pathExtension], NULL);
+ CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[path pathExtension], NULL);
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType);
+ NSString *mimeType = (__bridge_transfer NSString *)(MIMEType);
CFRelease(UTI);
if (!MIMEType) {
return @"application/octet-stream";
}
- return [NSMakeCollectable(MIMEType) autorelease];
+ return mimeType;
}
Something went wrong with that request. Please try again.