Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

Commit

Permalink
Updated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jschmid committed Dec 4, 2014
1 parent 2498949 commit 6ee12e2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 19 deletions.
2 changes: 1 addition & 1 deletion NSURLSession-PromiseKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "NSURLSession-PromiseKit"
s.version = "0.2.1"
s.version = "0.2.2"
s.summary = "Adds a category to NSURLSession to be able to use PromiseKit."
s.homepage = "https://github.com/jschmid/NSURLSession-PromiseKit"
s.license = 'MIT'
Expand Down
40 changes: 30 additions & 10 deletions Pod/Classes/NSURLSession+PromiseKit.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// NSURLSession+PromiseKit.h
// salesamp
//
// Created by Jonas Schmid on 04/12/14.
// Copyright (c) 2014 utribo SA. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "PromiseKit.h"
Expand All @@ -16,22 +8,50 @@
Creates an HTTP GET request promise for the specified URL.
@param url The `http` or `https` URL to be retrieved.
@return NSData *data, NSURLResponse *
@return NSData *, NSURLResponse *
*/
- (PMKPromise *)promiseDataTaskWithURL:(NSURL *)url;

/**
Creates an HTTP request promise based on the specified URL request object.
@param request An object that provides request-specific information such as the URL, cache policy, request type, and body data or body stream.
@return NSData *data, NSURLResponse *
@return NSData *, NSURLResponse *
*/
- (PMKPromise *)promiseDataTaskWithRequest:(NSURLRequest *)request;

/**
Creates a download task promise for the specified URL and saves the results to a file.
@param url An NSURL object that provides the URL to download.
@return NSURL *, NSURLResponse *
*/
- (PMKPromise *)promiseDownloadTaskWithURL:(NSURL *)url;

/**
Creates a download task promise for the specified URL request and saves the results to a file.
@param request An NSURLRequest object that provides the URL, cache policy, request type, body data or body stream, and so on.
@return NSURL *, NSURLResponse *
*/
- (PMKPromise *)promiseDownloadTaskWithRequest:(NSURLRequest *)request;

/**
Creates an HTTP request promise for the specified URL request object and uploads the provided data object.
@param request An NSURLRequest object that provides the URL, cache policy, request type, and so on. The body stream and body data in this request object are ignored.
@param bodyData The body data for the request.
@return NSData *, NSURLResponse *
*/
- (PMKPromise *)promiseUploadTaskWithRequest:(NSURLRequest *)request fromData:(NSData *)bodyData;

/**
Creates an HTTP request promise for uploading the specified file URL.
@param request An NSURLRequest object that provides the URL, cache policy, request type, and so on. The body stream and body data in this request object are ignored.
@param fileURL The URL of the file to upload.
@return NSData *, NSURLResponse *
*/
- (PMKPromise *)promiseUploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL;

@end
8 changes: 0 additions & 8 deletions Pod/Classes/NSURLSession+PromiseKit.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// NSURLSession+PromiseKit.m
// salesamp
//
// Created by Jonas Schmid on 04/12/14.
// Copyright (c) 2014 utribo SA. All rights reserved.
//

#import "NSURLSession+PromiseKit.h"

@implementation NSURLSession (PromiseKit)
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@

## Usage

Import the category

#import "NSURLSession+PromiseKit.h"

Create a `NSURLSession` like you are used to:

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];

Then use the category messages to get a `PMKPromise` instead of a `NSURLSessionTask`.

NSURL *url = [NSURL URLWithString:@"http://pastebin.com/raw.php?i=1gdNuVSh"];
[self.session promiseDataTaskWithURL:url].then( ^(NSData *data, NSURLResponse *response) {
NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Result: %@", result);
}).catch( ^(NSError *e) {
NSLog(@"Error: %@", e);
});

### Example project

To run the example project, clone the repo, and run `pod install` from the Example directory first.

## Requirements
Expand Down

0 comments on commit 6ee12e2

Please sign in to comment.