summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLURLSession.h
blob: 0d2a22e28cc41112b0cc64769526ed5aff4dabd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
//  SDLURLConnection.h
//  SmartDeviceLink-iOS
//
//  Created by Joel Fischer on 8/17/15.
//  Copyright (c) 2015 smartdevicelink. All rights reserved.
//

#import <Foundation/Foundation.h>


typedef void (^SDLURLConnectionRequestCompletionHandler)(NSData *__nullable data, NSURLResponse *__nullable response, NSError *__nullable error);


NS_ASSUME_NONNULL_BEGIN

@interface SDLURLSession : NSObject

@property (assign, nonatomic) NSURLRequestCachePolicy cachePolicy;

/**
 *  If any task is started with a request that is at the default timeout (60.0 sec), it will be altered to this connection timeout (by default 45.0 sec).
 */
@property (assign, nonatomic) NSTimeInterval connectionTimeout;

/**
 *  Get the default session, a singleton.
 *
 *  @return The default session
 */
+ (instancetype)defaultSession;

/**
 *  Retrieves data from a specified URL. Default settings for timeout and cache policy will be used.
 *
 *  @param url               An NSURLRequest will be assembled for this URL
 *  @param completionHandler The completion handler that will be called when the request is complete
 */
- (void)dataFromURL:(NSURL *)url completionHandler:(SDLURLConnectionRequestCompletionHandler)completionHandler;

/**
 *  Starts a URL request using data supplied.
 *
 *  @param request           An NSURLRequest that provides the URL, cache policy, request method, etc. The HTTPBody data in this request will be ignored
 *  @param data              The data to be uploaded over HTTP
 *  @param completionHandler The completion handler that will be called when the request is complete
 */
- (void)uploadWithURLRequest:(NSURLRequest *)request data:(NSData *)data completionHandler:(SDLURLConnectionRequestCompletionHandler)completionHandler;

/**
 *  Tells all pending requests to cancel
 */
- (void)cancelAllTasks;

@end

NS_ASSUME_NONNULL_END