Class: Tidal::ClientV1
- Inherits:
-
Object
- Object
- Tidal::ClientV1
- Defined in:
- lib/tidal/client_v1.rb
Constant Summary collapse
- BASE_URL =
'https://openapi.tidal.com/'.freeze
- TOKEN_URL =
'https://auth.tidal.com/v1/oauth2/token'.freeze
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
Instance Method Summary collapse
-
#get_album_items(album_id, country_code, offset = nil, limit = nil) ⇒ Array
Get album items.
-
#get_albums_by_artist(artist_id, country_code, offset = nil, limit = nil) ⇒ Array
Get albums by artist.
-
#get_albums_by_barcode_id(barcode_id, country_code) ⇒ Array
Get albums by barcode ID.
-
#get_multiple_albums(ids, country_code) ⇒ Array
Get multiple albums.
-
#get_multiple_artists(ids, country_code) ⇒ Array
Get multiple artists.
-
#get_multiple_tracks(ids, country_code) ⇒ Array
Get multiple tracks.
-
#get_multiple_videos(ids, country_code) ⇒ Array
Get multiple videos.
-
#get_search(query, country_code, type = nil, popularity = nil, offset = nil, limit = nil) ⇒ Hash
Search for content.
-
#get_similar_albums(album_id, country_code, offset = nil, limit = nil) ⇒ Array
Get similar albums.
-
#get_similar_artists(artist_id, country_code, offset = nil, limit = nil) ⇒ Array
Get similar artists.
-
#get_similar_tracks(track_id, country_code, offset = nil, limit = nil) ⇒ Array
Get similar tracks.
-
#get_single_album(album_id, country_code) ⇒ Hash
Get a single album.
-
#get_single_artist(artist_id, country_code) ⇒ Hash
Get a single artist.
-
#get_single_track(artist_id, country_code) ⇒ Hash
Get a single track.
-
#get_single_video(video_id, country_code) ⇒ Hash
Get a single video.
-
#get_tracks_by_artist(artist_id, country_code, collapse_by = nil, offset = nil, limit = nil) ⇒ Array
Get tracks by artist.
-
#get_tracks_by_isrc(isrc, country_code, offset = nil, limit = nil) ⇒ Array
Get tracks by ISRC.
-
#initialize(client_id, client_secret) ⇒ ClientV1
constructor
Initialize the Tidal client.
Constructor Details
#initialize(client_id, client_secret) ⇒ ClientV1
Initialize the Tidal client
15 16 17 18 19 20 |
# 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 |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
9 10 11 |
# File 'lib/tidal/client_v1.rb', line 9 def access_token @access_token end |
Instance Method Details
#get_album_items(album_id, country_code, offset = nil, limit = nil) ⇒ Array
Get album items
57 58 59 60 61 62 63 64 65 66 |
# 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) ⇒ Array
Get albums by artist
107 108 109 110 111 112 113 114 115 116 |
# 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) ⇒ Array
Get albums by barcode ID
27 28 29 30 31 32 33 34 |
# File 'lib/tidal/client_v1.rb', line 27 def (, country_code) uri = URI("#{BASE_URL}/albums/byBarcodeId") params = { barcodeId: , 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) ⇒ Array
Get multiple albums
41 42 43 44 45 46 47 48 |
# 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) ⇒ Array
Get multiple artists
123 124 125 126 127 128 129 130 |
# 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) ⇒ Array
Get multiple tracks
189 190 191 192 193 194 195 196 |
# 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) ⇒ Array
Get multiple videos
253 254 255 256 257 258 259 260 |
# 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_search(query, country_code, type = nil, popularity = nil, offset = nil, limit = nil) ⇒ Hash
Search for content
285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/tidal/client_v1.rb', line 285 def get_search(query, country_code, type = nil, popularity = nil, offset = nil, limit = nil) uri = URI("#{BASE_URL}/search") params = { query: query, countryCode: country_code } params[:type] = type if type params[:popularity] = popularity if popularity 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_albums(album_id, country_code, offset = nil, limit = nil) ⇒ Array
Get similar albums
75 76 77 78 79 80 81 82 83 84 |
# 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) ⇒ Array
Get similar artists
139 140 141 142 143 144 145 146 147 148 |
# 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) ⇒ Array
Get similar tracks
237 238 239 240 241 242 243 244 245 246 |
# 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) ⇒ Hash
Get a single album
91 92 93 94 95 96 97 98 |
# 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) ⇒ Hash
Get a single artist
155 156 157 158 159 160 161 162 |
# 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) ⇒ Hash
Get a single track
221 222 223 224 225 226 227 228 |
# 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) ⇒ Hash
Get a single video
267 268 269 270 271 272 273 274 |
# 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) ⇒ Array
Get tracks by artist
172 173 174 175 176 177 178 179 180 181 182 |
# 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) ⇒ Array
Get tracks by ISRC
205 206 207 208 209 210 211 212 213 214 |
# 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 |