diff --git a/CHANGELOG.md b/CHANGELOG.md index b05930e..f6b4f92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,24 @@ +## 0.6.1 + +- Added methods getUserId, updateUserId, getDeviceId, updateDeviceId for user analytics. +- Experiments for ios has been fixed. +- The Swift based version of Varioqub has been upgraded to 0.6.0 version. +- Updated docs. + ## 0.6.0 -Pigeon have been updated to version ^17.0.0. -Kotlin and swift packages have been updated to version 0.6.0. -Updated docs. +- Pigeon have been updated to version ^17.0.0. +- Kotlin and swift packages have been updated to version 0.6.0. +- Updated docs. ## 0.0.3 -Changing dependencies in .podspec for ios projects, the library is now static +- Changing dependencies in .podspec for ios projects, the library is now static ## 0.0.2 -Moving the lower sdk limits to >=3.2.0 +- Moving the lower sdk limits to >=3.2.0 ## 0.0.1 -Initial release. +- Initial release. diff --git a/README.md b/README.md index ea853b6..34c3290 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,6 @@ await configs.getString( [Official docs from Yandex](https://yandex.ru/support2/varioqub-app/ru/) -# Limitations - -At the moment, the library is used exclusively for obtaining and working with configs and experiments. Analytics elements are not used for fetch! - # Changelog [Refer to the Changelog to get all release notes.](https://github.com/meg4cyberc4t/varioqub_configs/blob/main/CHANGELOG.md) diff --git a/android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/Messages.g.kt b/android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/Messages.g.kt index 6ebb1f1..7524581 100644 --- a/android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/Messages.g.kt +++ b/android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/Messages.g.kt @@ -4,6 +4,7 @@ // Autogenerated from Pigeon (v17.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon +package com.meg4cyberc4t.varioqub_configs import android.util.Log import io.flutter.plugin.common.BasicMessageChannel @@ -99,6 +100,10 @@ private object VarioqubSenderCodec : StandardMessageCodec() { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ interface VarioqubSender { fun build(settings: PigeonBuildSettings) + fun getDeviceId(): String + fun updateDeviceId(value: String) + fun getUserId(): String + fun updateUserId(value: String) fun fetchConfig(callback: (Result) -> Unit) fun activateConfig(callback: (Result) -> Unit) fun setDefaults(values: Map) @@ -138,6 +143,76 @@ interface VarioqubSender { channel.setMessageHandler(null) } } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.varioqub_configs.VarioqubSender.getDeviceId", codec) + if (api != null) { + channel.setMessageHandler { _, reply -> + var wrapped: List + try { + wrapped = listOf(api.getDeviceId()) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.varioqub_configs.VarioqubSender.updateDeviceId", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val valueArg = args[0] as String + var wrapped: List + try { + api.updateDeviceId(valueArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.varioqub_configs.VarioqubSender.getUserId", codec) + if (api != null) { + channel.setMessageHandler { _, reply -> + var wrapped: List + try { + wrapped = listOf(api.getUserId()) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.varioqub_configs.VarioqubSender.updateUserId", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val valueArg = args[0] as String + var wrapped: List + try { + api.updateUserId(valueArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } run { val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.varioqub_configs.VarioqubSender.fetchConfig", codec) if (api != null) { diff --git a/android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/VarioqubConfigsPlugin.kt b/android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/VarioqubConfigsPlugin.kt index 0f9a304..6f0f707 100644 --- a/android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/VarioqubConfigsPlugin.kt +++ b/android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/VarioqubConfigsPlugin.kt @@ -1,7 +1,5 @@ package com.meg4cyberc4t.varioqub_configs -import PigeonBuildSettings -import VarioqubSender import android.content.Context import android.util.Log import com.yandex.varioqub.config.FetchError @@ -21,6 +19,7 @@ class VarioqubConfigsPlugin : FlutterPlugin, VarioqubSender { private lateinit var api: VarioqubApi private lateinit var context: Context + private val adapter: VarioqubAdapter = VarioqubAdapter() override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { try { @@ -28,7 +27,7 @@ class VarioqubConfigsPlugin : FlutterPlugin, VarioqubSender { context = flutterPluginBinding.applicationContext api = Varioqub.getInstance() } catch (error: Throwable) { - Log.e(TAG, "Failed to initialize TickerPlugin") + Log.e(TAG, "Failed to initialize VarioqubConfigsPlugin") } } @@ -52,11 +51,25 @@ class VarioqubConfigsPlugin : FlutterPlugin, VarioqubSender { } api.init( settingsBuilder.build(), - VarioqubAdapter(), + adapter, context, ); } + override fun updateDeviceId(value: String) { + adapter.deviceId = value; + } + + override fun getDeviceId(): String { + return adapter.deviceId; + } + override fun updateUserId(value: String) { + adapter.userId = value; + } + override fun getUserId(): String { + return adapter.userId; + } + override fun fetchConfig(callback: (Result) -> Unit) { api.fetchConfig( object : OnFetchCompleteListener { diff --git a/android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/VarioqubReceiverAdapter.kt b/android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/VarioqubReceiverAdapter.kt index 1890b02..fe013ec 100644 --- a/android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/VarioqubReceiverAdapter.kt +++ b/android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/VarioqubReceiverAdapter.kt @@ -6,14 +6,17 @@ import com.yandex.varioqub.analyticadapter.VarioqubConfigAdapter class VarioqubAdapter : VarioqubConfigAdapter { override val adapterName: String = "VarioqubAdapter" + var deviceId: String = "000" + var userId: String = "000" + override fun reportConfigChanged(configData: com.yandex.varioqub.analyticadapter.data.ConfigData) {} override fun requestDeviceId(callback: AdapterIdentifiersCallback) { - callback.onSuccess("000") + callback.onSuccess(deviceId) } override fun requestUserId(callback: AdapterIdentifiersCallback) { - callback.onSuccess("000") + callback.onSuccess(userId) } override fun setExperiments(experiments: String) {} diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 7cd7128..af1ec35 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -23,7 +23,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "7.3.0" apply false + id "com.android.application" version '7.4.2' apply false } include ":app" diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index a4522b5..be0b08d 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,16 +1,13 @@ PODS: - Flutter (1.0.0) + - Varioqub (0.6.0): + - Varioqub/Core (= 0.6.0) - Varioqub/Core (0.6.0): - Varioqub/VQSwiftProtobuf - - Varioqub/MetricaAdapter (0.6.0): - - Varioqub/Core - - Varioqub/VQSwiftProtobuf - - YandexMobileMetrica/Dynamic/Core (~> 4.5.0) - Varioqub/VQSwiftProtobuf (0.6.0) - - varioqub_configs (0.0.1): + - varioqub_configs (0.6.1): - Flutter - - Varioqub/MetricaAdapter (~> 0.5) - - YandexMobileMetrica/Dynamic/Core (4.5.2) + - Varioqub (~> 0.6) DEPENDENCIES: - Flutter (from `Flutter`) @@ -19,7 +16,6 @@ DEPENDENCIES: SPEC REPOS: trunk: - Varioqub - - YandexMobileMetrica EXTERNAL SOURCES: Flutter: @@ -30,9 +26,8 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 Varioqub: 58ac5ff3e51a46aca97c3a9c9f3b5cc9d5bf949e - varioqub_configs: d8f4e7737df8a0e3149ca85105c09dee791b8d62 - YandexMobileMetrica: f5368ee93f286c793d73b58da00929babfc897c1 + varioqub_configs: 3bc95e7b23152922bf18d365c009bff6cff00c7b PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796 -COCOAPODS: 1.13.0 +COCOAPODS: 1.15.0 diff --git a/ios/Classes/Messages.g.swift b/ios/Classes/Messages.g.swift index 03d8b12..96784c0 100644 --- a/ios/Classes/Messages.g.swift +++ b/ios/Classes/Messages.g.swift @@ -111,6 +111,10 @@ class VarioqubSenderCodec: FlutterStandardMessageCodec { /// Generated protocol from Pigeon that represents a handler of messages from Flutter. protocol VarioqubSender { func build(settings: PigeonBuildSettings) throws + func getDeviceId() throws -> String + func updateDeviceId(value: String) throws + func getUserId() throws -> String + func updateUserId(value: String) throws func fetchConfig(completion: @escaping (Result) -> Void) func activateConfig(completion: @escaping (Result) -> Void) func setDefaults(values: [String: Any]) throws @@ -145,6 +149,62 @@ class VarioqubSenderSetup { } else { buildChannel.setMessageHandler(nil) } + let getDeviceIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.varioqub_configs.VarioqubSender.getDeviceId", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getDeviceIdChannel.setMessageHandler { _, reply in + do { + let result = try api.getDeviceId() + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getDeviceIdChannel.setMessageHandler(nil) + } + let updateDeviceIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.varioqub_configs.VarioqubSender.updateDeviceId", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + updateDeviceIdChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let valueArg = args[0] as! String + do { + try api.updateDeviceId(value: valueArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + updateDeviceIdChannel.setMessageHandler(nil) + } + let getUserIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.varioqub_configs.VarioqubSender.getUserId", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getUserIdChannel.setMessageHandler { _, reply in + do { + let result = try api.getUserId() + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getUserIdChannel.setMessageHandler(nil) + } + let updateUserIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.varioqub_configs.VarioqubSender.updateUserId", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + updateUserIdChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let valueArg = args[0] as! String + do { + try api.updateUserId(value: valueArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + updateUserIdChannel.setMessageHandler(nil) + } let fetchConfigChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.varioqub_configs.VarioqubSender.fetchConfig", binaryMessenger: binaryMessenger, codec: codec) if let api = api { fetchConfigChannel.setMessageHandler { _, reply in diff --git a/ios/Classes/VarioqubConfigsPlugin.swift b/ios/Classes/VarioqubConfigsPlugin.swift index b05cf84..ca8e4aa 100644 --- a/ios/Classes/VarioqubConfigsPlugin.swift +++ b/ios/Classes/VarioqubConfigsPlugin.swift @@ -9,7 +9,20 @@ import Varioqub #endif +public class VarioqubIdHandler: NSObject, VarioqubIdProvider { + public var deviceId: String = "000" + public var userId: String = "000" + + public func fetchIdentifiers(completion: @escaping Completion) { + completion(Result.success(VarioqubIdentifiers(deviceId: deviceId, userId: userId))) + } + + public var varioqubName: String = "VarioqubIdHandler" +} + public class VarioqubConfigsPlugin: NSObject, FlutterPlugin, VarioqubSender { + let idHandler: VarioqubIdHandler = VarioqubIdHandler(); + init(binaryMessenger: FlutterBinaryMessenger) { super.init() VarioqubSenderSetup.setUp(binaryMessenger: binaryMessenger, api: self) @@ -35,7 +48,7 @@ public class VarioqubConfigsPlugin: NSObject, FlutterPlugin, VarioqubSender { VarioqubFacade.shared.initialize( clientId: settings.clientId, config: config, - idProvider: nil, + idProvider: idHandler, reporter: nil ) } @@ -64,6 +77,22 @@ public class VarioqubConfigsPlugin: NSObject, FlutterPlugin, VarioqubSender { return VarioqubFacade.shared.setDefaultsAndWait(defaults) } + func getDeviceId() throws -> String { + return idHandler.deviceId + } + + func updateDeviceId(value: String) throws { + return idHandler.deviceId = value + } + + func getUserId() throws -> String { + return idHandler.userId + } + + func updateUserId(value: String) throws { + return idHandler.userId = value + } + func getString(key: String, defaultValue: String) throws -> String { return VarioqubFacade.shared.getString(for: VarioqubFlag(rawValue: key), defaultValue: defaultValue) } diff --git a/ios/varioqub_configs.podspec b/ios/varioqub_configs.podspec index d99d1f8..c39e5de 100644 --- a/ios/varioqub_configs.podspec +++ b/ios/varioqub_configs.podspec @@ -4,20 +4,20 @@ # Pod::Spec.new do |s| s.name = 'varioqub_configs' - s.version = '0.0.3' + s.version = '0.6.1' s.summary = 'Flutter plugin providing work with remote configs,experiments and A/B testing via Varioqub.' s.description = <<-DESC Flutter plugin providing work with remote configs, experiments and A/B testing via Varioqub. Read the README for full details. DESC - s.homepage = 'http://example.com' + s.homepage = 'https://github.com/meg4cyberc4t/varioqub_configs' s.license = { :file => '../LICENSE' } s.author = { 'Igor Molchanov' => 'meg4cyberc4t@gmail.com' } s.source = { :path => '.' } s.source_files = 'Classes/**/*' s.dependency 'Flutter' - s.dependency 'Varioqub', '~> 0.5' + s.dependency 'Varioqub', '~> 0.6' s.platform = :ios, '11.0' s.static_framework = true diff --git a/lib/src/messages.g.dart b/lib/src/messages.g.dart index 3c6bf9c..d4c1df8 100644 --- a/lib/src/messages.g.dart +++ b/lib/src/messages.g.dart @@ -113,6 +113,112 @@ class VarioqubSender { } } + Future getDeviceId() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.varioqub_configs.VarioqubSender.getDeviceId'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as String?)!; + } + } + + Future updateDeviceId(String value) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.varioqub_configs.VarioqubSender.updateDeviceId'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future getUserId() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.varioqub_configs.VarioqubSender.getUserId'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as String?)!; + } + } + + Future updateUserId(String value) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.varioqub_configs.VarioqubSender.updateUserId'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + Future fetchConfig() async { const String __pigeon_channelName = 'dev.flutter.pigeon.varioqub_configs.VarioqubSender.fetchConfig'; diff --git a/lib/src/platform/varioqub.dart b/lib/src/platform/varioqub.dart index 46e9edf..45de152 100644 --- a/lib/src/platform/varioqub.dart +++ b/lib/src/platform/varioqub.dart @@ -29,6 +29,22 @@ abstract interface class VarioqubConfigs { /// To do this, specify it in the appropriate field in A/B experiments. Future getId(); + /// Getting the DeviceID from the metric. + /// It is used for analysis and experiments. + Future getDeviceId(); + + /// Updating the DeviceID in metrics. + /// It is used for analysis and experiments. + Future updateDeviceId(final String value); + + /// Getting the UserID from the metric. + /// It is used for analysis and experiments. + Future getUserId(); + + /// Updating the UserID in metrics. + /// It is used for analysis and experiments. + Future updateUserId(final String value); + /// Adding default values Future setDefaults(final Map values); @@ -91,6 +107,19 @@ final class _VarioqubPlatform implements VarioqubConfigs { @override Future getId() async => _sender.getId(); + @override + Future getDeviceId() async => _sender.getDeviceId(); + + @override + Future updateDeviceId(final String value) => + _sender.updateDeviceId(value); + + @override + Future getUserId() async => _sender.getUserId(); + + @override + Future updateUserId(final String value) => _sender.updateUserId(value); + @override Future getString({ required final String key, diff --git a/pigeons/messages.dart b/pigeons/messages.dart index 10600d3..6d0c28f 100644 --- a/pigeons/messages.dart +++ b/pigeons/messages.dart @@ -11,7 +11,10 @@ import 'package:pigeon/pigeon.dart'; dartOptions: DartOptions(), kotlinOut: 'android/src/main/kotlin/com/meg4cyberc4t/varioqub_configs/Messages.g.kt', - kotlinOptions: KotlinOptions(), + kotlinOptions: KotlinOptions( + errorClassName: 'FlutterError', + package: 'com.meg4cyberc4t.varioqub_configs', + ), swiftOut: 'ios/Classes/Messages.g.swift', swiftOptions: SwiftOptions(), copyrightHeader: 'pigeons/copyright.txt', @@ -52,6 +55,12 @@ final class PigeonBuildSettings { abstract class VarioqubSender { void build(final PigeonBuildSettings settings); + String getDeviceId(); + void updateDeviceId(final String value); + + String getUserId(); + void updateUserId(final String value); + @async void fetchConfig(); diff --git a/pubspec.yaml b/pubspec.yaml index f7aba32..2f0aec7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: varioqub_configs description: "Flutter plugin providing work with remote configs, experiments and A/B testing via Varioqub" -version: 0.6.0 +version: 0.6.1 repository: https://github.com/meg4cyberc4t/varioqub_configs homepage: https://github.com/meg4cyberc4t/varioqub_configs issue_tracker: https://github.com/meg4cyberc4t/varioqub_configs/issues