mirror of
https://bitbucket.org/myhomie/myhomie_app.git
synced 2025-12-06 00:51:19 +00:00
Test all api + add access token to auth when received it
This commit is contained in:
parent
b210e5d112
commit
a6ef5da499
@ -14,8 +14,20 @@ class Client {
|
|||||||
UserApi _userApi;
|
UserApi _userApi;
|
||||||
UserApi get userApi => _userApi;
|
UserApi get userApi => _userApi;
|
||||||
|
|
||||||
ValuesApi _valuesApi;
|
GroupApi _groupApi;
|
||||||
ValuesApi get valuesApi => _valuesApi;
|
GroupApi get groupApi => _groupApi;
|
||||||
|
|
||||||
|
DeviceApi _deviceApi;
|
||||||
|
DeviceApi get deviceApi => _deviceApi;
|
||||||
|
|
||||||
|
AutomationApi _automationApi;
|
||||||
|
AutomationApi get automationApi => _automationApi;
|
||||||
|
|
||||||
|
ProviderApi _providerApi;
|
||||||
|
ProviderApi get providerApi => _providerApi;
|
||||||
|
|
||||||
|
RoomApi _roomApi;
|
||||||
|
RoomApi get roomApi => _roomApi;
|
||||||
|
|
||||||
Client() {
|
Client() {
|
||||||
_apiClient = ApiClient(
|
_apiClient = ApiClient(
|
||||||
@ -24,6 +36,10 @@ class Client {
|
|||||||
_tokenApi = TokenApi(_apiClient);
|
_tokenApi = TokenApi(_apiClient);
|
||||||
_authenticationApi = AuthenticationApi(_apiClient);
|
_authenticationApi = AuthenticationApi(_apiClient);
|
||||||
_userApi = UserApi(_apiClient);
|
_userApi = UserApi(_apiClient);
|
||||||
_valuesApi = ValuesApi(_apiClient);
|
_groupApi = GroupApi(_apiClient);
|
||||||
|
_deviceApi = DeviceApi(_apiClient);
|
||||||
|
_automationApi = AutomationApi(_apiClient);
|
||||||
|
_providerApi = ProviderApi(_apiClient);
|
||||||
|
_roomApi = RoomApi(_apiClient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,15 +85,55 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
|
|
||||||
void authenticateTRY() async {
|
void authenticateTRY() async {
|
||||||
print("try auth.. ");
|
print("try auth.. ");
|
||||||
LoginDTO loginDTO = new LoginDTO(email: "test@email.be", password: "kljqsdkljqsd");
|
var isError = true;
|
||||||
var user2 = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO);
|
try {
|
||||||
print("USER ??");
|
LoginDTO loginDTO = new LoginDTO(email: "test@email.be", password: "kljqsdkljqsd");
|
||||||
print(user2);
|
TokenDTO token = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO);
|
||||||
// TODO Call authenticationAuthenticateWithJson to retrieve token and set apiclient bearer token with the result
|
print("Token ??");
|
||||||
|
print(token.accessToken);
|
||||||
|
setAccessToken(token.accessToken);
|
||||||
|
isError = false;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
print("error auth");
|
||||||
|
}
|
||||||
|
|
||||||
var user23 = await clientAPI.userApi.userGet("604a33639b4a377a413045b9");
|
if (!isError) {
|
||||||
print("user2 values ??");
|
UserInfoDetailDTO user = await clientAPI.userApi.userGet("604a33639b4a377a413045b9");
|
||||||
print(user23.email);
|
print("user values ??");
|
||||||
|
print(user.email);
|
||||||
|
print(user.id);
|
||||||
|
|
||||||
|
List<RoomSummaryDTO> rooms = await clientAPI.roomApi.roomGetAll(user.id);
|
||||||
|
print("number of rooms " + rooms.length.toString());
|
||||||
|
rooms.forEach((element) {
|
||||||
|
print(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
List<ProviderDTO> providers = await clientAPI.providerApi.providerGetAll(user.id);
|
||||||
|
print("number of providers " + providers.length.toString());
|
||||||
|
providers.forEach((element) {
|
||||||
|
print(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
List<DeviceSummaryDTO> devices = await clientAPI.deviceApi.deviceGetAll(user.id);
|
||||||
|
print("number of devices " + devices.length.toString());
|
||||||
|
/*devices.forEach((element) {
|
||||||
|
print(element);
|
||||||
|
});*/
|
||||||
|
|
||||||
|
List<AutomationDTO> automations = await clientAPI.automationApi.automationGetAll(user.id);
|
||||||
|
print("number of automations " + automations.length.toString());
|
||||||
|
automations.forEach((element) {
|
||||||
|
print(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
List<GroupSummaryDTO> groups = await clientAPI.groupApi.groupGetAll(user.id);
|
||||||
|
print("number of groups " + groups.length.toString());
|
||||||
|
groups.forEach((element) {
|
||||||
|
print(element);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// connection succeeded
|
// connection succeeded
|
||||||
@ -107,6 +147,14 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
});*/
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setAccessToken(String accessToken) {
|
||||||
|
clientAPI.apiApi.authentications.forEach((key, auth) {
|
||||||
|
if (auth is OAuth) {
|
||||||
|
auth.accessToken = accessToken;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// unconnected
|
// unconnected
|
||||||
void onDisconnected() {
|
void onDisconnected() {
|
||||||
print('Disconnected');
|
print('Disconnected');
|
||||||
|
|||||||
@ -284,7 +284,7 @@ class AutomationApi {
|
|||||||
///
|
///
|
||||||
/// * [String] userId (required):
|
/// * [String] userId (required):
|
||||||
/// Id of user
|
/// Id of user
|
||||||
Future<List<RoomSummaryDTO>> automationGetAll(String userId) async {
|
Future<List<AutomationDTO>> automationGetAll(String userId) async {
|
||||||
final response = await automationGetAllWithHttpInfo(userId);
|
final response = await automationGetAllWithHttpInfo(userId);
|
||||||
if (response.statusCode >= HttpStatus.badRequest) {
|
if (response.statusCode >= HttpStatus.badRequest) {
|
||||||
throw ApiException(response.statusCode, _decodeBodyBytes(response));
|
throw ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
@ -293,11 +293,11 @@ class AutomationApi {
|
|||||||
// At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
|
// At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
|
||||||
// FormatException when trying to decode an empty string.
|
// FormatException when trying to decode an empty string.
|
||||||
if (response.body != null && response.statusCode != HttpStatus.noContent) {
|
if (response.body != null && response.statusCode != HttpStatus.noContent) {
|
||||||
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<RoomSummaryDTO>') as List)
|
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<AutomationDTO>') as List)
|
||||||
.cast<RoomSummaryDTO>()
|
.cast<AutomationDTO>()
|
||||||
.toList(growable: false);
|
.toList(growable: false);
|
||||||
}
|
}
|
||||||
return Future<List<RoomSummaryDTO>>.value(null);
|
return Future<List<AutomationDTO>>.value(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get detail info of a specified automation
|
/// Get detail info of a specified automation
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user