-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NativeResponseHandler and Wrapper
- Loading branch information
1 parent
5438171
commit 333288a
Showing
8 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
part of '../kiota_abstractions.dart'; | ||
|
||
/// The [ErrorMappings] are used for the response when deserializing failed | ||
/// responses bodies. Where an error code like 401 applies specifically to | ||
/// that status code, a class code like 4XX applies to all status codes within | ||
/// the range if an the specific error code is not present. | ||
typedef ErrorMappings = Map<String, ParsableFactory<Parsable>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
part of '../kiota_abstractions.dart'; | ||
|
||
/// Default response handler to access the native response object. | ||
class NativeResponseHandler implements ResponseHandler { | ||
/// The native response object as returned by the core service. | ||
Object? value; | ||
|
||
/// The error mappings for the response to use when deserializing failed | ||
/// response bodies. | ||
/// | ||
/// See [ErrorMappings] for more information. | ||
ErrorMappings? errorMappings; | ||
|
||
@override | ||
Future<ModelType?> | ||
handleResponse<NativeResponseType, ModelType extends Parsable>( | ||
NativeResponseType response, [ | ||
ErrorMappings? errorMapping, | ||
]) { | ||
errorMappings = errorMapping; | ||
value = response; | ||
|
||
return Future<ModelType?>.value(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
part of '../kiota_abstractions.dart'; | ||
|
||
/// Type definition for request callback. | ||
typedef RequestCallback<T> = Future<T> Function( | ||
QueryParameters Function()?, | ||
HttpHeaders Function()?, | ||
Iterable<RequestOption>?, | ||
ResponseHandler, | ||
); | ||
|
||
/// Type definition for request callback with body. | ||
typedef RequestWithBodyCallback<TBody, TResponse> = Future<TResponse> Function( | ||
TBody, | ||
QueryParameters Function()?, | ||
HttpHeaders Function()?, | ||
Iterable<RequestOption>?, | ||
ResponseHandler, | ||
); | ||
|
||
/// This class can be used to wrap a request using the fluent API and get the | ||
/// native response object in return. | ||
class NativeResponseWrapper { | ||
NativeResponseWrapper._(); | ||
|
||
/// Makes a request with the given parameters and returns the native response | ||
/// object. | ||
static Future<NativeResponseType?> | ||
callAndGetNativeType<ModelType, NativeResponseType>( | ||
RequestCallback<ModelType> callback, [ | ||
QueryParameters Function()? query, | ||
HttpHeaders Function()? headers, | ||
Iterable<RequestOption>? options, | ||
]) async { | ||
final handler = NativeResponseHandler(); | ||
|
||
// ignore result | ||
await callback(query, headers, options, handler); | ||
|
||
return handler.value as NativeResponseType?; | ||
} | ||
|
||
/// Makes a request with the given parameters and request body and then | ||
/// returns the native response object. | ||
static Future<NativeResponseType?> | ||
callAndGetNativeTypeWithBody<TBody, TResponse, NativeResponseType>( | ||
RequestWithBodyCallback<TBody, TResponse> callback, | ||
TBody body, [ | ||
QueryParameters Function()? query, | ||
HttpHeaders Function()? headers, | ||
Iterable<RequestOption>? options, | ||
]) async { | ||
final handler = NativeResponseHandler(); | ||
|
||
// ignore result | ||
await callback(body, query, headers, options, handler); | ||
|
||
return handler.value as NativeResponseType?; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
part of '../kiota_abstractions.dart'; | ||
|
||
/// Type definition for path parameters to be substituted in the URL template. | ||
typedef PathParameters = Map<String, dynamic>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
part of '../kiota_abstractions.dart'; | ||
|
||
/// Type definition for query parameters. | ||
typedef QueryParameters = Map<String, dynamic>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters