Common API Methods

Last Updated on : 2024-11-18 11:32:44

Server API methods

Server APIs are supported by the TuyaSmartRequest class.

API description

- (void)requestWithApiName:(NSString *)apiName
                  postData:(nullable NSDictionary *)postData
                   getData:(nullable NSDictionary *)getData
                   version:(NSString *)version
                   success:(nullable TYSuccessID)success
                   failure:(nullable TYFailureError)failure;

Parameters

Parameter Description
apiName The name of an API.
postData The request parameters.
getData The common parameters.
version The version number of an API.
success The success callback.
failure The failure callback.

Example

- (void)getCountryList {
  // self.request = [TuyaSmartRequest alloc] init];

  [self.request requestWithApiName:@"tuya.m.country.list" postData:nil version:@"1.0" success:^(id result) {

  } failure:^(NSError *error) {

  }];

}

Combined APIs

API description

Two API methods can be combined in the same API request.

- (void)addMergeRequestWithApiName:(NSString *)apiName
                          postData:(nullable NSDictionary *)postData
                           version:(NSString *)version
                           success:(nullable TYSuccessID)success
                           failure:(nullable TYFailureError)failure;

- (void)sendMergeRequestWithGetData:(nullable NSDictionary *)getData
                            success:(nullable TYSuccessList)success
                            failure:(nullable TYFailureError)failure;

Parameters

Parameter Description
apiName The name of an API.
postData The request parameters.
version The version number of an API.
getData The common parameters.
success The success callback.
failure The failure callback.

Example

- (void)loadHomeDataWithHomeId:(long long)homeId {
  // self.request = [TuyaSmartRequest alloc] init];

  [self.request addMergeRequestWithApiName:@"tuya.m.my.group.mesh.list" postData:@{} version:@"1.0" success:nil failure:nil];
  [self.request addApiRequest:@"tuya.m.location.get" postData:@{@"gid": @(homeId)} version:@"2.0" success:nil failure:nil];

  [self.request sendMergeRequestWithGetData:@{@"gid": @(homeId)} success:success failure:failure];
}