-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
317 additions
and
227 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
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 |
---|---|---|
@@ -1,19 +1,34 @@ | ||
import 'package:http_interop/http_interop.dart'; | ||
import 'package:http_interop/http_interop.dart' as i; | ||
import 'package:json_api/document.dart'; | ||
import 'package:json_api/src/client/response.dart'; | ||
|
||
/// A response to a relationship fetch request. | ||
class RelationshipFetched<R extends Relationship> { | ||
RelationshipFetched(this.httpResponse, this.relationship); | ||
RelationshipFetched(this.rawResponse, this.relationship); | ||
|
||
static RelationshipFetched<ToMany> many(Response httpResponse, Map json) => | ||
RelationshipFetched(httpResponse, InboundDocument(json).asToMany()) | ||
..included.addAll(InboundDocument(json).included()); | ||
static RelationshipFetched<ToMany> many(Response response) { | ||
final document = InboundDocument(response.document ?? | ||
(throw FormatException('The document must not be empty'))); | ||
return RelationshipFetched(response, document.asToMany()) | ||
..included.addAll(document.included()); | ||
} | ||
|
||
static RelationshipFetched<ToOne> one(Response httpResponse, Map json) => | ||
RelationshipFetched(httpResponse, InboundDocument(json).asToOne()) | ||
..included.addAll(InboundDocument(json).included()); | ||
static RelationshipFetched<ToOne> one(Response response) { | ||
final document = InboundDocument(response.document ?? | ||
(throw FormatException('The document must not be empty'))); | ||
return RelationshipFetched(response, document.asToOne()) | ||
..included.addAll(document.included()); | ||
} | ||
|
||
// coverage:ignore-start | ||
/// The raw HTTP response | ||
@Deprecated('Use rawResponse.httpResponse instead') | ||
i.Response get httpResponse => rawResponse.httpResponse; | ||
// coverage:ignore-end | ||
|
||
/// The raw JSON:API response | ||
final Response rawResponse; | ||
|
||
final Response httpResponse; | ||
final R relationship; | ||
final included = <Resource>[]; | ||
} |
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
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
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
Oops, something went wrong.