Safe Haskell | None |
---|---|
Language | Haskell2010 |
StripeAPI.Common
Description
This module serves the purpose of defining common functionality which remains the same across all OpenAPI specifications.
Synopsis
- data Configuration s = Configuration {}
- doCallWithConfiguration :: (MonadHTTP m, SecurityScheme s) => Configuration s -> Text -> Text -> [(Text, Maybe String)] -> m (Either HttpException (Response ByteString))
- doCallWithConfigurationM :: (MonadHTTP m, SecurityScheme s) => Text -> Text -> [(Text, Maybe String)] -> ReaderT (Configuration s) m (Either HttpException (Response ByteString))
- doBodyCallWithConfiguration :: (MonadHTTP m, SecurityScheme s, ToJSON body) => Configuration s -> Text -> Text -> [(Text, Maybe String)] -> Maybe body -> RequestBodyEncoding -> m (Either HttpException (Response ByteString))
- doBodyCallWithConfigurationM :: (MonadHTTP m, SecurityScheme s, ToJSON body) => Text -> Text -> [(Text, Maybe String)] -> Maybe body -> RequestBodyEncoding -> ReaderT (Configuration s) m (Either HttpException (Response ByteString))
- runWithConfiguration :: SecurityScheme s => Configuration s -> ReaderT (Configuration s) m a -> m a
- class Monad m => MonadHTTP m where
- httpBS :: Request -> m (Either HttpException (Response ByteString))
- stringifyModel :: StringifyModel a => a -> String
- class Show a => StringifyModel a
- class SecurityScheme s where
- authenticateRequest :: s -> Request -> Request
- data AnonymousSecurityScheme = AnonymousSecurityScheme
- textToByte :: Text -> ByteString
- newtype JsonByteString = JsonByteString ByteString
- newtype JsonDateTime = JsonDateTime ZonedTime
- data RequestBodyEncoding
Documentation
data Configuration s Source #
An operation can and must be configured with data, which may be common for many operations.
This configuration consists of information about the server URL and the used security scheme.
In OpenAPI these information can be defined
- Root level
- Path level
- Operation level
To get started, the defaultConfiguration
can be used and changed accordingly.
Note that it is possible that BearerAuthenticationSecurityScheme
is not available because it is not a security scheme in the OpenAPI specification.
defaultConfiguration { configSecurityScheme = BearerAuthenticationSecurityScheme "token" }
Constructors
Configuration | |
Fields
|
Instances
doCallWithConfiguration Source #
Arguments
:: (MonadHTTP m, SecurityScheme s) | |
=> Configuration s | Configuration options like base URL and security scheme |
-> Text | HTTP method (GET, POST, etc.) |
-> Text | Path to append to the base URL (path parameters should already be replaced) |
-> [(Text, Maybe String)] | Query parameters |
-> m (Either HttpException (Response ByteString)) | The raw response from the server |
This is the main functionality of this module
It makes a concrete Call to a Server without a body
doCallWithConfigurationM :: (MonadHTTP m, SecurityScheme s) => Text -> Text -> [(Text, Maybe String)] -> ReaderT (Configuration s) m (Either HttpException (Response ByteString)) Source #
Same as doCallWithConfiguration
but run in a ReaderT
environment which contains the configuration.
This is useful if multiple calls have to be executed with the same configuration.
doBodyCallWithConfiguration Source #
Arguments
:: (MonadHTTP m, SecurityScheme s, ToJSON body) | |
=> Configuration s | Configuration options like base URL and security scheme |
-> Text | HTTP method (GET, POST, etc.) |
-> Text | Path to append to the base URL (path parameters should already be replaced) |
-> [(Text, Maybe String)] | Query parameters |
-> Maybe body | Request body |
-> RequestBodyEncoding | JSON or form data deepobjects |
-> m (Either HttpException (Response ByteString)) | The raw response from the server |
This is the main functionality of this module
It makes a concrete Call to a Server with a body
doBodyCallWithConfigurationM :: (MonadHTTP m, SecurityScheme s, ToJSON body) => Text -> Text -> [(Text, Maybe String)] -> Maybe body -> RequestBodyEncoding -> ReaderT (Configuration s) m (Either HttpException (Response ByteString)) Source #
Same as doBodyCallWithConfiguration
but run in a ReaderT
environment which contains the configuration.
This is useful if multiple calls have to be executed with the same configuration.
runWithConfiguration :: SecurityScheme s => Configuration s -> ReaderT (Configuration s) m a -> m a Source #
Run the ReaderT
monad with a specified configuration
Note: This is just
.flip
runReaderT
class Monad m => MonadHTTP m where Source #
Abstracts the usage of httpBS
away,
so that it can be used for testing
Methods
httpBS :: Request -> m (Either HttpException (Response ByteString)) Source #
Instances
MonadHTTP IO Source # | This instance is the default instance used for production code |
Defined in StripeAPI.Common Methods httpBS :: Request -> IO (Either HttpException (Response ByteString)) Source # | |
MonadHTTP m => MonadHTTP (ReaderT r m) Source # | |
Defined in StripeAPI.Common Methods httpBS :: Request -> ReaderT r m (Either HttpException (Response ByteString)) Source # |
stringifyModel :: StringifyModel a => a -> String Source #
Stringifies a showable value
>>>
stringifyModel "Test"
"Test"
>>>
stringifyModel 123
"123"
class Show a => StringifyModel a Source #
This type class makes the code generation for URL parameters easier as it allows to stringify a value
The Show
class is not sufficient as strings should not be stringified with quotes.
Minimal complete definition
Instances
Show a => StringifyModel a Source # | |
Defined in StripeAPI.Common Methods stringifyModel :: a -> String Source # | |
StringifyModel Text Source # | |
Defined in StripeAPI.Common Methods stringifyModel :: Text -> String Source # | |
StringifyModel String Source # | |
Defined in StripeAPI.Common Methods stringifyModel :: String -> String Source # |
class SecurityScheme s where Source #
Allows to specify an authentication scheme for requests done with doCallWithConfiguration
This can be used to define custom schemes as well
Methods
authenticateRequest :: s -> Request -> Request Source #
Instances
SecurityScheme AnonymousSecurityScheme Source # | Instance for the anonymous scheme which does not alter the request in any way |
Defined in StripeAPI.Common Methods authenticateRequest :: AnonymousSecurityScheme -> Request -> Request Source # | |
SecurityScheme BearerAuthenticationSecurityScheme Source # | |
Defined in StripeAPI.SecuritySchemes Methods authenticateRequest :: BearerAuthenticationSecurityScheme -> Request -> Request Source # | |
SecurityScheme BasicAuthenticationSecurityScheme Source # | |
Defined in StripeAPI.SecuritySchemes Methods authenticateRequest :: BasicAuthenticationSecurityScheme -> Request -> Request Source # |
data AnonymousSecurityScheme Source #
The default authentication scheme which does not add any authentication information
Constructors
AnonymousSecurityScheme |
Instances
SecurityScheme AnonymousSecurityScheme Source # | Instance for the anonymous scheme which does not alter the request in any way |
Defined in StripeAPI.Common Methods authenticateRequest :: AnonymousSecurityScheme -> Request -> Request Source # |
textToByte :: Text -> ByteString Source #
Convert Text
a to ByteString
newtype JsonByteString Source #
Wraps a ByteString
to implement ToJSON
and FromJSON
Constructors
JsonByteString ByteString |
Instances
newtype JsonDateTime Source #
Constructors
JsonDateTime ZonedTime |
Instances
Eq JsonDateTime Source # | |
Defined in StripeAPI.Common | |
Ord JsonDateTime Source # | |
Defined in StripeAPI.Common Methods compare :: JsonDateTime -> JsonDateTime -> Ordering # (<) :: JsonDateTime -> JsonDateTime -> Bool # (<=) :: JsonDateTime -> JsonDateTime -> Bool # (>) :: JsonDateTime -> JsonDateTime -> Bool # (>=) :: JsonDateTime -> JsonDateTime -> Bool # max :: JsonDateTime -> JsonDateTime -> JsonDateTime # min :: JsonDateTime -> JsonDateTime -> JsonDateTime # | |
Show JsonDateTime Source # | |
Defined in StripeAPI.Common Methods showsPrec :: Int -> JsonDateTime -> ShowS # show :: JsonDateTime -> String # showList :: [JsonDateTime] -> ShowS # | |
ToJSON JsonDateTime Source # | |
Defined in StripeAPI.Common Methods toJSON :: JsonDateTime -> Value # toEncoding :: JsonDateTime -> Encoding # toJSONList :: [JsonDateTime] -> Value # toEncodingList :: [JsonDateTime] -> Encoding # | |
FromJSON JsonDateTime Source # | |
Defined in StripeAPI.Common |
data RequestBodyEncoding Source #
Defines how a request body is encoded
Constructors
RequestBodyEncodingJSON | Encode the body as JSON |
RequestBodyEncodingFormData | Encode the body as form data |