brendanhay / gogol

A comprehensive Google Services SDK for Haskell.
Other
281 stars 105 forks source link

Remove servant and conduit #177

Open brendanhay opened 2 years ago

brendanhay commented 2 years ago

Various updates/fixes to eventually be catalogued here.

  1. Per-service OAuth scopes are now generated as type aliases of the form:
-- | View and manage your data across Google Cloud Platform services
type CloudPlatform'FullControl = "https://www.googleapis.com/auth/cloud-platform"

-- | View your data across Google Cloud Platform services
type CloudPlatform'ReadOnly = "https://www.googleapis.com/auth/cloud-platform.read-only"

-- | Manage your data and permissions in Google Cloud Storage
type Devstorage'FullControl = "https://www.googleapis.com/auth/devstorage.full_control"

-- | View your data in Google Cloud Storage
type Devstorage'ReadOnly = "https://www.googleapis.com/auth/devstorage.read_only"

-- | Manage your data in Google Cloud Storage
type Devstorage'ReadWrite = "https://www.googleapis.com/auth/devstorage.read_write"
  1. A per-service parameters datatype matching the service definitions global parameters is synthesised by the generator - this will be supplied to some variant of send as a first-class value so you can, say, add the apiKey parameter to requests:
-- /See:/ 'newStorageParams' smart constructor.
data StorageParams = StorageParams
  { -- | Selector specifying which fields to include in a partial response.
    fields :: Core.Maybe Core.Text,
    -- | API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
    key :: Core.Maybe Core.Text,
    -- | OAuth 2.0 token for the current user.
    oauthToken :: Core.Maybe Core.Text,
    -- | Returns response with indentations and line breaks.
    prettyPrint :: Core.Bool,
    -- | An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
    quotaUser :: Core.Maybe Core.Text
  }
  deriving (Core.Eq, Core.Ord, Core.Show, Core.Generic)

newStorageParams :: StorageParams
newStorageParams =
  StorageParams
    { fields = Core.Nothing,
      key = Core.Nothing,
      oauthToken = Core.Nothing,
      prettyPrint = Core.False,
      quotaUser = Core.Nothing
    }
  1. Servant is being removed and GoogleRequest instances are generated which construct an http-client Request (or possiblly an intermediate request datatype):
instance Core.GoogleRequest StorageObjectsInsert where
  type GoogleResponse StorageObjectsInsert = Object
  type GoogleScopes StorageObjectsInsert = '[ CloudPlatform'FullControl, Devstorage'FullControl, Devstorage'ReadWrite]
  type GoogleParams StorageObjectsInsert = StorageParams
  googleRequest StorageParams {..} StorageObjectsInsert {..} =
      Core.defaultRequest
        { method = "POST",
          path = Core.toRequestPath [ "storage/v1/b/", Core.toPathBuilder bucket, "/o"],
          queryString =
            Core.toRequestQuery $
              Core.catMaybes
                [ ("contentEncoding",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> contentEncoding,
                  ("ifGenerationMatch",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> ifGenerationMatch,
                  ("ifGenerationNotMatch",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> ifGenerationNotMatch,
                  ("ifMetagenerationMatch",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> ifMetagenerationMatch,
                  ("ifMetagenerationNotMatch",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> ifMetagenerationNotMatch,
                  ("key",) Core.. Core.toQueryParamBuilder
                    Core.<$> key,
                  ("kmsKeyName",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> kmsKeyName,
                  ("name",) Core.. Core.toQueryParamBuilder
                    Core.<$> name,
                  ("oauth_token",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> oauthToken,
                  ("predefinedAcl",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> predefinedAcl,
                  ("projection",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> projection,
                  ("provisionalUserProject",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> provisionalUserProject,
                  ("userProject",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> userProject,
                  ("quotaUser",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> quotaUser,
                  Core.Just
                    ( "prettyPrint",
                      Core.toQueryParamBuilder prettyPrint
                    ),
                  ("fields",)
                    Core.. Core.toQueryParamBuilder
                    Core.<$> fields,
                  Core.Just ("alt", Core.AltJSON)
                ],
          requestBody = Core.toRequestBodyJSON payload
        }
brendanhay commented 2 years ago

I've posted some thoughts regarding the ergonomics of constructing records with smart constructors.