class SoundDrop::Client

Constants

LOG

Attributes

client[R]

Setup #

Public Class Methods

new(opts={}) click to toggle source
# File lib/sounddrop/client.rb, line 11
def initialize(opts={})
  @CLIENT_ID     = opts.fetch(:client_id)
  @CLIENT_SECRET = opts.fetch(:client_secret)
  @USERNAME      = opts.fetch(:username, nil)
  @PASSWORD      = opts.fetch(:password, nil)
  @client        = get_client
end

Public Instance Methods

get_drop(url) click to toggle source

Returns a Drop object that contains useful track information.

# File lib/sounddrop/client.rb, line 49
def get_drop(url)
  sc_track = client.get('/resolve', url: url)
  SoundDrop::Drop.new(client: client, track: sc_track)
end

Private Instance Methods

get_client() click to toggle source

Defines a Soundcloud client object

# File lib/sounddrop/client.rb, line 34
def get_client
  init_opts = {
    client_id:     @CLIENT_ID,
    client_secret: @CLIENT_SECRET
  }

  if username? and password?
    init_opts[:username] = @USERNAME
    init_opts[:password] = @PASSWORD
  end

  Soundcloud.new(init_opts)
end
password?() click to toggle source

Did the user specify a password?

# File lib/sounddrop/client.rb, line 29
def password?
  @PASSWORD.nil?
end
username?() click to toggle source

Did the user specify a username?

# File lib/sounddrop/client.rb, line 24
def username?
  @USERNAME.nil?
end