Git Product home page Git Product logo

lastfm-lib's Introduction

lastfm-library

Gradle:

compile 'com.github.ag:lastfm-library:1.0.2

#Usage

  1. Add the internet permission in your AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" /> 
  2. Add this to the resource file (example strings.xml).

    <string name="api_key">your_api_key</string>

    If you want to use methods that require authorization add your API secret to the resource file (example strings.xml).

    <string name="secret">your_api_secret</string>
  3. Initialize library on startup using the following method. Call it inside onCreate method of your Application class.

    public class TestApplication extends Application {
    
     @Override
     public void onCreate() {
         super.onCreate();
         //Initialize here.
         Lfm.initializeWithSecret(this);
         //You can initialize without secret,but remember that you cannot use methods that require authentication.
         //Lfm.initialize(this);
    
        }

}


# API Requests
1. Plain request.

```java
LfmRequest lfmRequest = LfmApi.user().getInfo();
 ```
2. Request with parameters.

```java
 LfmParameters params = new LfmParameters();
 params.put("artist","The artist name");
 params.put("track","The track name");
     
 LfmRequest request = LfmApi.track().getInfo(params);
  1. Track scrobble.

    Remember : This method requires authentication. It means that you should use API secret when initializing library at the beginning.

    ScrobbleParameters params = new ScrobbleParameters();
    params.put("track","track1","track2","track3");
    params.put("artist","artist1","artist2","artist3");
         
    String timestamp = String.valueOf(System.currentTimeMillis()/1000);
    params.put("timestamp",timestamp,timestamp,timestamp);
         
    LfmRequest trackScrobble = LfmApi.track().scrobble(params);

Requests Sending

 request.executeWithListener(new LfmRequest.LfmRequestListener() {
    @Override
    public void onComplete(JSONObject response) {
         //Called if there were no errors
    }

    @Override
    public void onError(LfmError error) {
        //Called immediately if there was API error, or  if there was an HTTP error
    }
});

User Authorization

Remember : Use Lfm.initializeWithSecret(Context context); method when initializing library at the beginning if you want to use user authorization .

Lfm.login("username", "password", new Lfm.LfmCallback<Session>() {
    @Override
    public void onResult(Session result) {
        // User passed Authorization      
    }

    @Override
    public void onError(LfmError error) {
        // User didn't pass Authorization
    }
});

lastfm-lib's People

Contributors

arthur-ghazaryan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.