Skip to content

Commit 006f183

Browse files
committed
Update README.md.
1 parent 9370da8 commit 006f183

File tree

5 files changed

+62
-40
lines changed

5 files changed

+62
-40
lines changed

README.md

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
11
# STNetTaskQueue
2-
Queue for managing network requests
2+
STNetTaskQueue is a networking queue library for iOS and OS X. It's abstract and can be implemented in different protocols.
33

4-
STNetTaskQueue may be your choice if you want to handle each network request stuff in separated STNetTask instead of having all the network requests logics in a "Manager" class.
4+
STNetTaskQueue avoid you from directly dealing with "url", "request packing" and "response parsing". All networking tasks are described and processed by subclassing STNetTask, which provides you a clean code style in UI layer when handling networking.
55

6-
**STHTTPNetTaskQueueHandler** is included, which is for HTTP based network reqeust. If you are looking for a socket or other protocol based handler, currently you should write your own net task queue handler and conform to **STNetTaskQueueHandler** protocol. **STHTTPNetTaskQeueuHandler** depends on [AFNetworking](https://github.com/AFNetworking/AFNetworking), which is included in example project.
6+
## STHTTPNetTaskQueueHandler
77

8-
## Features
9-
- Retry net task with specified max retry count.
10-
- Delegate for net task result according to "uri" of net task.
11-
- More features are coming as STNetTaskQueue is extendible.
8+
STHTTPNetTaskQueueHandler is a HTTP based implementation of STNetTaskQueueHandler. It provides different ways to pack request and parse response, e.g. STHTTPNetTaskRequestJSON is for JSON format request body, STHTTPNetTaskResponseJSON is for JSON format response data and STHTTPNetTaskRequestFormData is for form data format request body which is mostly used for uploading file.
129

13-
## Sequence Chart
14-
![STNetTaskQueue Sequence Chart](https://cloud.githubusercontent.com/assets/1491282/7292210/6d761f6a-e9cc-11e4-9620-0075082dcc8e.png)
10+
## STNetTask
1511

16-
## Get Started
12+
STNetTask is abstract, it provides basic properties and callbacks for subclassing.
13+
14+
## STNetTaskDelegate
15+
16+
STNetTaskDelegate is the delegate protocol for observing result of STNetTask, mostly it is used in view controller.
1717

18-
### Installation with CocoaPods
18+
## STNetTaskChain
1919

20-
[CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like AFNetworking in your projects. See the ["Getting Started" guide for more information](https://github.com/AFNetworking/AFNetworking/wiki/Getting-Started-with-AFNetworking).
20+
STNetTaskChain is a chain which processes an array of STNetTask serially. A net task chain is considered as successful only if all net tasks in the chain are end without error.
21+
22+
## Get Started
2123

22-
#### Podfile
24+
### Podfile
2325

2426
```ruby
2527
platform :ios, '7.0'
26-
pod 'STNetTaskQueue', '~> 0.0.1'
28+
pod 'STNetTaskQueue', '~> 0.0.2'
2729
```
2830

29-
31+
### Use STNetTaskQueue in your project
3032
#### Step 1: Setup STNetTaskQueue after your app launch
3133
```objc
3234
NSURL *baseUrl = [NSURL URLWithString:@"http://api.openweathermap.org"];
3335
STHTTPNetTaskQueueHandler *httpHandler = [[STHTTPNetTaskQueueHandler alloc] initWithBaseURL:baseUrl];
3436
[STNetTaskQueue sharedQueue].handler = httpHandler;
3537
```
3638
37-
#### Step 2: Write your net task for each reqeust
39+
#### Step 2: Create your net task
3840
```objc
3941
@interface STOpenWeatherNetTask : STHTTPNetTask
4042
@@ -61,7 +63,7 @@ STHTTPNetTaskQueueHandler *httpHandler = [[STHTTPNetTaskQueueHandler alloc] init
6163

6264
- (NSUInteger)maxRetryCount
6365
{
64-
return 3;
66+
return 3; // Retry after error occurs
6567
}
6668

6769
- (NSDictionary *)parameters
@@ -79,25 +81,28 @@ STHTTPNetTaskQueueHandler *httpHandler = [[STHTTPNetTaskQueueHandler alloc] init
7981
@end
8082
```
8183
82-
#### Step 3: Go and get your response
84+
#### Step 3: Send net task and delegate for the result
8385
```objc
84-
if (_openWeatherTask.pending) {
85-
return;
86+
- (void)sendOpenWeatherTask
87+
{
88+
if (_openWeatherTask.pending) {
89+
return;
90+
}
91+
_openWeatherTask = [STOpenWeatherNetTask new];
92+
_openWeatherTask.latitude = @"1.306038";
93+
_openWeatherTask.longitude = @"103.772962";
94+
// Task delegate will be a weak reference, so there is no need to remove it manually.
95+
// It's appropriate to add task delegate here because duplicated task delegates will be ignored by STNetTaskQueue.
96+
[[STNetTaskQueue sharedQueue] addTaskDelegate:self uri:_openWeatherTask.uri];
97+
[[STNetTaskQueue sharedQueue] addTask:_openWeatherTask];
8698
}
87-
_openWeatherTask = [STOpenWeatherNetTask new];
88-
_openWeatherTask.latitude = @"1.306038";
89-
_openWeatherTask.longitude = @"103.772962";
90-
// Task delegate will be a weak reference, so no need to remove it manually.
91-
// Duplicated task delegates will be ignored by STNetTaskQueue, so it's fine to invoke addTaskDelegate here.
92-
[[STNetTaskQueue sharedQueue] addTaskDelegate:self uri:_openWeatherTask.uri];
93-
[[STNetTaskQueue sharedQueue] addTask:_openWeatherTask];
9499
```
95100

96101
```objc
97102
- (void)netTaskDidEnd:(STNetTask *)task
98103
{
99-
// It's necessary to detect if _openWeatherTask != task and return,
100-
// if you have mutiple instance/viewController deleagating the same uri.
104+
// It's necessary to detect if _openWeatherTask != task,
105+
// if you have mutiple viewControllers deleagating the same uri.
101106
if (_openWeatherTask != task) {
102107
return;
103108
}
@@ -112,5 +117,10 @@ _openWeatherTask.longitude = @"103.772962";
112117
_goBtn.hidden = YES;
113118
}
114119
```
120+
For more details, download the example project or check out unit tests for usage references.
121+
122+
## What's Next
115123

116-
You can see more details in example project. The example is tested with iOS SDK 8.1, XCode 6.1.1 and iPhone 6 simulator.
124+
- More unit tests for STHTTPNetTaskQueueHandler.
125+
- Detailed documentation for STNetTaskQueue, STNetTask, STNetTaskChain.
126+
- Support other protocol based STNetTaskQueueHandler, e.g. STNetTaskQueueHandler for ProtocolBuffers.

STNetTaskQueue/STNetTask.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010

1111
FOUNDATION_EXPORT NSString *const STNetTaskUnknownError;
1212

13+
@class STNetTask;
14+
15+
@protocol STNetTaskDelegate <NSObject>
16+
17+
- (void)netTaskDidEnd:(STNetTask *)task;
18+
19+
@end
20+
1321
@interface STNetTask : NSObject
1422

1523
@property (nonatomic, strong) NSError *error;

STNetTaskQueue/STNetTaskQueue.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111

1212
@class STNetTaskQueue;
1313

14-
@protocol STNetTaskDelegate <NSObject>
15-
16-
- (void)netTaskDidEnd:(STNetTask *)task;
17-
18-
@end
19-
2014
@protocol STNetTaskQueueHandler <NSObject>
2115

2216
- (void)netTaskQueue:(STNetTaskQueue *)netTaskQueue task:(STNetTask *)task taskId:(int)taskId;

STNetTaskQueueExample/STNetTaskQueueExample/STOpenWeatherNetTask.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ - (NSString *)uri
2020
return @"data/2.5/weather";
2121
}
2222

23+
- (NSUInteger)maxRetryCount
24+
{
25+
return 3; // Retry after error occurs
26+
}
27+
2328
- (NSDictionary *)parameters
2429
{
2530
NSLog(@"Pack request parameters");

STNetTaskQueueExample/STNetTaskQueueExample/ViewController.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,28 @@ - (void)viewDidLoad
4242
}
4343

4444
- (void)goBtnDidTap
45+
{
46+
[self sendOpenWeatherTask];
47+
}
48+
49+
- (void)sendOpenWeatherTask
4550
{
4651
if (_openWeatherTask.pending) {
4752
return;
4853
}
4954
_openWeatherTask = [STOpenWeatherNetTask new];
5055
_openWeatherTask.latitude = @"1.306038";
5156
_openWeatherTask.longitude = @"103.772962";
52-
// Task delegate will be a weak reference, so no need to remove it manually.
53-
// Duplicated task delegates will be ignored by STNetTaskQueue, so it's fine to invoke addTaskDelegate here.
57+
// Task delegate will be a weak reference, so there is no need to remove it manually.
58+
// It's appropriate to add task delegate here because duplicated task delegates will be ignored by STNetTaskQueue.
5459
[[STNetTaskQueue sharedQueue] addTaskDelegate:self uri:_openWeatherTask.uri];
5560
[[STNetTaskQueue sharedQueue] addTask:_openWeatherTask];
5661
}
5762

5863
- (void)netTaskDidEnd:(STNetTask *)task
5964
{
60-
// It's necessary to detect if _openWeatherTask != task and return,
61-
// if you have mutiple instance/viewController deleagating the same uri.
65+
// It's necessary to detect if _openWeatherTask != task,
66+
// if you have mutiple viewControllers deleagating the same uri.
6267
if (_openWeatherTask != task) {
6368
return;
6469
}

0 commit comments

Comments
 (0)