Skip to content

Commit

Permalink
Merge pull request #57 from appwrite/dev
Browse files Browse the repository at this point in the history
Fix msg91 params
  • Loading branch information
christyjacob4 committed Mar 24, 2024
2 parents e5f8956 + 72e2075 commit aa70c2e
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 11.0.2

* Fixed MSG91 missing template ID

## 11.0.1

* Fixed parameters using enum types
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add this to your package's `pubspec.yaml` file:

```yml
dependencies:
dart_appwrite: ^11.0.1
dart_appwrite: ^11.0.2
```

You can install packages from the command line:
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/messaging/create-msg91provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Messaging messaging = Messaging(client);
Provider result = await messaging.createMsg91Provider(
providerId: '<PROVIDER_ID>',
name: '<NAME>',
from: '+12065550100', // (optional)
templateId: '<TEMPLATE_ID>', // (optional)
senderId: '<SENDER_ID>', // (optional)
authKey: '<AUTH_KEY>', // (optional)
enabled: false, // (optional)
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/messaging/update-msg91provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Provider result = await messaging.updateMsg91Provider(
providerId: '<PROVIDER_ID>',
name: '<NAME>', // (optional)
enabled: false, // (optional)
templateId: '<TEMPLATE_ID>', // (optional)
senderId: '<SENDER_ID>', // (optional)
authKey: '<AUTH_KEY>', // (optional)
from: '<FROM>', // (optional)
);
1 change: 1 addition & 0 deletions lib/dart_appwrite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
library dart_appwrite;

import 'dart:async';
import 'dart:math';
import 'dart:typed_data';
import 'dart:convert';

Expand Down
29 changes: 25 additions & 4 deletions lib/id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,34 @@ part of dart_appwrite;
class ID {
ID._();

/// Have Appwrite generate a unique ID for you.
static String unique() {
return 'unique()';
// Generate an hex ID based on timestamp
// Recreated from https://www.php.net/manual/en/function.uniqid.php
static String _hexTimestamp() {
final now = DateTime.now();
final sec = (now.millisecondsSinceEpoch / 1000).floor();
final usec = now.microsecondsSinceEpoch - (sec * 1000000);
return sec.toRadixString(16) +
usec.toRadixString(16).padLeft(5, '0');
}

// Generate a unique ID with padding to have a longer ID
static String unique({int padding = 7}) {
String id = _hexTimestamp();

if (padding > 0) {
StringBuffer sb = StringBuffer();
for (var i = 0; i < padding; i++) {
sb.write(Random().nextInt(16).toRadixString(16));
}

id += sb.toString();
}

return id;
}

/// Uses [id] as the ID for the resource.
static String custom(String id) {
return id;
}
}
}
8 changes: 4 additions & 4 deletions lib/services/messaging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,14 @@ class Messaging extends Service {
/// Create Msg91 provider
///
/// Create a new MSG91 provider.
Future<models.Provider> createMsg91Provider({required String providerId, required String name, String? from, String? senderId, String? authKey, bool? enabled}) async {
Future<models.Provider> createMsg91Provider({required String providerId, required String name, String? templateId, String? senderId, String? authKey, bool? enabled}) async {
final String apiPath = '/messaging/providers/msg91';

final Map<String, dynamic> apiParams = {

'providerId': providerId,
'name': name,
'from': from,
'templateId': templateId,
'senderId': senderId,
'authKey': authKey,
'enabled': enabled,
Expand All @@ -550,16 +550,16 @@ class Messaging extends Service {
/// Update Msg91 provider
///
/// Update a MSG91 provider by its unique ID.
Future<models.Provider> updateMsg91Provider({required String providerId, String? name, bool? enabled, String? senderId, String? authKey, String? from}) async {
Future<models.Provider> updateMsg91Provider({required String providerId, String? name, bool? enabled, String? templateId, String? senderId, String? authKey}) async {
final String apiPath = '/messaging/providers/msg91/{providerId}'.replaceAll('{providerId}', providerId);

final Map<String, dynamic> apiParams = {

'name': name,
'enabled': enabled,
'templateId': templateId,
'senderId': senderId,
'authKey': authKey,
'from': from,

};

Expand Down
2 changes: 1 addition & 1 deletion lib/src/client_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ClientBrowser extends ClientBase with ClientMixin {
'x-sdk-name': 'Dart',
'x-sdk-platform': 'server',
'x-sdk-language': 'dart',
'x-sdk-version': '11.0.1',
'x-sdk-version': '11.0.2',
'X-Appwrite-Response-Format' : '1.5.0',
};

Expand Down
4 changes: 2 additions & 2 deletions lib/src/client_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class ClientIO extends ClientBase with ClientMixin {
'x-sdk-name': 'Dart',
'x-sdk-platform': 'server',
'x-sdk-language': 'dart',
'x-sdk-version': '11.0.1',
'user-agent' : 'AppwriteDartSDK/11.0.1 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})',
'x-sdk-version': '11.0.2',
'user-agent' : 'AppwriteDartSDK/11.0.2 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})',
'X-Appwrite-Response-Format' : '1.5.0',
};

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dart_appwrite
version: 11.0.1
version: 11.0.2
description: Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API
homepage: https://appwrite.io
repository: https://github.com/appwrite/sdk-for-dart
Expand Down
4 changes: 2 additions & 2 deletions test/id_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'package:test/test.dart';

void main() {
group('unique()', () {
test('returns unique()', () {
expect(ID.unique(), 'unique()');
test('returns unique ID', () {
expect((ID.unique()).length, 20);
});
});

Expand Down

0 comments on commit aa70c2e

Please sign in to comment.