read method

  1. @override
Future<XmlDocument> read(
  1. String method,
  2. Map<String, String> data, [
  3. bool authorize = true
])
override

Perform a "read" operation on the Last.fm api. This is typically done to get information about artists, albums, or tracks, or when authenticated to get information about the user or their listening habits.

Implementation

@override
Future<XmlDocument> read(String method, Map<String, String> data, [bool authorize = true]) async {
  if (!authorize) return super.read(method, data);
  final params = {...data, "api_key": apiKey, "method": method, "sk": sessionKey};
  final resp = await dio.get('/', queryParameters: {...params, "api_sig": sign(params)});
  final doc = XmlDocument.parse(resp.data);
  if (doc.rootElement.getAttribute("status") == "ok" || doc.rootElement.getAttribute("status") == null) {
    return doc;
  } else {
    throw LastFMError(doc.rootElement.getElement("error")!);
  }
}