tidal 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 758385dc62e185fd969dc7c3050ad47d24c02ce196ea3d0f79ecfb415aab439a
4
+ data.tar.gz: 1c3284618e5d5e90b06947b1d48b0011c68cd23fa2ec14c3860ede396b6ec3e9
5
+ SHA512:
6
+ metadata.gz: 53f6804a66f35ccd446295a25b26e80138b560c5e46110259d8d4da5357329713a6228635455bbac9c95b64db5db7177c2f4a2556b094d8ec33167020e60641b
7
+ data.tar.gz: 8b3d7f6c794e1ad9abe988c538232905df5210b4286b46f7d3dd3d999d6de4eff890cd18a9f5f82a6f4de0251943e62364fc2b92f76c974bd8b6973b7aa3be7c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Fabrice Renard
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Tidal
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tidal`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tidal.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,201 @@
1
+ require 'oauth2'
2
+ require 'uri'
3
+
4
+ module Tidal
5
+ class ClientV1
6
+ BASE_URL = 'https://openapi.tidal.com/'.freeze
7
+ TOKEN_URL = 'https://auth.tidal.com/v1/oauth2/token'.freeze
8
+
9
+ attr_reader :access_token
10
+
11
+ def initialize(client_id, client_secret)
12
+ @client_id = client_id
13
+ @client_secret = client_secret
14
+ @client = OAuth2::Client.new(@client_id, @client_secret, site: BASE_URL, token_url: TOKEN_URL)
15
+ @access_token = @client.client_credentials.get_token.token
16
+ end
17
+
18
+ def get_albums_by_barcode_id(barcode_id, country_code)
19
+ uri = URI("#{BASE_URL}/albums/byBarcodeId")
20
+ params = { barcodeId: barcode_id, countryCode: country_code }
21
+ uri.query = URI.encode_www_form(params)
22
+
23
+ response = @client.request(:get, uri.to_s, headers: default_headers)
24
+ JSON.parse(response.body)
25
+ end
26
+
27
+ def get_multiple_albums(ids, country_code)
28
+ uri = URI("#{BASE_URL}/albums/byIds")
29
+ params = { ids: ids.join(','), countryCode: country_code }
30
+ uri.query = URI.encode_www_form(params)
31
+
32
+ response = @client.request(:get, uri.to_s, headers: default_headers)
33
+ JSON.parse(response.body)
34
+ end
35
+
36
+
37
+ def get_album_items(album_id, country_code, offset = nil, limit = nil)
38
+ uri = URI("#{BASE_URL}/albums/#{album_id}/items")
39
+ params = { countryCode: country_code }
40
+ params[:offset] = offset if offset
41
+ params[:limit] = limit if limit
42
+ uri.query = URI.encode_www_form(params)
43
+
44
+ response = @client.request(:get, uri.to_s, headers: default_headers)
45
+ JSON.parse(response.body)
46
+ end
47
+
48
+ def get_similar_albums(album_id, country_code, offset = nil, limit = nil)
49
+ uri = URI("#{BASE_URL}/albums/#{album_id}/similar")
50
+ params = { countryCode: country_code }
51
+ params[:offset] = offset if offset
52
+ params[:limit] = limit if limit
53
+ uri.query = URI.encode_www_form(params)
54
+
55
+ response = @client.request(:get, uri.to_s, headers: default_headers)
56
+ JSON.parse(response.body)
57
+ end
58
+
59
+ def get_single_album(album_id, country_code)
60
+ uri = URI("#{BASE_URL}/albums/#{album_id}")
61
+ params = { countryCode: country_code }
62
+ uri.query = URI.encode_www_form(params)
63
+
64
+ response = @client.request(:get, uri.to_s, headers: default_headers)
65
+ JSON.parse(response.body)
66
+ end
67
+
68
+ def get_albums_by_artist(artist_id, country_code, offset = nil, limit = nil)
69
+ uri = URI("#{BASE_URL}/artists/#{artist_id}/albums")
70
+ params = { countryCode: country_code }
71
+ params[:offset] = offset if offset
72
+ params[:limit] = limit if limit
73
+ uri.query = URI.encode_www_form(params)
74
+
75
+ response = @client.request(:get, uri.to_s, headers: default_headers)
76
+ JSON.parse(response.body)
77
+ end
78
+
79
+ def get_multiple_artists(ids, country_code)
80
+ uri = URI("#{BASE_URL}/artists")
81
+ params = { ids: ids.join(','), countryCode: country_code }
82
+ uri.query = URI.encode_www_form(params)
83
+
84
+ response = @client.request(:get, uri.to_s, headers: default_headers)
85
+ JSON.parse(response.body)
86
+ end
87
+
88
+ def get_similar_artists(artist_id, country_code, offset = nil, limit = nil)
89
+ uri = URI("#{BASE_URL}/artists/#{artist_id}/similar")
90
+ params = { countryCode: country_code }
91
+ params[:offset] = offset if offset
92
+ params[:limit] = limit if limit
93
+ uri.query = URI.encode_www_form(params)
94
+
95
+ response = @client.request(:get, uri.to_s, headers: default_headers)
96
+ JSON.parse(response.body)
97
+ end
98
+
99
+ def get_single_artist(artist_id, country_code)
100
+ uri = URI("#{BASE_URL}/artists/#{artist_id}")
101
+ params = { countryCode: country_code }
102
+ uri.query = URI.encode_www_form(params)
103
+
104
+ response = @client.request(:get, uri.to_s, headers: default_headers)
105
+ JSON.parse(response.body)
106
+ end
107
+
108
+ def get_tracks_by_artist(artist_id, country_code, collapse_by = nil, offset = nil, limit = nil)
109
+ uri = URI("#{BASE_URL}/artists/#{artist_id}/tracks")
110
+ params = { countryCode: country_code }
111
+ params[:collapseBy] = collapse_by if collapse_by
112
+ params[:offset] = offset if offset
113
+ params[:limit] = limit if limit
114
+ uri.query = URI.encode_www_form(params)
115
+
116
+ response = @client.request(:get, uri.to_s, headers: default_headers)
117
+ JSON.parse(response.body)
118
+ end
119
+
120
+ def get_multiple_tracks(ids, country_code)
121
+ uri = URI("#{BASE_URL}/tracks")
122
+ params = { ids: ids.join(','), countryCode: country_code }
123
+ uri.query = URI.encode_www_form(params)
124
+
125
+ response = @client.request(:get, uri.to_s, headers: default_headers)
126
+ JSON.parse(response.body)
127
+ end
128
+
129
+ def get_tracks_by_isrc(isrc, country_code, offset = nil, limit = nil)
130
+ uri = URI("#{BASE_URL}/tracks/byIsrc")
131
+ params = { isrc: isrc, countryCode: country_code }
132
+ params[:offset] = offset if offset
133
+ params[:limit] = limit if limit
134
+ uri.query = URI.encode_www_form(params)
135
+
136
+ response = @client.request(:get, uri.to_s, headers: default_headers)
137
+ JSON.parse(response.body)
138
+ end
139
+
140
+ def get_single_track(artist_id, country_code)
141
+ uri = URI("#{BASE_URL}/tracks/#{artist_id}")
142
+ params = { countryCode: country_code }
143
+ uri.query = URI.encode_www_form(params)
144
+
145
+ response = @client.request(:get, uri.to_s, headers: default_headers)
146
+ JSON.parse(response.body)
147
+ end
148
+
149
+ def get_similar_tracks(track_id, country_code, offset = nil, limit = nil)
150
+ uri = URI("#{BASE_URL}/tracks/#{track_id}/similar")
151
+ params = { countryCode: country_code }
152
+ params[:offset] = offset if offset
153
+ params[:limit] = limit if limit
154
+ uri.query = URI.encode_www_form(params)
155
+
156
+ response = @client.request(:get, uri.to_s, headers: default_headers)
157
+ JSON.parse(response.body)
158
+ end
159
+
160
+ def get_multiple_videos(ids, country_code)
161
+ uri = URI("#{BASE_URL}/videos")
162
+ params = { ids: ids.join(','), countryCode: country_code }
163
+ uri.query = URI.encode_www_form(params)
164
+
165
+ response = @client.request(:get, uri.to_s, headers: default_headers)
166
+ JSON.parse(response.body)
167
+ end
168
+
169
+ def get_single_video(video_id, country_code)
170
+ uri = URI("#{BASE_URL}/videos/#{video_id}")
171
+ params = { countryCode: country_code }
172
+ uri.query = URI.encode_www_form(params)
173
+
174
+ response = @client.request(:get, uri.to_s, headers: default_headers)
175
+ JSON.parse(response.body)
176
+ end
177
+
178
+ def get_search(query, country_code, type = nil, popularity = nil, offset = nil, limit = nil)
179
+ uri = URI("#{BASE_URL}/search")
180
+ params = { query: query, countryCode: country_code }
181
+ params[:type] = type if type
182
+ params[:popularity] = popularity if popularity
183
+ params[:offset] = offset if offset
184
+ params[:limit] = limit if limit
185
+ uri.query = URI.encode_www_form(params)
186
+
187
+ response = @client.request(:get, uri.to_s, headers: default_headers)
188
+ JSON.parse(response.body)
189
+ end
190
+
191
+ private
192
+
193
+ def default_headers
194
+ {
195
+ 'accept' => "application/vnd.tidal.v1+json",
196
+ 'Authorization' => "Bearer #{@access_token}",
197
+ 'Content-Type' => "application/vnd.tidal.v1+json",
198
+ }
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tidal
4
+ VERSION = "0.1.0"
5
+ end
data/lib/tidal.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "tidal/client_v1"
4
+ require_relative "tidal/version"
5
+
6
+ module Tidal
7
+ class Error < StandardError; end
8
+ end
data/sig/tidal.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Tidal
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tidal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fabrice Renard
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: uri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.13.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.13.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.10'
55
+ description: This gem provides a Ruby wrapper around the Tidal API, allowing developers
56
+ to easily interact with Tidal's services, including retrieving album and artist
57
+ information, searching for tracks, and more.
58
+ email:
59
+ - fabrice.renard12@outlook.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".rspec"
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/tidal.rb
69
+ - lib/tidal/client_v1.rb
70
+ - lib/tidal/version.rb
71
+ - sig/tidal.rbs
72
+ homepage: https://github.com/fabricerenard12/tidal.rb
73
+ licenses:
74
+ - MIT
75
+ metadata:
76
+ homepage_uri: https://github.com/fabricerenard12/tidal.rb
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 3.0.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.5.9
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: A Ruby wrapper to interact with the Tidal API
96
+ test_files: []