@hackage pixiv0.1.1

Pixiv API binding based on servant-client

pixiv

build nix Hackage Hackage-Deps LICENSE

Haskell implementation of Pixiv API, based on servant-client.

Usage

In most cases, it is enough to import only Web.Pixiv. If you want to use lenses to access and operate data types, you should import Web.Pixiv.Types.Lens as well. Pixiv API requires authentication before being accessed, thus the PixivT monad transformer provides an user-friendly and thread-safe interface to manage, and renew access token on demand, where you just need to give the username and password refresh token (See https://github.com/upbit/pixivpy/issues/158) of your pixiv account.

Example

Here is a simpe example:

import Control.Lens ((^.))
import Control.Monad.IO.Class (liftIO)
import Web.Pixiv
import Web.Pixiv.Types.Lens

main :: IO ()
main = do
  let credential = RefreshToken "token"
  result <- runPixivT' credential action
  case result of
    Left err -> print err
    Right x -> pure x

action :: PixivT IO ()
action = do
  -- gets the details of user <https://www.pixiv.net/users/16731>
  userDetail <- getUserDetail 16731
  liftIO $ print userDetail

  -- gets the details of illustration <https://www.pixiv.net/artworks/80132896>
  illustDetail <- getIllustDetail 80132896
  liftIO $ print illustDetail

  -- gets day ranking illustrations
  -- 1 means the first page of the results
  ranking <- getIllustRanking (Just Day) 1
  liftIO $ print ranking

  -- searches the user who has name "玉之けだま" then gets their first work
  -- (function 'head' is not total, just used for demonstration) 
  targetUser <- head <$> searchUser "玉之けだま" Nothing 1
  firstWork <- head <$> getUserIllusts (targetUser ^. user . userId) (Just TypeIllust) 1
  liftIO $ print firstWork

As you can see, functions accessing Pixiv API are run in PixivT IO monad. For more functionalities this library provides and relevant information about functions or data types, please refer to the documentation.

Documentation

Documentation is available at hackage (latest release) and our github pages (master).