Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simplespotify

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simplespotify

  • 0.1.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

SimpleSpotify

Gem Version Test status

A lousy and very badly programmed Spotify API Client written in Ruby.

If you'd rather have a proper, working, supported library I do recommend RSpotify.

Installation

Seriously, don't just run gem install simplespotify, it'll ruin your day.

Usage

You've suffered enough registering an app with Spotify and setting up your redirection URIs, why would you want to...?

client = SimpleSpotify::Client.new(client_id, client_secret)
redirect_uri = 'http://your-redirect-uri'

if ARGV[0] == 'login'
  login_url = SimpleSpotify::Authorization.login_uri redirect_uri, client, scope: 'playlist-modify-public user-read-private'
  puts login_url
elsif ARGV[0] == 'code'
  # Copy the `code` param from your browser...
  code = ARGV[1].strip
  auth = SimpleSpotify::Authorization.from_code code, client: client, redirect: redirect_uri

  puts auth.to_h
else
  # now do the same for the `access_token` and `refresh_token`
  token = ARGV[0]
  refresh_token = ARGV[1]
  client.session = SimpleSpotify::Authorization.new access_token: token, refresh_token: refresh_token, client: client

  me = client.me
  puts me.to_h
end

Oh, joy...

API

It's all syntactic sugar, but not the right kind that makes you happy and stuff, but the distasteful one that comes with coffee in an airplane. Seriously, it's not even properly tested!

playlist = client.playlist(some_user_id, some_playlist_id)
if playlist.tracks.total >= 10
  extra = (playlist.tracks.total - 10)
  playlist.remove_tracks positions: (0..extra).to_a
end

playlist.add_tracks('spotify:track:1SWhZ2rIxTPv9UcexFnPSU')
# or
client.playlist_tracks_add(playlist, tracks: '1SWhZ2rIxTPv9UcexFnPSU'})
# or even
client.post "/user/#{_user_}/playlists/#{_playlist_id_}/tracks", {uris: ['spotify:track:1SWhZ2rIxTPv9UcexFnPSU']}
Dealing with refreshing tokens
client.session.on_refresh do |sess|
  # Then token was refreshed on the last call
  cache[:spotify_session] = sess.to_h
end

# And maybe later...
credentials = cache[:spotify_session]
credentials[:client] = client
client.session = SimpleSpotify::Authorization.new(credentials)

FAQs

Package last updated on 11 Oct 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc