diff --git a/lib/src/Client.dart b/lib/src/Client.dart index d2e13b4f..fa8ee94c 100644 --- a/lib/src/Client.dart +++ b/lib/src/Client.dart @@ -23,6 +23,7 @@ import 'dart:async'; import 'dart:core'; +import 'requests/SetPushersRequest.dart'; import 'responses/ErrorResponse.dart'; import 'Connection.dart'; import 'RoomList.dart'; @@ -246,4 +247,20 @@ class Client { return PushrulesResponse.fromJson(resp); } + + /// This endpoint allows the creation, modification and deletion of pushers for this user ID. + Future setPushers(SetPushersRequest data) async { + final dynamic resp = await connection.jsonRequest( + type: "POST", + action: "/client/r0/pushers/set", + data: data, + ); + + if (resp is ErrorResponse) { + connection.onError.add(resp); + return null; + } + + return null; + } } diff --git a/lib/src/requests/SetPushersRequest.dart b/lib/src/requests/SetPushersRequest.dart new file mode 100644 index 00000000..8bc4fc16 --- /dev/null +++ b/lib/src/requests/SetPushersRequest.dart @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2019 Zender & Kurtz GbR. + * + * Authors: + * Christian Pauly + * Marcel Radzio + * + * This file is part of famedlysdk. + * + * famedlysdk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * famedlysdk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with famedly. If not, see . + */ +import 'package:json_annotation/json_annotation.dart'; + +part 'SetPushersRequest.g.dart'; + +@JsonSerializable(explicitToJson: true, nullable: false) +class SetPushersRequest { + // Required Keys + @JsonKey(nullable: false) + String lang; + @JsonKey(nullable: false) + String device_display_name; + @JsonKey(nullable: false) + String app_display_name; + @JsonKey(nullable: false) + String app_id; + @JsonKey(nullable: false) + String kind; + @JsonKey(nullable: false) + String pushkey; + @JsonKey(nullable: false) + PusherData data; + + // Optional keys + String profile_tag; + bool append; + + SetPushersRequest({ + this.lang, + this.device_display_name, + this.app_display_name, + this.app_id, + this.kind, + this.pushkey, + this.data, + this.profile_tag, + this.append, + }); + + factory SetPushersRequest.fromJson(Map json) => + _$SetPushersRequestFromJson(json); + + Map toJson() => _$SetPushersRequestToJson(this); +} + +@JsonSerializable(explicitToJson: true, nullable: false) +class PusherData { + String url; + String format; + + PusherData({ + this.url, + this.format, + }); + + factory PusherData.fromJson(Map json) => + _$PusherDataFromJson(json); + + Map toJson() => _$PusherDataToJson(this); +} diff --git a/lib/src/requests/SetPushersRequest.g.dart b/lib/src/requests/SetPushersRequest.g.dart new file mode 100644 index 00000000..0b4a5e16 --- /dev/null +++ b/lib/src/requests/SetPushersRequest.g.dart @@ -0,0 +1,41 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'SetPushersRequest.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SetPushersRequest _$SetPushersRequestFromJson(Map json) { + return SetPushersRequest( + lang: json['lang'] as String, + device_display_name: json['device_display_name'] as String, + app_display_name: json['app_display_name'] as String, + app_id: json['app_id'] as String, + kind: json['kind'] as String, + pushkey: json['pushkey'] as String, + data: PusherData.fromJson(json['data'] as Map), + profile_tag: json['profile_tag'] as String, + append: json['append'] as bool); +} + +Map _$SetPushersRequestToJson(SetPushersRequest instance) => + { + 'lang': instance.lang, + 'device_display_name': instance.device_display_name, + 'app_display_name': instance.app_display_name, + 'app_id': instance.app_id, + 'kind': instance.kind, + 'pushkey': instance.pushkey, + 'data': instance.data.toJson(), + 'profile_tag': instance.profile_tag, + 'append': instance.append + }; + +PusherData _$PusherDataFromJson(Map json) { + return PusherData( + url: json['url'] as String, format: json['format'] as String); +} + +Map _$PusherDataToJson(PusherData instance) => + {'url': instance.url, 'format': instance.format};