1
wei
2021-01-21 62d098cb78296feaa6f786a20748921338db838c
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// TuyaSmartRequest.h
// TuyaSmartBaseKit
//
// Copyright (c) 2014-2021 Tuya Inc. (https://developer.tuya.com)
 
#ifndef TuyaSmart_TuyaSmartRequest
#define TuyaSmart_TuyaSmartRequest
 
#import <TuyaSmartUtil/TuyaSmartUtil.h>
 
NS_ASSUME_NONNULL_BEGIN
 
/// @brief TuyaSmartRequest is used for invoke Tuya Cloud API.
///
/// All of the Tuya Cloud API (atop) is made from this class.
///
/// Usually, a request need these params:
///   - API name.
///   - API version.
///   - API params (aka postData). A serializable dictionary object.
///   - Common params (aka getData). A serializable dictionary object. Optional.
///
/// And a response will be back through `success` or `failure` callback.
/// A success callback will give any kind of object, which depends on the specific API.
/// An error callback will give an error object, `error.userInfo[NSLocalizedFailureReasonErrorKey]` is for Tuya error code, `error.localizedDescription` is for detailed reasons.
///
/// @warning The `error.localizedDescription` is not recommend for display, please handle every possible error types and prepare the error messages for your own.
///
@interface TuyaSmartRequest : NSObject
 
/// Network request for Tuya server API.
/// @param apiName API name.
/// @param postData API params.
/// @param version  API version.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)requestWithApiName:(NSString *)apiName
                  postData:(nullable NSDictionary *)postData
                   version:(NSString *)version
                   success:(nullable TYSuccessID)success
                   failure:(nullable TYFailureError)failure;
 
 
/// Network request for Tuya server API.
/// @param apiName API name.
/// @param postData API params.
/// @param getData Common params.
/// @param version API version.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)requestWithApiName:(NSString *)apiName
                  postData:(nullable NSDictionary *)postData
                   getData:(nullable NSDictionary *)getData
                   version:(NSString *)version
                   success:(nullable TYSuccessID)success
                   failure:(nullable TYFailureError)failure;
 
/// Cancel network request.
- (void)cancel;
 
/// Remove network cache.
+ (void)removeAllCache;
 
@end
 
 
@interface TuyaSmartRequest (ApiMerge)
 
/// Invoke multiple api in one network request.
/// @param apiName API name.
/// @param postData API params.
/// @param version API version.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)addMergeRequestWithApiName:(NSString *)apiName
                          postData:(nullable NSDictionary *)postData
                           version:(NSString *)version
                           success:(nullable TYSuccessID)success
                           failure:(nullable TYFailureError)failure;
 
 
/// Send multiple api request.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)sendMergeRequestWithSuccess:(nullable TYSuccessList)success
                            failure:(nullable TYFailureError)failure;
 
 
/// Send multiple api request.
/// @param getData Common params.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)sendMergeRequestWithGetData:(nullable NSDictionary *)getData
                            success:(nullable TYSuccessList)success
                            failure:(nullable TYFailureError)failure;
 
 
/// Remove all multiple api request.
- (void)removeAllMergeRequest;
 
@end
 
@interface TuyaSmartRequest (Encryption)
 
/// Network request for Tuya server API with post data encrypt.
/// @param apiName API name.
/// @param postData API params.
/// @param version API version.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)requestPostDataEncryptWithApiName:(NSString *)apiName
                                 postData:(nullable NSDictionary *)postData
                                  version:(NSString *)version
                                  success:(nullable TYSuccessID)success
                                  failure:(nullable TYFailureError)failure;
 
@end
 
NS_ASSUME_NONNULL_END
 
#endif