🚀 DAY 4 OF LAUNCH WEEK:Introducing Socket Scanning for OpenVSX Extensions.Learn more →
Socket
Book a DemoInstallSign in
Socket

lastfm-client

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lastfm-client

bundlerRubygems
Version
0.0.3
Version published
Maintainers
1
Created
Source

Last.fm API Ruby Client

LastFM is a Ruby wrapper for Last.fm API.

Installation

Add the following line to your Gemfile and run bundle install:

gem 'lastfm-client', :git => 'http://github.com/pch/lastfm-client.git'

You also need to set up your API key and client name, e.g.:

LastFM.api_key     = "7234655fd87556209fa94ca6f5e7ad0a8b47f394"
LastFM.client_name = "My awesome app"

If you're using Rails, you can add the above lines to an initalizer file, e.g. config/initializers/lastfm.rb

Usage examples

LastFM::Album.get_info(:artist => "Red Hot Chili Peppers", :album => "Mother's Milk")
LastFM::Artist.get_top_fans(:artist => "Gorillaz")
LastFM::Geo.get_events(:location => "Warsaw")
LastFM::User.get_top_albums(:user => "some_user")

Authentication

For some methods Last.fm requires authentication, which is somewhat similar to oAuth:

class SessionsController < ApplicationController
  def new
    redirect_to LastFM.auth_url
  end

  def create
    token = params[:token]
    redirect_to root_path and return if !token || token == ""

    api_session = LastFM::Auth.get_session(:token => token, :api_sig => true)
    api_session = api_session["session"]

    user = User.find_by_username(api_session["name"])
    unless user
      # new user
      user = User.create(:username => api_session["name"])
    end

    session[:user_id]     = user.id
    session[:session_key] = api_session["key"]

    redirect_to root_path
  end
end

FAQs

Package last updated on 05 Mar 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts