1111In your ` Package.swift ` file, add the following
1212
1313``` swift
14- .package (url : " https://github.com/vapor-community/google-cloud-provider.git" , from : " 1.0.0-alpha.1 " )
14+ .package (url : " https://github.com/vapor-community/google-cloud-provider.git" , from : " 1.0.0-beta " )
1515```
1616
1717Register the credentials configuration (required) and the provider in ` Configure.swift `
@@ -20,39 +20,34 @@ Register the credentials configuration (required) and the provider in `Configur
2020 import GoogleCloud
2121
2222 // register the credentials configuration which is used by all APIs
23- s .register (GoogleCloudCredentialsConfiguration.self ) { _ in
23+ app .register (GoogleCloudCredentialsConfiguration.self ) { _ in
2424 return GoogleCloudCredentialsConfiguration (project : " myprojectid-12345" ,
2525 credentialsFile : " ~/path/to/service-account.json" )
2626 }
2727
2828 // Register an API specific configuration. CloudStorage in this example.
29- s .register (GoogleCloudStorageConfiguration.self ) { _ in
29+ app .register (GoogleCloudStorageConfiguration.self ) { _ in
3030 return GoogleCloudStorageConfiguration.defult ()
3131 }
3232
33- s.provider (GoogleCloudProvider ())
33+ // Configure more API configurations that you want to use.
34+
35+ // Add the GoogleCloudProvider and choose the APIs you want to include
36+ app.provider (GoogleCloudProvider (apis : [.storage , .pubsub , ... ])
3437```
3538
36- Example usage
37- ``` swift
39+ Now we can access the `GoogleCloudClient` which has access to all the APIs we've configured.
3840
39- struct UploadRequest : Content {
40- var data: Data
41- var filename: String
42- }
43-
44- func uploadImage (_ req : Request) throws {
45- let upload = try req.content .decode (UploadRequest.self )
46-
47- let storageClient = try container.make (GoogleCloudStorageClient.self )
48- storageClient.object .createSimpleUpload (bucket : " vapor-cloud-storage-demo" ,
49- data : upload.data ,
50- name : upload.filename ,
51- contentType : " image/jpeg" ).flatMap { uploadedObject in
52- print (uploadedObject.mediaLink ) // prints the download link for the image.
41+ ```swift
42+ let cloudClient = app.make (GoogleCloudClient.self )
43+ // Use the Storage api to list the buckets.
44+ cloudClient.storage .buckets .list ().flatMap { buckets in
45+ print (buckets.items .last .name )
5346 }
54- }
5547```
5648
49+ ### Supported APIs
50+ [x] [CloudStorage](/ Sources/ CloudStorage/ README.md )
51+
5752### A More detailed guide can be found [here](https :// github.com/vapor-community/GoogleCloudKit).
5853
0 commit comments