class Tidal::ClientV1

Constants

BASE_URL
TOKEN_URL

Attributes

access_token[R]

Public Class Methods

new(client_id, client_secret) click to toggle source

Initialize the Tidal client

@param client_id [String] The client ID for the Tidal API @param client_secret [String] The client secret for the Tidal API

# File lib/tidal/client_v1.rb, line 15
def initialize(client_id, client_secret)
  @client_id = client_id
  @client_secret = client_secret
  @client = OAuth2::Client.new(@client_id, @client_secret, site: BASE_URL, token_url: TOKEN_URL)
  @access_token = @client.client_credentials.get_token.token
end

Public Instance Methods

get_album_items(album_id, country_code, offset = nil, limit = nil) click to toggle source

Get album items

@param album_id [String] The album ID @param country_code [String] The country code @param offset [Integer, nil] The offset for pagination @param limit [Integer, nil] The limit for pagination @return [Array] The list of album items

# File lib/tidal/client_v1.rb, line 57
def get_album_items(album_id, country_code, offset = nil, limit = nil)
  uri = URI("#{BASE_URL}/albums/#{album_id}/items")
  params = { countryCode: country_code }
  params[:offset] = offset if offset
  params[:limit] = limit if limit
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_albums_by_artist(artist_id, country_code, offset = nil, limit = nil) click to toggle source

Get albums by artist

@param artist_id [String] The artist ID @param country_code [String] The country code @param offset [Integer, nil] The offset for pagination @param limit [Integer, nil] The limit for pagination @return [Array] The list of albums by the artist

# File lib/tidal/client_v1.rb, line 107
def get_albums_by_artist(artist_id, country_code, offset = nil, limit = nil)
  uri = URI("#{BASE_URL}/artists/#{artist_id}/albums")
  params = { countryCode: country_code }
  params[:offset] = offset if offset
  params[:limit] = limit if limit
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_albums_by_barcode_id(barcode_id, country_code) click to toggle source

Get albums by barcode ID

@param barcode_id [String] The barcode ID @param country_code [String] The country code @return [Array] The list of albums

# File lib/tidal/client_v1.rb, line 27
def get_albums_by_barcode_id(barcode_id, country_code)
  uri = URI("#{BASE_URL}/albums/byBarcodeId")
  params = { barcodeId: barcode_id, countryCode: country_code }
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_multiple_albums(ids, country_code) click to toggle source

Get multiple albums

@param ids [Array] The array of album IDs @param country_code [String] The country code @return [Array] The list of albums

# File lib/tidal/client_v1.rb, line 41
def get_multiple_albums(ids, country_code)
  uri = URI("#{BASE_URL}/albums/byIds")
  params = { ids: ids.join(','), countryCode: country_code }
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_multiple_artists(ids, country_code) click to toggle source

Get multiple artists

@param ids [Array] The array of artist IDs @param country_code [String] The country code @return [Array] The list of artists

# File lib/tidal/client_v1.rb, line 123
def get_multiple_artists(ids, country_code)
  uri = URI("#{BASE_URL}/artists")
  params = { ids: ids.join(','), countryCode: country_code }
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_multiple_tracks(ids, country_code) click to toggle source

Get multiple tracks

@param ids [Array] The array of track IDs @param country_code [String] The country code @return [Array] The list of tracks

# File lib/tidal/client_v1.rb, line 189
def get_multiple_tracks(ids, country_code)
  uri = URI("#{BASE_URL}/tracks")
  params = { ids: ids.join(','), countryCode: country_code }
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_multiple_videos(ids, country_code) click to toggle source

Get multiple videos

@param ids [Array] The array of video IDs @param country_code [String] The country code @return [Array] The list of videos

# File lib/tidal/client_v1.rb, line 253
def get_multiple_videos(ids, country_code)
  uri = URI("#{BASE_URL}/videos")
  params = { ids: ids.join(','), countryCode: country_code }
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_similar_albums(album_id, country_code, offset = nil, limit = nil) click to toggle source

Get similar albums

@param album_id [String] The album ID @param country_code [String] The country code @param offset [Integer, nil] The offset for pagination @param limit [Integer, nil] The limit for pagination @return [Array] The list of similar albums

# File lib/tidal/client_v1.rb, line 75
def get_similar_albums(album_id, country_code, offset = nil, limit = nil)
  uri = URI("#{BASE_URL}/albums/#{album_id}/similar")
  params = { countryCode: country_code }
  params[:offset] = offset if offset
  params[:limit] = limit if limit
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_similar_artists(artist_id, country_code, offset = nil, limit = nil) click to toggle source

