diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/messages.dart b/packages/shorebird_code_push_protocol/lib/src/messages/messages.dart index 6f27f612..f48dee32 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/messages.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/messages.dart @@ -5,6 +5,7 @@ export 'create_app_collaborator/create_app_collaborator.dart'; export 'create_channel/create_channel.dart'; export 'create_patch/create_patch.dart'; export 'create_patch_artifact/create_patch_artifact.dart'; +export 'record_patch_install/record_patch_install.dart'; export 'create_payment_link/create_payment_link.dart'; export 'create_release/create_release.dart'; export 'create_release_artifact/create_release_artifact.dart'; diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/record_patch_install/record_patch_install.dart b/packages/shorebird_code_push_protocol/lib/src/messages/record_patch_install/record_patch_install.dart new file mode 100644 index 00000000..0a405e39 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/messages/record_patch_install/record_patch_install.dart @@ -0,0 +1 @@ +export 'record_patch_install_request.dart'; diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/record_patch_install/record_patch_install_request.dart b/packages/shorebird_code_push_protocol/lib/src/messages/record_patch_install/record_patch_install_request.dart new file mode 100644 index 00000000..75ba8df0 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/messages/record_patch_install/record_patch_install_request.dart @@ -0,0 +1,45 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; + +part 'record_patch_install_request.g.dart'; + +/// {@template record_patch_install_request} +/// Request to record a patch install. +/// {@endtemplate} +@JsonSerializable() +class RecordPatchInstallRequest { + /// {@macro record_patch_install_request} + RecordPatchInstallRequest({ + required this.clientId, + required this.appId, + required this.releaseVersion, + required this.patchNumber, + required this.platform, + required this.arch, + }); + + /// Converts a Map to a [RecordPatchInstallRequest] + factory RecordPatchInstallRequest.fromJson(Map json) => + _$RecordPatchInstallRequestFromJson(json); + + /// Converts a [RecordPatchInstallRequest] to a Map + Map toJson() => _$RecordPatchInstallRequestToJson(this); + + /// The client id of the device being updated. + final String clientId; + + /// The id of the app being updated. + final String appId; + + /// The id of the app being updated. + final String releaseVersion; + + /// The patch number being installed. + final int patchNumber; + + /// The platform of the device being updated. + final ReleasePlatform platform; + + /// The architecture of the device being updated. + final String arch; +} diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/record_patch_install/record_patch_install_request.g.dart b/packages/shorebird_code_push_protocol/lib/src/messages/record_patch_install/record_patch_install_request.g.dart new file mode 100644 index 00000000..57ad4fe8 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/messages/record_patch_install/record_patch_install_request.g.dart @@ -0,0 +1,51 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: implicit_dynamic_parameter, require_trailing_commas, cast_nullable_to_non_nullable, lines_longer_than_80_chars + +part of 'record_patch_install_request.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +RecordPatchInstallRequest _$RecordPatchInstallRequestFromJson( + Map json) => + $checkedCreate( + 'RecordPatchInstallRequest', + json, + ($checkedConvert) { + final val = RecordPatchInstallRequest( + clientId: $checkedConvert('client_id', (v) => v as String), + appId: $checkedConvert('app_id', (v) => v as String), + releaseVersion: + $checkedConvert('release_version', (v) => v as String), + patchNumber: $checkedConvert('patch_number', (v) => v as int), + platform: $checkedConvert( + 'platform', (v) => $enumDecode(_$ReleasePlatformEnumMap, v)), + arch: $checkedConvert('arch', (v) => v as String), + ); + return val; + }, + fieldKeyMap: const { + 'clientId': 'client_id', + 'appId': 'app_id', + 'releaseVersion': 'release_version', + 'patchNumber': 'patch_number' + }, + ); + +Map _$RecordPatchInstallRequestToJson( + RecordPatchInstallRequest instance) => + { + 'client_id': instance.clientId, + 'app_id': instance.appId, + 'release_version': instance.releaseVersion, + 'patch_number': instance.patchNumber, + 'platform': _$ReleasePlatformEnumMap[instance.platform]!, + 'arch': instance.arch, + }; + +const _$ReleasePlatformEnumMap = { + ReleasePlatform.android: 'android', + ReleasePlatform.ios: 'ios', +}; diff --git a/packages/shorebird_code_push_protocol/test/src/messages/record_patch_install/record_patch_install_request_test.dart b/packages/shorebird_code_push_protocol/test/src/messages/record_patch_install/record_patch_install_request_test.dart new file mode 100644 index 00000000..a8dd38c3 --- /dev/null +++ b/packages/shorebird_code_push_protocol/test/src/messages/record_patch_install/record_patch_install_request_test.dart @@ -0,0 +1,21 @@ +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; +import 'package:test/test.dart'; + +void main() { + group(RecordPatchInstallRequest, () { + test('can be (de)serialized', () { + final response = RecordPatchInstallRequest( + clientId: 'some-client-id', + appId: 'some-app-id', + patchNumber: 2, + arch: 'arm64', + platform: ReleasePlatform.android, + releaseVersion: '1.0.0', + ); + expect( + RecordPatchInstallRequest.fromJson(response.toJson()).toJson(), + equals(response.toJson()), + ); + }); + }); +}