Class: Tidal::ClientV1

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret) ⇒ ClientV1

Returns a new instance of ClientV1.



11
12
13
14
15
16
# File 'lib/tidal/client_v1.rb', line 11

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_tokenObject (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) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/tidal/client_v1.rb', line 37

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) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/tidal/client_v1.rb', line 68

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) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/tidal/client_v1.rb', line 18

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) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/tidal/client_v1.rb', line 27

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) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/tidal/client_v1.rb', line 79

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) ⇒ Object



120
121
122
123
124
125
126
127
# File 'lib/tidal/client_v1.rb', line 120

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) ⇒ Object



160
161
162
163
164
165
166
167
# File 'lib/tidal/client_v1.rb', line 160

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) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/tidal/client_v1.rb', line 178

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) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/tidal/client_v1.rb', line 48

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) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/tidal/client_v1.rb', line 88

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) ⇒ Object



149
150
151
152
153
154
155
156
157
158
# File 'lib/tidal/client_v1.rb', line 149

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) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/tidal/client_v1.rb', line 59

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) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/tidal/client_v1.rb', line 99

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) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/tidal/client_v1.rb', line 140

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) ⇒ Object



169
170
171
172
173
174
175
176
# File 'lib/tidal/client_v1.rb', line 169

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) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/tidal/client_v1.rb', line 108

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) ⇒ Object



129
130
131
132
133
134
135
136
137
138
# File 'lib/tidal/client_v1.rb', line 129

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