Get similar artists

@param artist_id [String] The artist ID @param country_code [String] The country code @param offset [Integer, nil] The offset for pagination @param limit [Integer, nil] The limit for pagination @return [Array] The list of similar artists

# File lib/tidal/client_v1.rb, line 139
def get_similar_artists(artist_id, country_code, offset = nil, limit = nil)
  uri = URI("#{BASE_URL}/artists/#{artist_id}/similar")
  params = { countryCode: country_code }
  params[:offset] = offset if offset
  params[:limit] = limit if limit
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_similar_tracks(track_id, country_code, offset = nil, limit = nil) click to toggle source

Get similar tracks

@param track_id [String] The track ID @param country_code [String] The country code @param offset [Integer, nil] The offset for pagination @param limit [Integer, nil] The limit for pagination @return [Array] The list of similar tracks

# File lib/tidal/client_v1.rb, line 237
def get_similar_tracks(track_id, country_code, offset = nil, limit = nil)
  uri = URI("#{BASE_URL}/tracks/#{track_id}/similar")
  params = { countryCode: country_code }
  params[:offset] = offset if offset
  params[:limit] = limit if limit
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_single_album(album_id, country_code) click to toggle source

Get a single album

@param album_id [String] The album ID @param country_code [String] The country code @return [Hash] The album data

# File lib/tidal/client_v1.rb, line 91
def get_single_album(album_id, country_code)
  uri = URI("#{BASE_URL}/albums/#{album_id}")
  params = { countryCode: country_code }
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_single_artist(artist_id, country_code) click to toggle source

Get a single artist

@param artist_id [String] The artist ID @param country_code [String] The country code @return [Hash] The artist data

# File lib/tidal/client_v1.rb, line 155
def get_single_artist(artist_id, country_code)
  uri = URI("#{BASE_URL}/artists/#{artist_id}")
  params = { countryCode: country_code }
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_single_track(artist_id, country_code) click to toggle source

Get a single track

@param artist_id [String] The artist ID @param country_code [String] The country code @return [Hash] The track data

# File lib/tidal/client_v1.rb, line 221
def get_single_track(artist_id, country_code)
  uri = URI("#{BASE_URL}/tracks/#{artist_id}")
  params = { countryCode: country_code }
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_single_video(video_id, country_code) click to toggle source

Get a single video

@param video_id [String] The video ID @param country_code [String] The country code @return [Hash] The video data

# File lib/tidal/client_v1.rb, line 267
def get_single_video(video_id, country_code)
  uri = URI("#{BASE_URL}/videos/#{video_id}")
  params = { countryCode: country_code }
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_tracks_by_artist(artist_id, country_code, collapse_by = nil, offset = nil, limit = nil) click to toggle source

Get tracks by artist

@param artist_id [String] The artist ID @param country_code [String] The country code @param collapse_by [String, nil] The collapse criteria @param offset [Integer, nil] The offset for pagination @param limit [Integer, nil] The limit for pagination @return [Array] The list of tracks by the artist

# File lib/tidal/client_v1.rb, line 172
def get_tracks_by_artist(artist_id, country_code, collapse_by = nil, offset = nil, limit = nil)
  uri = URI("#{BASE_URL}/artists/#{artist_id}/tracks")
  params = { countryCode: country_code }
  params[:collapseBy] = collapse_by if collapse_by
  params[:offset] = offset if offset
  params[:limit] = limit if limit
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end
get_tracks_by_isrc(isrc, country_code, offset = nil, limit = nil) click to toggle source

Get tracks by ISRC

@param isrc [String] The ISRC code @param country_code [String] The country code @param offset [Integer, nil] The offset for pagination @param limit [Integer, nil] The limit for pagination @return [Array] The list of tracks by ISRC

# File lib/tidal/client_v1.rb, line 205
def get_tracks_by_isrc(isrc, country_code, offset = nil, limit = nil)
  uri = URI("#{BASE_URL}/tracks/byIsrc")
  params = { isrc: isrc, countryCode: country_code }
  params[:offset] = offset if offset
  params[:limit] = limit if limit
  uri.query = URI.encode_www_form(params)

  response = @client.request(:get, uri.to_s, headers: default_headers)
  JSON.parse(response.body)
end