Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// Copyright 2019 Google
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
 
15
#import <Foundation/Foundation.h>
16
 
17
/**
18
 * This class is a helper class for generating Multipart requests, as described in
19
 * http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html. In the case of multiple part messages, in
20
 * which one or more different sets of data are combined in a single body, a "multipart"
21
 * Content-Type field must appear in the entity's header. The body must then contain one or more
22
 * "body parts," each preceded by an encapsulation boundary, and the last one followed by a closing
23
 * boundary. Each part starts with an encapsulation boundary, and then contains a body part
24
 * consisting of header area, a blank line, and a body area.
25
 */
26
@interface FIRCLSMultipartMimeStreamEncoder : NSObject
27
 
28
/**
29
 * Convenience class method to populate a NSMutableURLRequest with data from a block that takes an
30
 * instance of this class as input.
31
 */
32
+ (void)populateRequest:(NSMutableURLRequest *)request
33
    withDataFromEncoder:(void (^)(FIRCLSMultipartMimeStreamEncoder *encoder))block;
34
 
35
/**
36
 * Returns a NSString instance with multipart/form-data appended to the boundary.
37
 */
38
+ (NSString *)contentTypeHTTPHeaderValueWithBoundary:(NSString *)boundary;
39
/**
40
 * Convenience class method that returns an instance of this class
41
 */
42
+ (instancetype)encoderWithStream:(NSOutputStream *)stream andBoundary:(NSString *)boundary;
43
/**
44
 * Returns a unique boundary string.
45
 */
46
+ (NSString *)generateBoundary;
47
/**
48
 * Designated initializer
49
 * @param stream NSOutputStream associated with the Multipart request
50
 * @param boundary the unique Boundary string to be used
51
 */
52
- (instancetype)initWithStream:(NSOutputStream *)stream
53
                   andBoundary:(NSString *)boundary NS_DESIGNATED_INITIALIZER;
54
- (instancetype)init NS_UNAVAILABLE;
55
+ (instancetype)new NS_UNAVAILABLE;
56
/**
57
 * Encodes this block within the boundary on the output stream
58
 */
59
- (void)encode:(void (^)(void))block;
60
/**
61
 * Adds the contents of the file data with given Mime type anf fileName within the boundary in
62
 * stream
63
 */
64
- (void)addFileData:(NSData *)data
65
           fileName:(NSString *)fileName
66
           mimeType:(NSString *)mimeType
67
          fieldName:(NSString *)name;
68
/**
69
 * Convenience method for the method above. Converts fileURL to data and calls the above method.
70
 */
71
- (void)addFile:(NSURL *)fileURL
72
       fileName:(NSString *)fileName
73
       mimeType:(NSString *)mimeType
74
      fieldName:(NSString *)name;
75
/**
76
 * Adds this field and value in the stream
77
 */
78
- (void)addValue:(id)value fieldName:(NSString *)name;
79
/**
80
 * String referring to the multipart MIME type with boundary
81
 */
82
@property(nonatomic, copy, readonly) NSString *contentTypeHTTPHeaderValue;
83
/**
84
 * Length of the data written to stream
85
 */
86
@property(nonatomic, copy, readonly) NSString *contentLengthHTTPHeaderValue;
87
 
88
@end