Common API Methods

Last Updated on : 2024-03-04 07:33:22

Server API methods

If you are using SDK v5.2 or later, you do not need to take care of the methods mentioned in this topic because they have been built into each library. These methods are valid, but not recommended. For SDKs earlier than v5.2, implementation of some features still relies on the methods in this topic. To determine which apiName should be used, see the respective documentation.

Server APIs are supported by the ThingSmartRequest class.

API description

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

Parameter description

Parameters Description
apiName The API name.
postData The service parameters.
getData The common parameters.
version The API version number.
success The success callback.
failure The failure callback.

Example

- (void)getCountryList {
  // self.request = [ThingSmartRequest 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 ThingSuccessID)success
                           failure:(nullable ThingFailureError)failure;

- (void)sendMergeRequestWithGetData:(nullable NSDictionary *)getData
                            success:(nullable ThingSuccessList)success
                            failure:(nullable ThingFailureError)failure;

Parameter description

Parameters Description
apiName The API name.
postData The service parameters.
version The API version number.
getData The common parameters.
success The success callback.
failure The failure callback.

Example

- (void)loadHomeDataWithHomeId:(long long)homeId {
  // self.request = [ThingSmartRequest 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];
}