The liblastfm package

[Tags:library, mit]

Provides interface to Lastfm REST API, supports XML and JSON formats.


[Skip to Readme]

Properties

Versions 0.0.1.0, 0.0.2.1, 0.0.2.2, 0.0.3.0, 0.0.3.1, 0.0.3.2, 0.0.3.3, 0.0.3.4, 0.0.3.5, 0.0.3.6, 0.0.3.7, 0.0.3.8, 0.1.0.0, 0.1.1.0, 0.1.1.1, 0.1.1.2, 0.2.0.0, 0.3.0.0, 0.3.2.0, 0.4.0.0, 0.4.1.0, 0.5.0, 0.5.1, 0.6.0
Change log CHANGELOG.md
Dependencies aeson, base (>=3 && <5), bytestring, cereal, containers (>=0.5), contravariant, crypto-api, http-conduit (>=1.9), http-types, network, pureMD5, semigroups, tagged, text, void [details]
License MIT
Author Matvey Aksenov, Dmitry Malikov
Maintainer Matvey Aksenov <matvey.aksenov@gmail.com>
Stability Unknown
Category Network APIs
Source repository head: git clone https://github.com/supki/liblastfm
Uploaded Tue Dec 31 18:32:40 UTC 2013 by MatveyAksenov
Distributions
Downloads 3906 total (47 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Successful builds reported [all 1 reports]

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for liblastfm

Readme for liblastfm-0.3.2.0

liblastfm

Hackage Build Status Build Status

Complete API interface to last.fm service. Documentation is available in two flavours:

General introduction

liblastfm provides Applicative interface for constructing requests. Also, it handles all machinery needed to prepare request for sending:

  • signing
  • url-encoding
  • miscellaneous stuff like choosing correct HTTP method, etc

Once request is ready, liblastfm may send it and get you back a response. Response format might be:

  • Maybe Value from aeson for json queries (nice interaction with aeson-lens for free!)
  • raw ByteString for xml queries

Installation

To install either use hackage:

% cabal install liblastfm

Or git:

% git clone git@github.com:supki/liblastfm
% cd liblastfm
% cabal install

Usage

Suppose, you need to use tag.search API method. First find it in liblastfm: Tag would be the name of the module and search would be the name of function. Here it is. So import a couple of modules:

ghci> import Network.Lastfm -- a bunch of useful utilities
ghci> import qualified Network.Lastfm.Tag as Tag -- for Tag.search

Now you may you applicative <*> for required and <* or *> for optional parameters to construct desired request:

Tag.search <*> tag "russian-folk" <* limit 3 <*> apiKey "29effec263316a1f8a97f753caaa83e0" <* json

To send constructed request use lastfm:

ghci> lastfm $ Tag.search <*> tag "russian-folk" <* limit 10 <*> apiKey "29effec263316a1f8a97f753caaa83e0" <* json
Just (Object fromList [("results",Object fromList [("tagmatches", ...

How to parse responses is described in wiki.

FAQ

Q: I'm getting the following error. How do I fix it?

> Artist.getInfo <*> artist "Pink Floyd" <*> apiKey "29effec263316a1f8a97f753caaa83e0"

<interactive>:8:27:
    Couldn't match expected type `Data.Text.Lazy.Internal.Text'
                with actual type `[Char]

A: This means you haven't OverloadedStrings extension enabled. To enable it (either one works):

  • type in :set -XOverloadedStrings while in ghci session.
  • add {-# LANGUAGE OverloadedStrings #-} to the top of the file
  • compile with -XOverloadedStrings switch

Q: I'm getting the following error. How do I fix it?

> lastfm (Artist.getInfo <*> artist "Pink Floyd" <*> apiKey "29effec263316a1f8a97f753caaa83e0")

<interactive>:13:1:
    No instance for (Network.Lastfm.Response.Supported f0)
      arising from a use of `lastfm'
    The type variable `f0' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Network.Lastfm.Response.Supported 'XML
        -- Defined at src/Network/Lastfm/Response.hs:66:10
      instance Network.Lastfm.Response.Supported 'JSON
        -- Defined at src/Network/Lastfm/Response.hs:51:10

A: This error message indicates that GHC cannot infer response format for Request. To fix it, add use json or xml helpers, depending on your needs

> lastfm (Artist.getInfo <*> artist "Pink Floyd" <*> apiKey "29effec263316a1f8a97f753caaa83e0" <* json)
Just (Object fromList [("artist" ...
> lastfm (Artist.getInfo <*> artist "Pink Floyd" <*> apiKey "29effec263316a1f8a97f753caaa83e0" <* xml)
"<?xml version=\"1.0\" ...