Skip to content

Commit 97a91c7

Browse files
committed
Update for AFNetworking 2.3+.
This change also adds a proper podspec to the repository.
1 parent 6e353f6 commit 97a91c7

3 files changed

Lines changed: 25 additions & 13 deletions

File tree

AFHTTPClientLogger.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// AFHTTPClientLogger.h
22
//
3-
// Copyright (c) 2012 Jon Parise
3+
// Copyright (c) 2012-2015 Jon Parise
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy
66
// of this software and associated documentation files (the "Software"), to deal
@@ -20,7 +20,7 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
// THE SOFTWARE.
2222

23-
#import "AFHTTPClient.h"
23+
#import <AFNetworking/AFHTTPRequestOperationManager.h>
2424

2525
typedef enum {
2626
AFHTTPClientLogLevelDebug,
@@ -67,7 +67,7 @@ typedef enum {
6767
/**
6868
`AFHTTPClient` category that provides access to the logger.
6969
*/
70-
@interface AFHTTPClient (Logging)
70+
@interface AFHTTPRequestOperationManager (Logging)
7171

7272
/**
7373
The HTTP client's logger. A logger will be created if one doesn't already exist.

AFHTTPClientLogger.m

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// AFHTTPClientLogger.m
22
//
3-
// Copyright (c) 2012 Jon Parise
3+
// Copyright (c) 2012-2015 Jon Parise
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy
66
// of this software and associated documentation files (the "Software"), to deal
@@ -21,8 +21,8 @@
2121
// THE SOFTWARE.
2222

2323
#import "AFHTTPClientLogger.h"
24-
#import "AFHTTPRequestOperation.h"
25-
#import "AFJSONRequestOperation.h"
24+
25+
#import <AFNetworking/AFHTTPRequestOperation.h>
2626

2727
#import <objc/runtime.h>
2828

@@ -86,9 +86,8 @@ - (void)operationDidStart:(NSNotification *)notification {
8686

8787
id body = nil;
8888
if ([operation.request HTTPBody] && self.level <= AFHTTPClientLogLevelVerbose) {
89-
if ([operation isKindOfClass:[AFJSONRequestOperation class]]) {
90-
body = [NSJSONSerialization JSONObjectWithData:[operation.request HTTPBody] options:NSJSONReadingAllowFragments error:nil];
91-
} else {
89+
body = [NSJSONSerialization JSONObjectWithData:[operation.request HTTPBody] options:NSJSONReadingAllowFragments error:nil];
90+
if (body == nil) {
9291
body = [[NSString alloc] initWithData:[operation.request HTTPBody] encoding:NSUTF8StringEncoding];
9392
}
9493
}
@@ -131,7 +130,6 @@ - (void)operationDidFinish:(NSNotification *)notification {
131130
}
132131

133132
NSURL *URL = (operation.response) ? [operation.response URL] : [operation.request URL];
134-
id responseObject = ([operation isKindOfClass:[AFJSONRequestOperation class]]) ? ((AFJSONRequestOperation *)operation).responseJSON : operation.responseString;
135133

136134
if (operation.error) {
137135
switch (self.level) {
@@ -148,14 +146,14 @@ - (void)operationDidFinish:(NSNotification *)notification {
148146
switch (self.level) {
149147
case AFHTTPClientLogLevelDebug:
150148
if (operation.responseString) {
151-
NSLog(@"<< %ld %@\n%@\n%@", (long)[operation.response statusCode], [URL absoluteString], [operation.response allHeaderFields], responseObject);
149+
NSLog(@"<< %ld %@\n%@\n%@", (long)[operation.response statusCode], [URL absoluteString], [operation.response allHeaderFields], operation.responseObject);
152150
} else {
153151
NSLog(@"<< %ld %@\n%@", (long)[operation.response statusCode], [URL absoluteString], [operation.response allHeaderFields]);
154152
}
155153
break;
156154
case AFHTTPClientLogLevelVerbose:
157155
if (operation.responseString) {
158-
NSLog(@"<< %ld %@\n%@", (long)[operation.response statusCode], [URL absoluteString], responseObject);
156+
NSLog(@"<< %ld %@\n%@", (long)[operation.response statusCode], [URL absoluteString], operation.responseObject);
159157
} else {
160158
NSLog(@"<< %ld %@", (long)[operation.response statusCode], [URL absoluteString]);
161159
}
@@ -173,7 +171,7 @@ - (void)operationDidFinish:(NSNotification *)notification {
173171

174172
#pragma mark -
175173

176-
@implementation AFHTTPClient (Logging)
174+
@implementation AFHTTPRequestOperationManager (Logging)
177175

178176
static char AFHTTPClientLoggerObject;
179177

AFHTTPClientLogger.podspec

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Pod::Spec.new do |s|
2+
s.name = 'AFHTTPClientLogger'
3+
s.version = '0.6.0'
4+
s.license = 'MIT'
5+
s.authors = { 'Jon Parise' => 'jon@indelible.org' }
6+
s.summary = 'AFNetworking Extension for request logging.'
7+
s.homepage = 'https://github.com/jparise/AFHTTPClientLogger'
8+
s.source = { :git => 'https://github.com/jparise/AFHTTPClientLogger.git', :tag => s.version }
9+
s.requires_arc = true
10+
11+
s.source_files = 'AFHTTPClientLogger.{h,m}'
12+
13+
s.ios.deployment_target = '6.0'
14+
end

0 commit comments

Comments
 (0)