-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve API discoverability/clarity for devs with
S3ByteArrayFetching
Introducing: * **New type alias `S3ByteArrayFetching`** for `Fetching[ObjectId, Array[Byte]]` - when developers encounter a method needing `S3ByteArrayFetching`, the type alias now documents how to create that precise thing. * **New method `S3ObjectFetching.byteArraysWith(s3AsyncClient)`** as a convenience to create a `S3ByteArrayFetching` for AWS SDK v2, removing the need to know about the `Byte` transformer, or the need to map with `_.asByteArray()` This prompted by this PR (aiming to support the PR and make the changes in it easier to adopt): * guardian/facia-scala-client#287 ## How calling code changes Given calling code that already has `"com.gu.etag-caching" %% "aws-s3-sdk-v2"` as a dependency, and has this setup: ```scala import com.gu.etagcaching.aws.sdkv2.s3.S3ObjectFetching val s3AsyncClient: software.amazon.awssdk.services.s3.S3AsyncClient = ??? // AWS SDK v2 ``` ...the code to get a `Fetching[ObjectId, Array[Byte]]` looks like this: #### Before ```scala S3ObjectFetching(s3AsyncClient, Bytes).mapResponse(_.asByteArray()) ``` #### After ```scala S3ObjectFetching.byteArraysWith(s3AsyncClient) ```
- Loading branch information
Showing
7 changed files
with
80 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 @@ | ||
Au revoir! |
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 @@ | ||
Hello World! |
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
23 changes: 23 additions & 0 deletions
23
aws-s3/base/src/main/scala/com/gu/etagcaching/aws/s3/package.scala
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,23 @@ | ||
package com.gu.etagcaching.aws | ||
|
||
import com.gu.etagcaching.fetching.Fetching | ||
|
||
package object s3 { | ||
/** | ||
* This type provides an interface to get bytes out of S3, independent of the version of the | ||
* AWS SDK in use. When code depends on this interface, it's not directly tied to AWS SDK | ||
* version 1 or 2, and consumers can provide an instance of the interface backed by whatever | ||
* client they prefer (even AWS SDK v1, though that is discouraged). | ||
* | ||
* Assuming you're using AWS SDK v2, get an instance of `S3ByteArrayFetching` by adding | ||
* "com.gu.etag-caching" %% "aws-s3-sdk-v2" as a dependency, then: | ||
* | ||
* {{{ | ||
* import com.gu.etagcaching.aws.sdkv2.s3.S3ObjectFetching | ||
* | ||
* val s3AsyncClient: software.amazon.awssdk.services.s3.S3AsyncClient = ??? // AWS SDK v2 | ||
* val s3Fetching: S3ByteArrayFetching = S3ObjectFetching.byteArraysWith(s3AsyncClient) | ||
* }}} | ||
*/ | ||
type S3ByteArrayFetching = Fetching[ObjectId, Array[Byte]] | ||
} |
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