You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if the library supported pagination natively, so that the user doesn't have to do it themself. The wreq library, for instance, has some basic support for this.
I'm not sure what exactly this should look like, and if the library wants to provide such higher-level helpers at all. Just in case, here's a naive conduit implementation:
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedStrings #-}
{-| Copyright: 2017 (C) AlphaSheets, Inc Description: Conduit support for 'Web.Stripe'-}moduleWeb.Stripe.ConduitwhereimportControl.MonadimportControl.Monad.CatchimportControl.Monad.IO.ClassimportData.AesonimportData.ConduitimportSafe (lastMay)
importWeb.Stripe (stripe, (-&-))
importqualifiedData.Conduit.ListasCLimportqualifiedWeb.StripeasStripeimportqualifiedWeb.Stripe.CustomerasStripe--| Create a conduit request to `Stripe`'s API
stripeConduit
:: (MonadIOm, FromJSON (Stripe.StripeReturna)
, Stripe.StripeReturna~Stripe.StripeListb
, Stripe.StripeHasParama (Stripe.StartingAfterid)
, MonadThrowm)
=>Stripe.StripeConfig->Stripe.StripeRequesta-> (b->id)
--^ A mapping between the type and its ID field used in pagination-- TODO: the user should not have to set this themself->Sourcemb
stripeConduit config request toId =do
res <- liftIO $ stripe config request
case res ofLeft e -> throwM e
Right slist ->do-- Yield all objs already presentlet objs =Stripe.list slist
CL.sourceList objs
-- Paginate
when (Stripe.hasMore slist) $do
lastId <-case toId <$> lastMay objs ofJust lastId ->pure lastId
Nothing-> throwM Stripe.StripeError
{ Stripe.errorType =Stripe.APIError
, Stripe.errorMsg ="Stripe returned an empty list"
, Stripe.errorCode =Nothing
, Stripe.errorParam =Nothing
, Stripe.errorHTTP =Nothing
}
stripeConduit
config
(request -&-Stripe.StartingAfter lastId)
toId
The text was updated successfully, but these errors were encountered:
It would be nice if the library supported pagination natively, so that the user doesn't have to do it themself. The
wreq
library, for instance, has some basic support for this.I'm not sure what exactly this should look like, and if the library wants to provide such higher-level helpers at all. Just in case, here's a naive conduit implementation:
The text was updated successfully, but these errors were encountered: