Copyright | (c) 2021 Rory Tyler Hayford |
---|---|
License | BSD-3-Clause |
Maintainer | rory.hayford@protonmail.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- class Thing a where
- data RedditKind
- = CommentKind
- | AccountKind
- | SubmissionKind
- | MessageKind
- | SubredditKind
- | AwardKind
- | ListingKind
- | UserListKind
- | KarmaListKind
- | TrophyListKind
- | MoreKind
- | RelKind
- | SubredditSettingsKind
- | StylesheetKind
- | WikiPageKind
- | WikiPageListingKind
- | WikiPageSettingsKind
- | LabeledMultiKind
- | ModActionKind
- | LiveThreadKind
- | LiveUpdateKind
- class Paginable a where
- type PaginateOptions (a :: Type)
- type PaginateThing (a :: Type)
- defaultOpts :: PaginateOptions a
- getFullname :: a -> PaginateThing a
- optsToForm :: PaginateOptions a -> Form
- data Paginator t a = Paginator {}
- data Listing t a = Listing {}
- newtype CIText a = CIText a
- type family HKD f a where ...
- data ItemOpts a = ItemOpts {}
- defaultItemOpts :: ItemOpts a
- data ItemSort
- = Hot
- | New
- | Top
- | Controversial
- | Old
- | Random
- | QA
- | Live
- | Confidence
- data ItemReport = ItemReport {}
- data Distinction
- data Time
- data ItemType
- data UploadURL
- type Body = Text
- type Title = Text
- type URL = Text
- type Subject = Text
- type RGBText = Text
- type Name = Text
- type Domain = Text
- type Modifier = [Char] -> [Char]
- type RawBody m = ConduitM () ByteString m ()
- data RedditException
- data ClientException
- data APIException
- data OAauthError = OAauthError {
- errorType :: Text
- description :: Maybe Text
- data ErrorMessage
- type StatusCode = Int
- data StatusMessage = StatusMessage {
- statusCode :: StatusCode
- message :: Text
- data JSONError = JSONError {}
- dropTypePrefix :: RedditKind -> Text -> Parser Text
- integerToUTC :: Integer -> UTCTime
- withKind :: FromJSON b => RedditKind -> [Char] -> (b -> Parser a) -> Value -> Parser a
- textKind :: RedditKind -> Text
- prependType :: RedditKind -> Text -> Text
- bshow :: Show a => a -> ByteString
- tshow :: Show a => a -> Text
- editedP :: Value -> Parser (Maybe UTCTime)
- validateName :: (MonadThrow m, Coercible a Text) => Maybe [Char] -> Maybe (Int, Int) -> Text -> Text -> m a
- joinParams :: (Foldable t, ToHttpApiData a) => t a -> Text
- nothingTxtNull :: FromJSON a => Text -> Parser (Maybe a)
- textObject :: [Pair] -> Text
- textEncode :: ToJSON a => a -> Text
- withKinds :: FromJSON b => [RedditKind] -> [Char] -> (b -> Parser a) -> Value -> Parser a
- breakOnType :: Coercible a Text => Text -> Text -> Parser a
- getVals :: FromJSON b => HashMap Text Value -> Parser (Seq b)
- mkTextForm :: [(Text, Text)] -> Form
Documentation
"Thing"s are the base class of Reddit's OOP model. Each thing has several
properties, but here we are only interested in one, the "fullname". This
is a combination of a thing's type (here represented as a RedditKind
), and its
unique ID
fullname :: a -> Text Source #
A fullname
is an identifier with a "type prefix" attached. See RedditKind
for possible prefixes. This prefixed form is required in various places by
the Reddit API
Instances
data RedditKind Source #
A RedditKind
represents a textual prefix that Reddit uses to denote types
in its API
Instances
Eq RedditKind Source # | |
Defined in Network.Reddit.Types.Internal (==) :: RedditKind -> RedditKind -> Bool # (/=) :: RedditKind -> RedditKind -> Bool # | |
FromJSON RedditKind Source # | |
Defined in Network.Reddit.Types.Internal parseJSON :: Value -> Parser RedditKind # parseJSONList :: Value -> Parser [RedditKind] # |
class Paginable a where Source #
Represents requests that can take additional options in a Paginator
. This
can be used to filter/sort Listing
endpoints
type PaginateOptions (a :: Type) Source #
type PaginateThing (a :: Type) Source #
defaultOpts :: PaginateOptions a Source #
Default PaginateOptions
for this type
getFullname :: a -> PaginateThing a Source #
Get the fullname of the Thing
type associated with this type, if
any
default getFullname :: PaginateThing a ~ Text => a -> PaginateThing a Source #
optsToForm :: PaginateOptions a -> Form Source #
Convert the PaginateOptions
options to a Form
default optsToForm :: ToForm (PaginateOptions a) => PaginateOptions a -> Form Source #
Instances
This represents the protocol that Reddit uses to control paginating and
filtering entries. These can be applied to Listing
endpoints. The first
four fields below are common parameters that are applied to each Listing
.
The opts
field takes extended PaginateOptions
based on the second type
parameter
Paginator | |
|
Instances
Certain API endpoints are listings
, which can be paginated and filtered
using a Paginator
Instances
(Eq t, Eq a) => Eq (Listing t a) Source # | |
(Show t, Show a) => Show (Listing t a) Source # | |
Generic (Listing t a) Source # | |
Ord t => Semigroup (Listing t a) Source # | |
Ord t => Monoid (Listing t a) Source # | |
(FromJSON a, FromJSON t) => FromJSON (Listing t a) Source # | |
type Rep (Listing t a) Source # | |
Defined in Network.Reddit.Types.Internal type Rep (Listing t a) = D1 ('MetaData "Listing" "Network.Reddit.Types.Internal" "heddit-0.0.1-76ROQ5tOAm3CpLSaFw8ccb" 'False) (C1 ('MetaCons "Listing" 'PrefixI 'True) (S1 ('MetaSel ('Just "before") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe t)) :*: (S1 ('MetaSel ('Just "after") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe t)) :*: S1 ('MetaSel ('Just "children") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Seq a))))) |
CIText a |
Options that can be applied to comments or submissions, as represented by the phantom type parameter
Instances
Eq (ItemOpts a) Source # | |
Show (ItemOpts a) Source # | |
Generic (ItemOpts a) Source # | |
ToForm (ItemOpts a) Source # | |
Defined in Network.Reddit.Types.Internal | |
type Rep (ItemOpts a) Source # | |
Defined in Network.Reddit.Types.Internal type Rep (ItemOpts a) = D1 ('MetaData "ItemOpts" "Network.Reddit.Types.Internal" "heddit-0.0.1-76ROQ5tOAm3CpLSaFw8ccb" 'False) (C1 ('MetaCons "ItemOpts" 'PrefixI 'True) ((S1 ('MetaSel ('Just "itemSort") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe ItemSort)) :*: S1 ('MetaSel ('Just "itemType") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe ItemType))) :*: (S1 ('MetaSel ('Just "itemTime") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe Time)) :*: S1 ('MetaSel ('Just "context") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe Word))))) |
defaultItemOpts :: ItemOpts a Source #
Defaults for fetching items, like comments or submissions
How to sort items in certain Listing
s. Not every option is guaranteed to
be accepted by a given endpoint
Instances
data ItemReport Source #
A user- or moderator-generated report on a submission
Instances
data Distinction Source #
Sigils that a moderator can add to distinguish comments or submissions. Note
that the Admin
and Special
distinctions require special privileges to use
Moderator | Adds "[M]" |
Undistinguished | Removes an existing distinction when sent |
Admin | Adds "[A]" |
Special | User-specific distinction |
Instances
Time range when fetching comments or submissions
Instances
Eq Time Source # | |
Show Time Source # | |
Generic Time Source # | |
ToHttpApiData Time Source # | |
Defined in Network.Reddit.Types.Internal toUrlPiece :: Time -> Text # toEncodedUrlPiece :: Time -> Builder # toHeader :: Time -> ByteString # toQueryParam :: Time -> Text # | |
type Rep Time Source # | |
Defined in Network.Reddit.Types.Internal type Rep Time = D1 ('MetaData "Time" "Network.Reddit.Types.Internal" "heddit-0.0.1-76ROQ5tOAm3CpLSaFw8ccb" 'False) ((C1 ('MetaCons "Hour" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Day" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Week" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "Month" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Year" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "AllTime" 'PrefixI 'False) (U1 :: Type -> Type)))) |
Type of comments, for filtering in Listing
s
Instances
Eq ItemType Source # | |
Show ItemType Source # | |
Generic ItemType Source # | |
ToHttpApiData ItemType Source # | |
Defined in Network.Reddit.Types.Internal toUrlPiece :: ItemType -> Text # toEncodedUrlPiece :: ItemType -> Builder # toHeader :: ItemType -> ByteString # toQueryParam :: ItemType -> Text # | |
type Rep ItemType Source # | |
A URL pointing to a resource hosted by Reddit. These should only be obtained
by parsing the JSON of existing resources or through particular actions that
perform the upload transaction and return the URL, e.g.
uploadWidgetImage
Instances
Eq UploadURL Source # | |
Show UploadURL Source # | |
Generic UploadURL Source # | |
ToJSON UploadURL Source # | |
Defined in Network.Reddit.Types.Internal | |
FromJSON UploadURL Source # | |
ToHttpApiData UploadURL Source # | |
Defined in Network.Reddit.Types.Internal toUrlPiece :: UploadURL -> Text # toEncodedUrlPiece :: UploadURL -> Builder # toHeader :: UploadURL -> ByteString # toQueryParam :: UploadURL -> Text # | |
type Rep UploadURL Source # | |
Defined in Network.Reddit.Types.Internal |
type RawBody m = ConduitM () ByteString m () Source #
Type synonym the raw body of an HTTP response
Exceptions
data RedditException Source #
Base exception type for Reddit API client
Instances
Show RedditException Source # | |
Defined in Network.Reddit.Types.Internal showsPrec :: Int -> RedditException -> ShowS # show :: RedditException -> String # showList :: [RedditException] -> ShowS # | |
Exception RedditException Source # | |
Defined in Network.Reddit.Types.Internal |
data ClientException Source #
Exceptions generated within the Reddit API client
InvalidRequest Text | |
InvalidResponse Text | |
MalformedCredentials Text | |
OtherError Text | |
ConfigurationError Text |
Instances
data APIException Source #
Exceptions returned from API endpoints
ErrorWithStatus StatusMessage | |
ErrorWithMessage ErrorMessage | |
InvalidCredentials OAauthError | |
InvalidJSON JSONError | Sent if errors occur when posting JSON |
JSONParseError Text ByteString | With the response body, for further debugging |
Redirected (Maybe Request) | If the API action should not allow automatic redirects, this error returns the possible redirected request |
WebsocketError Text SomeException | Thrown when exceptions occur during websocket handling |
UploadFailed | When an error occurs uploading media to Reddit's servers |
Instances
data OAauthError Source #
An error which occurs when attempting to authenticate via OAuth
OAauthError | |
|
Instances
data ErrorMessage Source #
A specific error message
EmptyError | |
OtherErrorMessage [Value] | |
Ratelimited Integer Text | |
CommentDeleted | |
BadSRName | |
SubredditNotExists | |
SubredditRequired | |
AlreadySubmitted | |
NoURL | |
NoName | |
NoText | |
TooShort | |
BadCaptcha | |
UserRequired |
Instances
type StatusCode = Int Source #
Type synonym for status codes in responses
data StatusMessage Source #
Details about a non-200 HTTP response
Instances
Details about a non-200 response when posting JSON
Instances
Eq JSONError Source # | |
Show JSONError Source # | |
Generic JSONError Source # | |
FromJSON JSONError Source # | |
type Rep JSONError Source # | |
Defined in Network.Reddit.Types.Internal type Rep JSONError = D1 ('MetaData "JSONError" "Network.Reddit.Types.Internal" "heddit-0.0.1-76ROQ5tOAm3CpLSaFw8ccb" 'False) (C1 ('MetaCons "JSONError" 'PrefixI 'True) ((S1 ('MetaSel ('Just "fields") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 [Text]) :*: S1 ('MetaSel ('Just "explanation") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Text)) :*: (S1 ('MetaSel ('Just "message") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Just "reason") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Text)))) |
Utilities
dropTypePrefix :: RedditKind -> Text -> Parser Text Source #
Drop the leading textual representation of a RedditKind
from a Reddit identifier,
or return the entire identifier if there is no prefix
withKind :: FromJSON b => RedditKind -> [Char] -> (b -> Parser a) -> Value -> Parser a Source #
Ensures that the kind
field of a JSON object corresponds to the
expected RedditKind
of the response and runs a parsing function on its
data
field
textKind :: RedditKind -> Text Source #
Convert a RedditKind
to its textual representation
prependType :: RedditKind -> Text -> Text Source #
Opposite of dropTypePrefix
: joins the textual representation of a RedditKind
to an identifier with an underscore
bshow :: Show a => a -> ByteString Source #
editedP :: Value -> Parser (Maybe UTCTime) Source #
Parse the edited
field in comments or submissions, which can either be
false
or a Unix timestamp
validateName :: (MonadThrow m, Coercible a Text) => Maybe [Char] -> Maybe (Int, Int) -> Text -> Text -> m a Source #
Verify that some name corresponds to specifiable Reddit naming rules
joinParams :: (Foldable t, ToHttpApiData a) => t a -> Text Source #
Make a comma-separated sequence of query params
nothingTxtNull :: FromJSON a => Text -> Parser (Maybe a) Source #
Return Nothing
if a text field is empty
withKinds :: FromJSON b => [RedditKind] -> [Char] -> (b -> Parser a) -> Value -> Parser a Source #
Like withKind
, but can be used in the exceptional circumstances that a
container of values have heterogeneous kinds
breakOnType :: Coercible a Text => Text -> Text -> Parser a Source #
Split a JSON identifier on "_"; if it matches the given type prefix, returning the remaining text. Otherwise, return the identifier whole if there is no remaining text