Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ishkawa committed Apr 13, 2014
2 parents 525b536 + 99877b9 commit 9ef1661
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 108 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
Pods
Podfile.lock
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -2,6 +2,7 @@ rvm: 1.9.3
language: objective-c

before_install:
- gem install cocoapods -v '0.29.0'
- sudo easy_install cpp-coveralls

script:
Expand Down
6 changes: 3 additions & 3 deletions ISHTTPOperation.podspec
@@ -1,17 +1,17 @@
Pod::Spec.new do |s|
s.name = "ISHTTPOperation"
s.version = "1.1.2"
s.version = "1.2.0"
s.summary = "a subclass of NSOperation to wrap asynchronous NSURLConnection."
s.homepage = "https://github.com/ishkawa/ISHTTPOperation"
s.author = { "Yosuke Ishikawa" => "y@ishkawa.org" }
s.source = { :git => "https://github.com/ishkawa/ISHTTPOperation.git", :tag => "1.1.2" }
s.source = { :git => "https://github.com/ishkawa/ISHTTPOperation.git", :tag => "1.2.0" }
s.platform = :ios, '4.3'
s.requires_arc = true
s.source_files = 'ISHTTPOperation/**/*.{h,m}'
s.license = {
:type => 'MIT',
:text => <<-LICENSE
Copyright (c) 2013 Yosuke Ishikawa
Copyright (c) 2013-2014 Yosuke Ishikawa
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights 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:
Expand Down
4 changes: 1 addition & 3 deletions ISHTTPOperation.xcodeproj/project.pbxproj
Expand Up @@ -297,7 +297,7 @@
7F907E6416E4A1B9005D06BA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0460;
LastUpgradeCheck = 0510;
ORGANIZATIONNAME = "Yosuke Ishikawa";
TargetAttributes = {
7FA0D63C1886BC7500BB5C93 = {
Expand Down Expand Up @@ -564,7 +564,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = FB94C60D5CF04D1386244964 /* Pods-UnitTests.xcconfig */;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
Expand Down Expand Up @@ -597,7 +596,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = FB94C60D5CF04D1386244964 /* Pods-UnitTests.xcconfig */;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
LastUpgradeVersion = "0510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
LastUpgradeVersion = "0510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
10 changes: 5 additions & 5 deletions ISHTTPOperation/ISHTTPOperation.h
Expand Up @@ -7,12 +7,12 @@
BOOL _finished;
}

@property (nonatomic, strong) NSURLRequest *request;
@property (nonatomic, copy) void (^handler)(NSHTTPURLResponse *response, id object, NSError *error);

+ (void)sendRequest:(NSURLRequest *)request
handler:(void (^)(NSHTTPURLResponse *response, id object, NSError *error))handler;
@property (nonatomic, readonly) NSURLRequest *request;
@property (nonatomic, readonly) NSHTTPURLResponse *response;
@property (nonatomic, readonly) NSData *receivedData;
@property (nonatomic, readonly) void (^handler)(NSHTTPURLResponse *response, id object, NSError *error);

+ (void)sendRequest:(NSURLRequest *)request handler:(void (^)(NSHTTPURLResponse *response, id object, NSError *error))handler;
+ (void)sendRequest:(NSURLRequest *)request
queue:(NSOperationQueue *)queue
handler:(void (^)(NSHTTPURLResponse *response, id object, NSError *error))handler;
Expand Down
49 changes: 26 additions & 23 deletions ISHTTPOperation/ISHTTPOperation.m
Expand Up @@ -2,16 +2,14 @@

@interface ISHTTPOperation ()

@property (nonatomic, strong) NSURLConnection *connection;
@property (nonatomic, strong) NSHTTPURLResponse *response;
@property (nonatomic, strong) NSMutableData *data;
@property (nonatomic, readonly) NSURLConnection *connection;
@property (nonatomic, readonly) NSMutableData *buffer;
#if OS_OBJECT_USE_OBJC
@property (nonatomic, strong) dispatch_semaphore_t semaphore;
#else
@property (nonatomic, assign) dispatch_semaphore_t semaphore;
#endif


@end

@implementation ISHTTPOperation
Expand Down Expand Up @@ -42,9 +40,9 @@ - (id)initWithRequest:(NSURLRequest *)request handler:(void (^)(NSHTTPURLRespons
{
self = [super init];
if (self) {
self.request = request;
self.handler = handler;
self.semaphore = dispatch_semaphore_create(1);
_request = request;
_handler = handler;
_semaphore = dispatch_semaphore_create(1);

_finished = NO;
_executing = NO;
Expand All @@ -59,7 +57,7 @@ - (void)dealloc
#endif
}

#pragma mark - KVO
#pragma mark - accessor

- (BOOL)isExecuting
{
Expand All @@ -76,6 +74,11 @@ - (BOOL)isConcurrent
return YES;
}

- (NSData *)receivedData
{
return [self.buffer copy];
}

#pragma mark -

- (void)start
Expand Down Expand Up @@ -103,7 +106,7 @@ - (void)main
dispatch_semaphore_signal(self.semaphore);
return;
}
self.connection = [NSURLConnection connectionWithRequest:self.request delegate:self];
_connection = [NSURLConnection connectionWithRequest:self.request delegate:self];
dispatch_semaphore_signal(self.semaphore);
}

Expand All @@ -121,8 +124,8 @@ - (void)cancel
{
dispatch_semaphore_wait(self.semaphore, DISPATCH_TIME_FOREVER);
[self.connection cancel];
self.connection = nil;
self.handler = nil;
_connection = nil;
_handler = nil;
dispatch_semaphore_signal(self.semaphore);

[super cancel];
Expand All @@ -149,34 +152,34 @@ - (id)processData:(NSData *)data

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
self.response = (NSHTTPURLResponse *)response;
self.data = [NSMutableData data];
_response = (NSHTTPURLResponse *)response;
_buffer = [NSMutableData data];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.data appendData:data];
[self.buffer appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
id object = [self processData:self.data];
if (self.handler) {
dispatch_async(dispatch_get_main_queue(), ^{
id object = [self processData:self.buffer];
dispatch_async(dispatch_get_main_queue(), ^{
if (self.handler) {
self.handler(self.response, object, nil);
});
}
}
});

[self completeOperation];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
if (self.handler) {
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{
if (self.handler) {
self.handler(self.response, nil, error);
});
}
}
});

[self completeOperation];
}
Expand Down
20 changes: 0 additions & 20 deletions Podfile.lock

This file was deleted.

0 comments on commit 9ef1661

Please sign in to comment.