| CARVIEW |
liblastfm: Lastfm API interface
Modules
[Index] [Quick Jump]
Flags
Manual Flags
| Name | Description | Default |
|---|---|---|
| test-api | a real API test | Disabled |
Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info
Downloads
- liblastfm-0.7.0.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
| Versions [RSS] | 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, 0.6.1, 0.7.0 (info) |
|---|---|
| Change log | CHANGELOG.markdown |
| Dependencies | aeson, base (>=4 && <5), bytestring, cereal, containers (>=0.5), cryptonite (>=0.7), http-client (>=0.5), http-client-tls (>=0.2), network-uri, profunctors, semigroups, text, transformers, xml-conduit (>=1.1) [details] |
| License | MIT |
| Author | Matvey Aksenov, Dmitry Malikov |
| Maintainer | Matvey Aksenov <matvey.aksenov@gmail.com> |
| Uploaded | by DmitryMalikov at 2018-08-07T19:59:58Z |
| Category | Network APIs |
| Source repo | head: git clone https://github.com/supki/liblastfm this: git clone https://github.com/supki/liblastfm(tag 0.7.0) |
| Distributions | |
| Reverse Dependencies | 1 direct, 0 indirect [details] |
| Downloads | 19707 total (111 in the last 30 days) |
| Rating | (no votes yet) [estimated by Bayesian average] |
| Your Rating |
|
| Status | Docs available [build log] Last success reported on 2018-08-07 [all 1 reports] |
Readme for liblastfm-0.7.0
[back to package description]liblastfm
Complete API interface to last.fm service. Documentation is available in two flavours:
-
original API reference
-
liblastfm haddocks
Introduction
liblastfm provides Applicative interface for constructing requests. Also, it handles all machinery needed to prepare request for sending:
-
url-encoding
-
miscellaneous stuff like choosing correct HTTP method, etc
Once request is ready, liblastfm can send it and get you back a response. Response format might be:
-
aeson
Valuefor json queries -
xml-conduit
Documentfor 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:
>>> import Lastfm -- a bunch of useful utilities
>>> import qualified Lastfm.Tag as Tag -- for Tag.search
Now you may use 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:
>>> con <- newConnection
>>> lastfm con $ Tag.search <*> tag "russian-folk" <* limit 10 <*> apiKey "29effec263316a1f8a97f753caaa83e0" <* json
Right (Object (fromList [("results",Object (fromList [("tagmatches", ...
Wiki describes how to parse responses.
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 -XOverloadedStringswhile in ghci session. -
add
{-# LANGUAGE OverloadedStrings #-}to the top of the file -
compile with
-XOverloadedStringsswitch
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 (Show (IO (Either LastfmError r0)))
arising from a use of `print'
Possible fix:
add an instance declaration for (Show (IO (Either LastfmError r0)))
In the first argument of `print', namely `it'
In a stmt of an interactive GHCi command: print it
A: This error message indicates that GHC cannot infer response format for the Request.
To fix it, add use json or xml helpers, depending on your needs
A note on testing
To test Lastfm API compatibility (api test suite)—specifically, authentication requiring
examples—you will need to set HASKELL_LIBLASTFM_APIKEY, HASKELL_LIBLASTFM_SESSIONKEY,
and HASKELL_LIBLASTFM_SECRET environment variables to your api key, session key, and
secret respectively; for example (bash):
export HASKELL_LIBLASTFM_APIKEY="__API_KEY__"
export HASKELL_LIBLASTFM_SESSIONKEY="__SESSION_KEY__"
export HASKELL_LIBLASTFM_SECRET="__SECRET__"
Please, consult Lastfm API documentation and example/*-authentication.hs
examples if you don't know where to get your credentials.
