-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add http call for all subscription update list
- Loading branch information
Sebastien Dugene
committed
Jan 11, 2021
1 parent
ace6cb4
commit e637266
Showing
8 changed files
with
176 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.0.17 | ||
|
||
* Add http call for all subscription update list | ||
|
||
## 0.0.16 | ||
|
||
* Clean code | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:rocket_chat_connector_flutter/models/subscription_update.dart'; | ||
|
||
class Subscription { | ||
List<SubscriptionUpdate> update; | ||
Object remove; | ||
bool success; | ||
|
||
Subscription({ | ||
this.update, | ||
this.remove, | ||
this.success, | ||
}); | ||
|
||
Subscription.fromMap(Map<String, dynamic> json) { | ||
if (json != null) { | ||
if (json['update'] != null) { | ||
List<dynamic> jsonList = json['update'].runtimeType == String // | ||
? jsonDecode(json['update']) | ||
: json['update']; | ||
update = jsonList | ||
.where((json) => json != null) | ||
.map((value) => SubscriptionUpdate.fromMap(value)) | ||
.toList(); | ||
} else { | ||
update = null; | ||
} | ||
|
||
remove = json['remove'] != null ? json['remove'] : null; | ||
success = json['success']; | ||
} | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'Subscription{update: $update, remove: $remove, success: $success}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:rocket_chat_connector_flutter/models/user.dart'; | ||
|
||
class SubscriptionUpdate { | ||
String id; | ||
bool open; | ||
bool alert; | ||
int unread; | ||
int userMentions; | ||
int groupMentions; | ||
DateTime ts; | ||
String rid; | ||
String name; | ||
String fName; | ||
String t; | ||
User u; | ||
DateTime ls; | ||
DateTime updatedAt; | ||
List<String> roles; | ||
|
||
SubscriptionUpdate({ | ||
this.id, | ||
this.open, | ||
this.alert, | ||
this.unread, | ||
this.userMentions, | ||
this.groupMentions, | ||
this.ts, | ||
this.rid, | ||
this.name, | ||
this.fName, | ||
this.t, | ||
this.u, | ||
this.ls, | ||
this.updatedAt, | ||
this.roles, | ||
}); | ||
|
||
SubscriptionUpdate.fromMap(Map<String, dynamic> json) { | ||
if (json != null) { | ||
id = json['_id']; | ||
open = json['open']; | ||
alert = json['alert']; | ||
unread = json['unread']; | ||
userMentions = json['userMentions']; | ||
groupMentions = json['groupMentions']; | ||
ts = json['ts'] != null ? DateTime.parse(json['ts']) : null; | ||
rid = json['rid']; | ||
name = json['name']; | ||
fName = json['fName']; | ||
t = json['t']; | ||
u = json['u'] != null ? User.fromMap(json['u']) : null; | ||
ls = json['ls'] != null ? DateTime.parse(json['ls']) : null; | ||
updatedAt = json['_updatedAt'] != null | ||
? DateTime.parse(json['_updatedAt']) | ||
: null; | ||
if (json['roles'] != null) { | ||
List<dynamic> jsonList = json['roles'].runtimeType == String // | ||
? jsonDecode(json['roles']) | ||
: json['roles']; | ||
roles = jsonList | ||
.where((json) => json != null) | ||
.map((value) => value.toString()) | ||
.toList(); | ||
} else { | ||
roles = null; | ||
} | ||
} | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'SubscriptionUpdate{id: $id, open: $open, alert: $alert, unread: $unread, userMentions: $userMentions, groupMentions: $groupMentions, ts: $ts, rid: $rid, name: $name, fName: $fName, t: $t, u: $u, ls: $ls, updatedAt: $updatedAt, roles: $roles}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:http/http.dart' as http; | ||
import 'package:rocket_chat_connector_flutter/exceptions/exception.dart'; | ||
import 'package:rocket_chat_connector_flutter/models/authentication.dart'; | ||
import 'package:rocket_chat_connector_flutter/models/subscription.dart'; | ||
import 'package:rocket_chat_connector_flutter/services/http_service.dart'; | ||
|
||
class SubscriptionService { | ||
HttpService _httpService; | ||
|
||
SubscriptionService(this._httpService); | ||
|
||
Future<Subscription> getSubscriptions(Authentication authentication) async { | ||
http.Response response = await _httpService.get( | ||
'/api/v1/subscriptions.get', | ||
authentication, | ||
); | ||
|
||
if (response?.statusCode == 200) { | ||
if (response?.body?.isNotEmpty == true) { | ||
return Subscription.fromMap(jsonDecode(response.body)); | ||
} else { | ||
return Subscription(); | ||
} | ||
} | ||
throw RocketChatException(response?.body); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters