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 get userApi => _userApi;
|
||||
|
||||
ValuesApi _valuesApi;
|
||||
ValuesApi get valuesApi => _valuesApi;
|
||||
GroupApi _groupApi;
|
||||
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() {
|
||||
_apiClient = ApiClient(
|
||||
@ -24,6 +36,10 @@ class Client {
|
||||
_tokenApi = TokenApi(_apiClient);
|
||||
_authenticationApi = AuthenticationApi(_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 {
|
||||
print("try auth.. ");
|
||||
var isError = true;
|
||||
try {
|
||||
LoginDTO loginDTO = new LoginDTO(email: "test@email.be", password: "kljqsdkljqsd");
|
||||
var user2 = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO);
|
||||
print("USER ??");
|
||||
print(user2);
|
||||
// TODO Call authenticationAuthenticateWithJson to retrieve token and set apiclient bearer token with the result
|
||||
TokenDTO token = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO);
|
||||
print("Token ??");
|
||||
print(token.accessToken);
|
||||
setAccessToken(token.accessToken);
|
||||
isError = false;
|
||||
}
|
||||
catch (e) {
|
||||
print("error auth");
|
||||
}
|
||||
|
||||
var user23 = await clientAPI.userApi.userGet("604a33639b4a377a413045b9");
|
||||
print("user2 values ??");
|
||||
print(user23.email);
|
||||
if (!isError) {
|
||||
UserInfoDetailDTO user = await clientAPI.userApi.userGet("604a33639b4a377a413045b9");
|
||||
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
|
||||
@ -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
|
||||
void onDisconnected() {
|
||||
print('Disconnected');
|
||||
|
||||
@ -284,7 +284,7 @@ class AutomationApi {
|
||||
///
|
||||
/// * [String] userId (required):
|
||||
/// Id of user
|
||||
Future<List<RoomSummaryDTO>> automationGetAll(String userId) async {
|
||||
Future<List<AutomationDTO>> automationGetAll(String userId) async {
|
||||
final response = await automationGetAllWithHttpInfo(userId);
|
||||
if (response.statusCode >= HttpStatus.badRequest) {
|
||||
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"
|
||||
// FormatException when trying to decode an empty string.
|
||||
if (response.body != null && response.statusCode != HttpStatus.noContent) {
|
||||
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<RoomSummaryDTO>') as List)
|
||||
.cast<RoomSummaryDTO>()
|
||||
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<AutomationDTO>') as List)
|
||||
.cast<AutomationDTO>()
|
||||
.toList(growable: false);
|
||||
}
|
||||
return Future<List<RoomSummaryDTO>>.value(null);
|
||||
return Future<List<AutomationDTO>>.value(null);
|
||||
}
|
||||
|
||||
/// Get detail info of a specified automation
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user