From 88be5721708c8eb60d190aac9e37378d83d852ae Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 25 Jun 2019 15:33:56 +0200 Subject: [PATCH 1/3] [Client] add setPushers Took 15 minutes --- lib/src/Client.dart | 17 +++++ lib/src/requests/SetPushersRequest.dart | 81 +++++++++++++++++++++++ lib/src/requests/SetPushersRequest.g.dart | 41 ++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 lib/src/requests/SetPushersRequest.dart create mode 100644 lib/src/requests/SetPushersRequest.g.dart 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}; From 8ac7b01d5356b8d0c8c91d16ef473cecac2c7a62 Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 25 Jun 2019 15:39:56 +0200 Subject: [PATCH 2/3] [SetPushRequest] make required field required in the class too Took 6 minutes --- lib/src/requests/SetPushersRequest.dart | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/src/requests/SetPushersRequest.dart b/lib/src/requests/SetPushersRequest.dart index 8bc4fc16..6372f2b0 100644 --- a/lib/src/requests/SetPushersRequest.dart +++ b/lib/src/requests/SetPushersRequest.dart @@ -21,6 +21,7 @@ * along with famedly. If not, see . */ import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'SetPushersRequest.g.dart'; @@ -47,13 +48,13 @@ class SetPushersRequest { bool append; SetPushersRequest({ - this.lang, - this.device_display_name, - this.app_display_name, - this.app_id, - this.kind, - this.pushkey, - this.data, + @required this.lang, + @required this.device_display_name, + @required this.app_display_name, + @required this.app_id, + @required this.kind, + @required this.pushkey, + @required this.data, this.profile_tag, this.append, }); From e5464f1c49d7d351b1c9f7709eff7580caf8f504 Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 25 Jun 2019 15:51:09 +0200 Subject: [PATCH 3/3] [SetPushRequest] Use correct import Took 3 minutes --- lib/src/requests/SetPushersRequest.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/requests/SetPushersRequest.dart b/lib/src/requests/SetPushersRequest.dart index 6372f2b0..a39115fe 100644 --- a/lib/src/requests/SetPushersRequest.dart +++ b/lib/src/requests/SetPushersRequest.dart @@ -20,8 +20,8 @@ * You should have received a copy of the GNU General Public License * along with famedly. If not, see . */ +import 'package:flutter/widgets.dart'; import 'package:json_annotation/json_annotation.dart'; -import 'package:meta/meta.dart'; part 'SetPushersRequest.g.dart';