| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Stripe.Wreq
Description
Typical use of this module:
- Run
get,post, ordeleteto get aWreqResponse. - Use
wreqResponseto convert the Wreq response to aResponse. - Use
responseValueto obtain the response payload as an AesonValue(or anErrorif the request was not successful).
Synopsis
- get :: Session -> ApiSecretKey -> Get -> IO WreqResponse
- get' :: Session -> ApiSecretKey -> RequestApiVersion -> Get -> IO WreqResponse
- data Get = Get {}
- post :: Session -> ApiSecretKey -> Post -> IO WreqResponse
- post' :: Session -> ApiSecretKey -> RequestApiVersion -> Post -> IO WreqResponse
- data Post = Post {
- postPath :: [Text]
- postParams :: [FormParam]
- delete :: Session -> ApiSecretKey -> Delete -> IO WreqResponse
- delete' :: Session -> ApiSecretKey -> RequestApiVersion -> Delete -> IO WreqResponse
- data Delete = Delete {
- deletePath :: [Text]
- deleteParams :: [(Text, Text)]
- type WreqResponse = Response ByteString
- data Response = Response {}
- wreqResponse :: WreqResponse -> Response
- responseValue :: Response -> Either Error Value
- responseValueError :: Value -> Error
- data Error = Error {
- userMessages :: [UserMessage]
- logMessages :: [LogMessage]
- newtype UserMessage = UserMessage Text
- newtype LogMessage = LogMessage Text
- userError :: Text -> Error
- logError :: Text -> Error
- newtype StatusCode = StatusCode Int
- isSuccess :: StatusCode -> Bool
- isError :: StatusCode -> Bool
- isClientError :: StatusCode -> Bool
- isServerError :: StatusCode -> Bool
- badRequest400 :: StatusCode
- unauthorized401 :: StatusCode
- requestFailed402 :: StatusCode
- notFound404 :: StatusCode
- conflict409 :: StatusCode
- tooManyRequests429 :: StatusCode
- data FormParam where
- (:=) :: forall v. FormValue v => ByteString -> v -> FormParam
- data Session
- newAPISession :: IO Session
Request
GET
get :: Session -> ApiSecretKey -> Get -> IO WreqResponse Source #
get' :: Session -> ApiSecretKey -> RequestApiVersion -> Get -> IO WreqResponse Source #
POST
post :: Session -> ApiSecretKey -> Post -> IO WreqResponse Source #
post' :: Session -> ApiSecretKey -> RequestApiVersion -> Post -> IO WreqResponse Source #
Constructors
| Post | |
Fields
| |
DELETE
delete :: Session -> ApiSecretKey -> Delete -> IO WreqResponse Source #
delete' :: Session -> ApiSecretKey -> RequestApiVersion -> Delete -> IO WreqResponse Source #
Constructors
| Delete | |
Fields
| |
Response
type WreqResponse = Response ByteString Source #
Constructors
| Response | |
Fields
| |
wreqResponse :: WreqResponse -> Response Source #
Convert a WreqResponse into a Response by parsing the JSON response
body (the Stripe API always returns JSON) and getting the HTTP status code.
responseValueError :: Value -> Error Source #
If the response object looks like this:
{
"error": {
"type": "card_error",
"message": "..."
}
}
}then we use the value of the message field as a UserMessage. Otherwise it is
a LogMessage.
"message: A human-readable message providing more details about the error. For
card errors, these messages can be shown to your users. [...] Card errors are
the most common type of error you should expect to handle. They result when the
user enters a card that can't be charged for some reason." -
Stripe
Error
Constructors
| Error | |
Fields
| |
newtype UserMessage Source #
An error message suitable for being shown to a user.
Constructors
| UserMessage Text |
Instances
| Show UserMessage Source # | |
Defined in Stripe.Wreq Methods showsPrec :: Int -> UserMessage -> ShowS # show :: UserMessage -> String # showList :: [UserMessage] -> ShowS # | |
| Eq UserMessage Source # | |
Defined in Stripe.Wreq | |
newtype LogMessage Source #
An error message that should go into an error log, not shown to a user.
Constructors
| LogMessage Text |
Instances
| Show LogMessage Source # | |
Defined in Stripe.Wreq Methods showsPrec :: Int -> LogMessage -> ShowS # show :: LogMessage -> String # showList :: [LogMessage] -> ShowS # | |
| Eq LogMessage Source # | |
Defined in Stripe.Wreq | |
Status code
newtype StatusCode Source #
An HTTP status code returned by Stripe.
"Stripe uses conventional HTTP response codes to indicate the success or failure of an API request." - Stripe
Constructors
| StatusCode Int |
Instances
| Eq StatusCode Source # | |
Defined in Stripe.Wreq | |
Predicates
Some basic functions for interpreting status codes.
isError :: StatusCode -> Bool Source #
isError x is equivalent to .isClientError x || isServerError x
isClientError :: StatusCode -> Bool Source #
"Codes in the 4xx range indicate an error that failed given the information provided (e.g., a required parameter was omitted, a charge failed, etc.)." - Stripe
isServerError :: StatusCode -> Bool Source #
"Codes in the 5xx range indicate an error with Stripe's servers." - Stripe
Client error codes
Constants for each of the error codes enumerated in the Stripe API documentation, for your convenience.
badRequest400 :: StatusCode Source #
400 - Bad Request
"The request was unacceptable, often due to missing a required parameter." - Stripe
unauthorized401 :: StatusCode Source #
401 - Unauthorized
"No valid API key provided." - Stripe
requestFailed402 :: StatusCode Source #
402 - Request Failed
"The parameters were valid but the request failed." - Stripe
notFound404 :: StatusCode Source #
404 - Not Found
"The requested resource doesn't exist." - Stripe
conflict409 :: StatusCode Source #
409 - Conflict
"The request conflicts with another request (perhaps due to using the same idempotent key)." - Stripe
tooManyRequests429 :: StatusCode Source #
429 - Too Many Requests
"Too many requests hit the API too quickly. We recommend an exponential backoff of your requests." - Stripe
Re-exports from Wreq
A key/value pair for an application/x-www-form-urlencoded
POST request body.
Constructors
| (:=) :: forall v. FormValue v => ByteString -> v -> FormParam infixr 3 |
A session that spans multiple requests. This is responsible for cookie management and TCP connection reuse.
newAPISession :: IO Session #
Create a session.
This uses the default session manager settings, but does not manage cookies. It is intended for use with REST-like HTTP-based APIs, which typically do not use cookies.
Since: wreq-0.5.2.0