Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor large files into 1 file per class #138

Merged
merged 20 commits into from Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2cedd13
- Rename codegen files to be consistent with their output
ben-xD Jul 7, 2021
2463547
Remove unused import
ben-xD Jul 7, 2021
a029304
Rename test file to the class it contains (mock_method_call_manager)
ben-xD Jul 7, 2021
a5877da
Tear down tests without digging into methodChannel directly (law of d…
ben-xD Jul 7, 2021
af9325e
Move file scoped variables to a class, instead of importing a file `a…
ben-xD Jul 7, 2021
0e07b1d
- Use mini libraries and export them instead of adding each file to a…
ben-xD Jul 7, 2021
3dcd2f7
Import classes/ files when they are referenced in comments. To disabl…
ben-xD Jul 7, 2021
3a6b548
Fix formatting using `flutter format .`
ben-xD Jul 8, 2021
915b28f
Simplify import
ben-xD Jul 8, 2021
144eea6
Revert renaming template files because not all systems are case sensi…
ben-xD Jul 9, 2021
706b80d
Update references to file in readme after file rename
ben-xD Jul 9, 2021
0053a9b
Remove empty file
ben-xD Aug 9, 2021
2a8c97b
Rename typo in filename
ben-xD Aug 9, 2021
9405f41
Reformat file with extra comma
ben-xD Aug 9, 2021
50034c9
Removed file import
ben-xD Aug 10, 2021
bb99e08
Use Ably developer team in Xcode project
ben-xD Aug 10, 2021
4d2a191
Merge remote-tracking branch 'origin/main' into refactor-classes-into…
ben-xD Aug 12, 2021
298822d
Merge remote-tracking branch 'origin/schedule-integration-test-workfl…
ben-xD Aug 12, 2021
5f9a137
Merge branch 'schedule-integration-test-workflow' into refactor-class…
ben-xD Aug 13, 2021
e0d7917
Merge remote-tracking branch 'origin/main' into refactor-classes-into…
ben-xD Aug 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Expand Up @@ -75,14 +75,14 @@ Some files in the project are generated to maintain sync between

## Implementing new codec types

1. Add new type along with value in `_types` list at [bin/codegencontext.dart](bin/codegencontext.dart)
2. Add an object definition with object name and its properties to `objects` list at [bin/codegencontext.dart](bin/codegencontext.dart)
1. Add new type along with value in `_types` list at [bin/codegen_context.dart](bin/codegen_context.dart)
2. Add an object definition with object name and its properties to `objects` list at [bin/codegen_context.dart](bin/codegen_context.dart)
This will create `Tx<ObjectName>` under which all properties are accessible.

Generate platform constants and continue

3. update `getCodecType` in [lib.src.codec.Codec](lib/src/codec.dart) so new codec type is returned based on runtime type
4. update `codecPair` in [lib.src.codec.Codec](lib/src/codec.dart) so new encoder/decoder is assigned for new type
3. update `getCodecType` in [Codec.dart](lib/src/platform/src/codec.dart) so new codec type is returned based on runtime type
4. update `codecPair` in [Codec.dart](lib/src/platform/src/codec.dart) so new encoder/decoder is assigned for new type
5. update `writeValue` in [android.src.main.java.io.ably.flutter.plugin.AblyMessageCodec](android/src/main/java/io/ably/flutter/plugin/AblyMessageCodec.java)
so new codec type is obtained from runtime type
6. update `codecMap` in [android.src.main.java.io.ably.flutter.plugin.AblyMessageCodec](android/src/main/java/io/ably/flutter/plugin/AblyMessageCodec.java)
Expand All @@ -94,7 +94,7 @@ Generate platform constants and continue

## Implementing new platform methods

1. Add new method name in `_platformMethods` list at [bin/codegencontext.dart](bin/codegencontext.dart)
1. Add new method name in `_platformMethods` list at [bin/codegen_context.dart](bin/codegen_context.dart)

Generate platform constants and use wherever required

Expand Down
Expand Up @@ -7,7 +7,6 @@
import io.ably.lib.types.AblyException;
import io.ably.lib.types.AsyncPaginatedResult;
import io.ably.lib.types.ClientOptions;
import io.ably.lib.types.PaginatedResult;

class AblyLibrary {

Expand Down
4 changes: 2 additions & 2 deletions bin/codegen.dart
@@ -1,6 +1,6 @@
import 'dart:io';

import 'codegencontext.dart' show context;
import 'codegen_context.dart' show context;
import 'templates/platformconstants.dart.dart' as dart_template;
import 'templates/platformconstants.h.dart' as objc_header_template;
import 'templates/platformconstants.java.dart' as java_template;
Expand All @@ -12,7 +12,7 @@ const String projectRoot = '../';

Map<Template, String> toGenerate = {
// input template method vs output file path
dart_template.$: '${projectRoot}lib/src/generated/platformconstants.dart',
dart_template.$: '${projectRoot}lib/src/generated/platform_constants.dart',
java_template.$:
'${projectRoot}android/src/main/java/io/ably/flutter/plugin/generated/PlatformConstants.java',
objc_header_template.$:
Expand Down
File renamed without changes.
21 changes: 12 additions & 9 deletions lib/ably_flutter.dart
@@ -1,9 +1,12 @@
export 'src/generated/platformconstants.dart';
export 'src/impl/paginated_result.dart';
export 'src/impl/realtime/channels.dart';
export 'src/impl/realtime/connection.dart';
export 'src/impl/realtime/realtime.dart';
export 'src/impl/rest/channels.dart';
export 'src/impl/rest/rest.dart';
export 'src/info.dart';
export 'src/spec/spec.dart';
library ably_flutter;

export 'src/authentication/authentication.dart';
export 'src/common/common.dart';
export 'src/error/error.dart';
export 'src/logging/logging.dart';
export 'src/message/message.dart';
export 'src/platform/platform.dart';
export 'src/push_notifications/push_notifications.dart';
export 'src/realtime/realtime.dart';
export 'src/rest/rest.dart';
export 'src/stats/stats.dart';
8 changes: 8 additions & 0 deletions lib/src/authentication/authentication.dart
@@ -0,0 +1,8 @@
export 'src/auth.dart';
export 'src/auth_options.dart';
export 'src/cipher_params.dart';
export 'src/client_options.dart';
export 'src/http_auth_type.dart';
export 'src/token_details.dart';
export 'src/token_params.dart';
export 'src/token_request.dart';
@@ -1,5 +1,4 @@
import 'common.dart';
import 'rest/options.dart';
import '../authentication.dart';
tiholic marked this conversation as resolved.
Show resolved Hide resolved

/// [Auth] object provides a way to create [TokenRequest] objects
/// with [createTokenRequest] method or create Ably Tokens with
Expand Down
93 changes: 93 additions & 0 deletions lib/src/authentication/src/auth_options.dart
@@ -0,0 +1,93 @@
import '../authentication.dart';

/// A class providing configurable authentication options used when
/// authenticating or issuing tokens explicitly.
///
/// These options are used when invoking Auth#authorize, Auth#requestToken,
/// Auth#createTokenRequest and Auth#authorize.
///
/// https://docs.ably.com/client-lib-development-guide/features/#AO1
abstract class AuthOptions {
/// initializes an instance without any defaults
AuthOptions();

/// Convenience constructor, to create an AuthOptions based
/// on the key string obtained from the application dashboard.
/// param [key]: the full key string as obtained from the dashboard
AuthOptions.fromKey(String key) {
if (key.contains(':')) {
this.key = key;
} else {
tokenDetails = TokenDetails(key);
}
}

/// A function which is called when a new token is required.
///
/// The role of the callback is to either generate a signed [TokenRequest]
/// which may then be submitted automatically by the library to
/// the Ably REST API requestToken; or to provide a valid token
/// as a [TokenDetails] object.
/// https://docs.ably.com/client-lib-development-guide/features/#AO2b
AuthCallback? authCallback;

/// A URL that the library may use to obtain
/// a token String (in plain text format),
/// or a signed [TokenRequest] or [TokenDetails] (in JSON format).
///
/// https://docs.ably.com/client-lib-development-guide/features/#AO2c
String? authUrl;

/// HTTP Method used when a request is made using authURL
///
/// defaults to 'GET', supports 'GET' and 'POST'
/// https://docs.ably.com/client-lib-development-guide/features/#AO2d
String? authMethod;

/// Full Ably key string, as obtained from dashboard,
/// used when signing token requests locally
///
/// https://docs.ably.com/client-lib-development-guide/features/#AO2a
String? key;

/// An authentication token issued for this application
///
/// https://docs.ably.com/client-lib-development-guide/features/#AO2i
TokenDetails? tokenDetails;

/// Headers to be included in any request made to the [authUrl]
///
/// https://docs.ably.com/client-lib-development-guide/features/#AO2e
Map<String, String>? authHeaders;

/// Additional params to be included in any request made to the [authUrl]
///
/// As query params in the case of GET
/// and as form-encoded in the body in the case of POST
/// https://docs.ably.com/client-lib-development-guide/features/#AO2f
Map<String, String>? authParams;

/// If true, the library will when issuing a token request query
/// the Ably system for the current time instead of relying on a
/// locally-available time of day.
///
/// https://docs.ably.com/client-lib-development-guide/features/#AO2g
bool? queryTime;

/// Token Auth is used if useTokenAuth is set to true
///
/// or if useTokenAuth is unspecified and any one of
/// [authUrl], [authCallback], token, or [TokenDetails] is provided
/// https://docs.ably.com/client-lib-development-guide/features/#RSA4
bool? useTokenAuth;

// TODO(tiholic) missing token attribute here
// see: https://docs.ably.com/client-lib-development-guide/features/#AO2h
}

/// Function-type alias implemented by a function that provides either tokens,
/// or signed token requests, in response to a request with given token params.
///
/// Java: io.ably.lib.rest.Auth.TokenCallback.getTokenRequest(TokenParams)
/// returns either a [String] token or [TokenDetails] or [TokenRequest]
typedef AuthCallback = Future<Object> Function(TokenParams params);
26 changes: 26 additions & 0 deletions lib/src/authentication/src/cipher_params.dart
@@ -0,0 +1,26 @@
/// params to configure encryption for a channel
///
/// https://docs.ably.com/client-lib-development-guide/features/#TZ1
abstract class CipherParams {
/// Specifies the algorithm to use for encryption
///
/// Default is AES. Currently only AES is supported.
/// https://docs.ably.com/client-lib-development-guide/features/#TZ2a
String? algorithm;

/// private key used to encrypt and decrypt payloads
///
/// https://docs.ably.com/client-lib-development-guide/features/#TZ2d
dynamic key;

/// the length in bits of the key
///
/// https://docs.ably.com/client-lib-development-guide/features/#TZ2b
int? keyLength;

/// Specify cipher mode
///
/// Default is CBC. Currently only CBC is supported
/// https://docs.ably.com/client-lib-development-guide/features/#TZ2c
String? mode;
}
@@ -1,105 +1,6 @@
import '../../../ably_flutter.dart';
import '../common.dart';

/// Function-type alias implemented by a function that provides either tokens,
/// or signed token requests, in response to a request with given token params.
///
/// Java: io.ably.lib.rest.Auth.TokenCallback.getTokenRequest(TokenParams)
/// returns either a [String] token or [TokenDetails] or [TokenRequest]
typedef AuthCallback = Future<Object> Function(TokenParams params);

/// A class providing configurable authentication options used when
/// authenticating or issuing tokens explicitly.
///
/// These options are used when invoking Auth#authorize, Auth#requestToken,
/// Auth#createTokenRequest and Auth#authorize.
///
/// https://docs.ably.com/client-lib-development-guide/features/#AO1
abstract class AuthOptions {
/// initializes an instance without any defaults
AuthOptions();

/// Convenience constructor, to create an AuthOptions based
/// on the key string obtained from the application dashboard.
/// param [key]: the full key string as obtained from the dashboard
AuthOptions.fromKey(String key) {
if (key.contains(':')) {
this.key = key;
} else {
tokenDetails = TokenDetails(key);
}
}

/// A function which is called when a new token is required.
///
/// The role of the callback is to either generate a signed [TokenRequest]
/// which may then be submitted automatically by the library to
/// the Ably REST API requestToken; or to provide a valid token
/// as a [TokenDetails] object.
/// https://docs.ably.com/client-lib-development-guide/features/#AO2b
AuthCallback? authCallback;

/// A URL that the library may use to obtain
/// a token String (in plain text format),
/// or a signed [TokenRequest] or [TokenDetails] (in JSON format).
///
/// https://docs.ably.com/client-lib-development-guide/features/#AO2c
String? authUrl;

/// HTTP Method used when a request is made using authURL
///
/// defaults to 'GET', supports 'GET' and 'POST'
/// https://docs.ably.com/client-lib-development-guide/features/#AO2d
String? authMethod;

/// Full Ably key string, as obtained from dashboard,
/// used when signing token requests locally
///
/// https://docs.ably.com/client-lib-development-guide/features/#AO2a
String? key;

/// An authentication token issued for this application
///
/// https://docs.ably.com/client-lib-development-guide/features/#AO2i
TokenDetails? tokenDetails;

/// Headers to be included in any request made to the [authUrl]
///
/// https://docs.ably.com/client-lib-development-guide/features/#AO2e
Map<String, String>? authHeaders;

/// Additional params to be included in any request made to the [authUrl]
///
/// As query params in the case of GET
/// and as form-encoded in the body in the case of POST
/// https://docs.ably.com/client-lib-development-guide/features/#AO2f
Map<String, String>? authParams;

/// If true, the library will when issuing a token request query
/// the Ably system for the current time instead of relying on a
/// locally-available time of day.
///
/// https://docs.ably.com/client-lib-development-guide/features/#AO2g
bool? queryTime;

/// Token Auth is used if useTokenAuth is set to true
///
/// or if useTokenAuth is unspecified and any one of
/// [authUrl], [authCallback], token, or [TokenDetails] is provided
/// https://docs.ably.com/client-lib-development-guide/features/#RSA4
bool? useTokenAuth;

// TODO(tiholic) missing token attribute here
// see: https://docs.ably.com/client-lib-development-guide/features/#AO2h
}

/// Custom handler to handle SDK log messages
///
/// https://docs.ably.com/client-lib-development-guide/features/#TO3c
typedef LogHandler = void Function({
String? msg,
AblyException? exception,
});
import '../../logging/logging.dart';
import '../../realtime/realtime.dart';
import '../authentication.dart';

/// Ably library options used when instancing a REST or Realtime client library
///
Expand Down
11 changes: 11 additions & 0 deletions lib/src/authentication/src/http_auth_type.dart
@@ -0,0 +1,11 @@
/// Java: io.ably.lib.http.HttpAuth.Type
enum HttpAuthType {
/// indicates basic authentication
basic,

/// digest authentication
digest,

/// Token auth
xAblyToken,
}
53 changes: 53 additions & 0 deletions lib/src/authentication/src/token_details.dart
@@ -0,0 +1,53 @@
/// Response to a `requestToken` request
///
/// https://docs.ably.com/client-lib-development-guide/features/#TD1
class TokenDetails {
/// https://docs.ably.com/client-lib-development-guide/features/#TD2
String? token;

/// Token expiry time in milliseconds
///
/// https://docs.ably.com/client-lib-development-guide/features/#TD3
int? expires;

/// the time the token was issued in milliseconds
///
/// https://docs.ably.com/client-lib-development-guide/features/#TD4
int? issued;

/// stringified capabilities JSON
///
/// https://docs.ably.com/client-lib-development-guide/features/#TD5
String? capability;

/// Client ID assigned to the token.
///
/// If [clientId] is not set (i.e. null), then the token is prohibited
/// from assuming a clientId in any operations, however if clientId
/// is a wildcard string '*', then the token is permitted to assume
/// any clientId. Any other string value for clientId implies that the
/// clientId is both enforced and assumed for all operations for this token
///
/// https://docs.ably.com/client-lib-development-guide/features/#TD6
String? clientId;

/// instantiates a [TokenDetails] with provided values
TokenDetails(
this.token, {
this.expires,
this.issued,
this.capability,
this.clientId,
});

/// Creates an instance from the map
///
/// https://docs.ably.com/client-lib-development-guide/features/#TD7
TokenDetails.fromMap(Map<String, dynamic> map) {
token = map['token'] as String?;
expires = map['expires'] as int?;
issued = map['issued'] as int?;
capability = map['capability'] as String?;
clientId = map['clientId'] as String?;
}
}