Skip to content

Commit

Permalink
Merge pull request #138 from ably/refactor-classes-into-files
Browse files Browse the repository at this point in the history
Refactor large files into 1 file per class
  • Loading branch information
ben-xD authored Aug 16, 2021
2 parents e388139 + e0d7917 commit d1c6566
Show file tree
Hide file tree
Showing 114 changed files with 2,247 additions and 2,148 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Ably: 863d35bb6a6aa5fc537304ef19f85cfa51d1bbde
ably_flutter: b37439c7b63f4b3e44f4674c5bfb56452d193ad0
ably_flutter: 31894faaa659febdd3a57cdc03c1fc2c218d2c95
AblyDeltaCodec: 6123f31df5b04a0f5452968505a46ba16a9eb689
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
msgpack: a14de9216d29cfd0a7aff5af5150601a27e899a4
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
TargetAttributes = {
97C146ED1CF9000F007C117D = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = S38X8U35U5;
DevelopmentTeam = XXY98AVDR6;
};
};
};
Expand Down Expand Up @@ -377,7 +377,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = S38X8U35U5;
DEVELOPMENT_TEAM = XXY98AVDR6;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -506,7 +506,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = S38X8U35U5;
DEVELOPMENT_TEAM = XXY98AVDR6;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -530,7 +530,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = S38X8U35U5;
DEVELOPMENT_TEAM = XXY98AVDR6;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down
21 changes: 12 additions & 9 deletions lib/ably_flutter.dart
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'common.dart';
import 'rest/options.dart';
import '../authentication.dart';

/// [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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// Java: io.ably.lib.http.HttpAuth.Type
enum HttpAuthType {
/// indicates basic authentication
basic,

/// digest authentication
digest,

/// Token auth
xAblyToken,
}
Loading

0 comments on commit d1c6566

Please sign in to comment.