music_explorer 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +89 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/music_explorer +5 -0
- data/bin/setup +8 -0
- data/changelog.md +0 -0
- data/db/students.sqlite +0 -0
- data/lib/music_explorer/api.rb +83 -0
- data/lib/music_explorer/artist.rb +35 -0
- data/lib/music_explorer/cli.rb +169 -0
- data/lib/music_explorer/version.rb +3 -0
- data/lib/music_explorer.rb +13 -0
- data/lib/test/cli/version.rb +5 -0
- data/lib/test/cli.rb +8 -0
- data/music_explorer.code-workspace +7 -0
- data/music_explorer.gemspec +39 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5ac364f1e6e649b8cf14f2d636c5fe17aced3f7685330becd06724c241f888ea
|
4
|
+
data.tar.gz: 4d42c1d9b91d1a474adfe01e2048e6cf775f18f3a3bffdd6d6668c2fe5e5ad58
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6fa6508261c7450b91c886745796ccd50386a3f6768a92762da7ab0137a4521f2a22138f7d8d309bdbb28e7977feff37a7eaee88262d92065303541c45031356
|
7
|
+
data.tar.gz: 18deeeb5614e75e00edaf6ae0cecb5b30eec0171f964ba077c20bfa60667e6df58a0c6ad1b61394fed68fe681ac3a924680ec28bfcd7053921622b317bf05147
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at wkdewey@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
MusicExplorer (0.0.1)
|
5
|
+
dotenv (~> 2.7.5)
|
6
|
+
httparty (~> 0.17.3)
|
7
|
+
rspotify (~> 2.8.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.5.2)
|
13
|
+
public_suffix (>= 2.0.2, < 4.0)
|
14
|
+
coderay (1.1.3)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
domain_name (0.5.20190701)
|
17
|
+
unf (>= 0.0.5, < 1.0.0)
|
18
|
+
dotenv (2.7.6)
|
19
|
+
faraday (1.0.1)
|
20
|
+
multipart-post (>= 1.2, < 3)
|
21
|
+
hashie (4.1.0)
|
22
|
+
http-cookie (1.0.3)
|
23
|
+
domain_name (~> 0.5)
|
24
|
+
httparty (0.17.3)
|
25
|
+
mime-types (~> 3.0)
|
26
|
+
multi_xml (>= 0.5.2)
|
27
|
+
jwt (2.2.1)
|
28
|
+
method_source (1.0.0)
|
29
|
+
mime-types (3.3.1)
|
30
|
+
mime-types-data (~> 3.2015)
|
31
|
+
mime-types-data (3.2020.0512)
|
32
|
+
multi_json (1.15.0)
|
33
|
+
multi_xml (0.6.0)
|
34
|
+
multipart-post (2.1.1)
|
35
|
+
netrc (0.11.0)
|
36
|
+
oauth2 (1.4.4)
|
37
|
+
faraday (>= 0.8, < 2.0)
|
38
|
+
jwt (>= 1.0, < 3.0)
|
39
|
+
multi_json (~> 1.3)
|
40
|
+
multi_xml (~> 0.5)
|
41
|
+
rack (>= 1.2, < 3)
|
42
|
+
omniauth (1.9.1)
|
43
|
+
hashie (>= 3.4.6)
|
44
|
+
rack (>= 1.6.2, < 3)
|
45
|
+
omniauth-oauth2 (1.5.0)
|
46
|
+
oauth2 (~> 1.1)
|
47
|
+
omniauth (~> 1.2)
|
48
|
+
pry (0.13.1)
|
49
|
+
coderay (~> 1.1)
|
50
|
+
method_source (~> 1.0)
|
51
|
+
public_suffix (3.1.1)
|
52
|
+
rack (2.2.3)
|
53
|
+
rake (12.3.3)
|
54
|
+
rest-client (2.0.2)
|
55
|
+
http-cookie (>= 1.0.2, < 2.0)
|
56
|
+
mime-types (>= 1.16, < 4.0)
|
57
|
+
netrc (~> 0.8)
|
58
|
+
rspec (3.9.0)
|
59
|
+
rspec-core (~> 3.9.0)
|
60
|
+
rspec-expectations (~> 3.9.0)
|
61
|
+
rspec-mocks (~> 3.9.0)
|
62
|
+
rspec-core (3.9.2)
|
63
|
+
rspec-support (~> 3.9.3)
|
64
|
+
rspec-expectations (3.9.2)
|
65
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
+
rspec-support (~> 3.9.0)
|
67
|
+
rspec-mocks (3.9.1)
|
68
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
+
rspec-support (~> 3.9.0)
|
70
|
+
rspec-support (3.9.3)
|
71
|
+
rspotify (2.8.0)
|
72
|
+
addressable (~> 2.5.2)
|
73
|
+
omniauth-oauth2 (~> 1.5.0)
|
74
|
+
rest-client (~> 2.0.2)
|
75
|
+
unf (0.1.4)
|
76
|
+
unf_ext
|
77
|
+
unf_ext (0.0.7.7)
|
78
|
+
|
79
|
+
PLATFORMS
|
80
|
+
ruby
|
81
|
+
|
82
|
+
DEPENDENCIES
|
83
|
+
MusicExplorer!
|
84
|
+
pry (~> 0.13.1)
|
85
|
+
rake (~> 12.0)
|
86
|
+
rspec (~> 3.0)
|
87
|
+
|
88
|
+
BUNDLED WITH
|
89
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Your Name
|
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,41 @@
|
|
1
|
+
# Music_Explorer
|
2
|
+
|
3
|
+
This gem enables users to learn more about music artists with data from the Spotify API. Users are prompted to search for an artist. The app returns the first search result from Spotify and allows users to see the artist's top tracks, album releases, genres or related artists. For the latter option, users can choose one of the related artists and view artist details for that artist in turn. Finally, users can review a list of all artists they have browsed. The app makes use of the RSpotify gem for OAuth authentication, HTTParty to retrieve data from the API, and dotenv to store client_id and client_secret. As explained below under Usage, this means that users will need to obtain their own credentials and store them in their own .env file.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'musicexplorer'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install musicexplorer
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
You must obtain a client_id and client_secret from https://developer.spotify.com/dashboard and put them in your .env file. Then follow the instructions on the screen to search the API and choose the options described above. The app will store all artists you search for, and they can be retrieved from the main menu.
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
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.
|
28
|
+
|
29
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wkdewey/Music_Explorer_CLI-Data-Gem-Project. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/wkdewey/Music_Explorer_CLI-Data-Gem-Project/blob/master/CODE_OF_CONDUCT.md).
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
38
|
+
|
39
|
+
## Code of Conduct
|
40
|
+
|
41
|
+
Everyone interacting in the Music_Explorer project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/wkdewey/Music_Explorer_CLI-Data-Gem-Project/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "test/cli"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/music_explorer
ADDED
data/bin/setup
ADDED
data/changelog.md
ADDED
File without changes
|
data/db/students.sqlite
ADDED
Binary file
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class MusicExplorer::API
|
2
|
+
attr_accessor :artist_query, :artist_data, :token, :id
|
3
|
+
|
4
|
+
@@base_url = "https://api.spotify.com/v1/"
|
5
|
+
|
6
|
+
def initialize(artist_query)
|
7
|
+
#initialize the API with credentials
|
8
|
+
RSpotify.authenticate(ENV['CLIENT_ID'], ENV['CLIENT_SECRET'])
|
9
|
+
#get the token necessary to look up info from API
|
10
|
+
@token = RSpotify.client_token
|
11
|
+
#store artist that will be looked up from API
|
12
|
+
@artist_query = artist_query
|
13
|
+
get_artist_id
|
14
|
+
#methods for authentication with Spotify and setup will go here
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_artist_id
|
18
|
+
#conduct the initial search, get the first result, and return the ID (necessary for other API calls)
|
19
|
+
url = "#{@@base_url}search?q=#{@artist_query}&type=artist"
|
20
|
+
search = retrieve_data_from_url(url)
|
21
|
+
first_result = search["artists"]["items"][0]
|
22
|
+
@id = first_result["id"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def retrieve_artist_data
|
26
|
+
#calls other methods (which interact directly with API) to fill out hash of artist data
|
27
|
+
self.artist_data = {}
|
28
|
+
self.artist_data[:name] = retrieve_name
|
29
|
+
self.artist_data[:genres] = retrieve_genres
|
30
|
+
self.artist_data[:top_tracks] = retrieve_top_tracks
|
31
|
+
self.artist_data[:albums] = retrieve_albums
|
32
|
+
self.artist_data[:related_artists] = retrieve_related_artists
|
33
|
+
self.artist_data
|
34
|
+
end
|
35
|
+
|
36
|
+
def retrieve_data_from_url(url)
|
37
|
+
url = URI.parse(URI.escape(url))
|
38
|
+
HTTParty.get(url,
|
39
|
+
{headers: {"Authorization" => "Bearer #{@token}"}}
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
def return_array_with_names(array)
|
44
|
+
array.map do |item|
|
45
|
+
item["name"]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def retrieve_name
|
50
|
+
#Get name of artist based on search from API
|
51
|
+
#search for the artist
|
52
|
+
url = "#{@@base_url}artists/#{id}"
|
53
|
+
artist = retrieve_data_from_url(url)
|
54
|
+
artist["name"]
|
55
|
+
end
|
56
|
+
|
57
|
+
def retrieve_genres
|
58
|
+
url = "#{@@base_url}artists/#{id}"
|
59
|
+
artist = retrieve_data_from_url(url)
|
60
|
+
artist["genres"]
|
61
|
+
end
|
62
|
+
|
63
|
+
def retrieve_top_tracks
|
64
|
+
#Get top tracks for artists from API in form of arrayxw
|
65
|
+
url = "#{@@base_url}artists/#{id}/top-tracks?country=US"
|
66
|
+
top_tracks = retrieve_data_from_url(url)
|
67
|
+
return_array_with_names(top_tracks["tracks"])
|
68
|
+
end
|
69
|
+
|
70
|
+
def retrieve_albums
|
71
|
+
#Get all of artists's albums from API in form of array
|
72
|
+
url = "#{@@base_url}artists/#{id}/albums?country=US"
|
73
|
+
albums = retrieve_data_from_url(url)
|
74
|
+
return_array_with_names(albums["items"])
|
75
|
+
end
|
76
|
+
|
77
|
+
def retrieve_related_artists
|
78
|
+
#Get related artists from API in form of array
|
79
|
+
url = "#{@@base_url}artists/#{id}/related-artists?country=US"
|
80
|
+
related_artists = retrieve_data_from_url(url)
|
81
|
+
return_array_with_names(related_artists["artists"])
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class MusicExplorer::Artist
|
2
|
+
|
3
|
+
attr_accessor :name, :top_tracks, :albums, :genres, :related_artists
|
4
|
+
|
5
|
+
@@all = []
|
6
|
+
|
7
|
+
def self.create_artist(artist_query)
|
8
|
+
artist_data = lookup_artist(artist_query)
|
9
|
+
self.new(artist_data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.lookup_artist(artist_query)
|
13
|
+
#Calls the API with the user's query, in order to get a hash of artist data
|
14
|
+
|
15
|
+
api = MusicExplorer::API.new(artist_query)
|
16
|
+
api.retrieve_artist_data
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.all
|
20
|
+
@@all
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(artist_data = nil)
|
24
|
+
#creates Artist object from the hash returned from the API
|
25
|
+
if artist_data && artist_data.length > 0
|
26
|
+
@name = artist_data[:name]
|
27
|
+
@genres = artist_data[:genres]
|
28
|
+
@top_tracks = artist_data[:top_tracks]
|
29
|
+
@albums = artist_data[:albums]
|
30
|
+
@related_artists = artist_data[:related_artists]
|
31
|
+
@@all << self
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
class MusicExplorer::CLI
|
2
|
+
|
3
|
+
|
4
|
+
def call
|
5
|
+
#Welcome message, initially called by the executable program
|
6
|
+
puts "Welcome to the Music Explorer!"
|
7
|
+
program_options
|
8
|
+
end
|
9
|
+
|
10
|
+
def program_options
|
11
|
+
while true
|
12
|
+
puts
|
13
|
+
puts "Please select an option (1-3)"
|
14
|
+
puts "1. Search for an artist"
|
15
|
+
puts "2. View all artists you have explored"
|
16
|
+
puts "3. Leave program"
|
17
|
+
puts
|
18
|
+
user_choice = get_numeric_input
|
19
|
+
case user_choice
|
20
|
+
when 1
|
21
|
+
search_artists
|
22
|
+
when 2
|
23
|
+
view_all_artists
|
24
|
+
when 3
|
25
|
+
end_program
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def search_artists(artist_query = nil)
|
31
|
+
if artist_query == nil
|
32
|
+
puts
|
33
|
+
puts "What artist would you like more info about?"
|
34
|
+
puts
|
35
|
+
artist_query = self.get_user_input
|
36
|
+
end
|
37
|
+
artist = MusicExplorer::Artist.create_artist(artist_query)
|
38
|
+
display_artist(artist)
|
39
|
+
artist_options(artist)
|
40
|
+
end
|
41
|
+
|
42
|
+
def display_artist(artist)
|
43
|
+
puts
|
44
|
+
puts "Your search matched #{artist.name}"
|
45
|
+
puts
|
46
|
+
end
|
47
|
+
|
48
|
+
def artist_options(artist)
|
49
|
+
while true
|
50
|
+
puts
|
51
|
+
puts "Please select an option (1-4)"
|
52
|
+
puts "1. Display #{artist.name}'s top tracks"
|
53
|
+
puts "2. Display #{artist.name}'s genres"
|
54
|
+
puts "3. Display albums by #{artist.name}"
|
55
|
+
puts "4. Display artists related to #{artist.name}"
|
56
|
+
puts "5. Go back to main menu"
|
57
|
+
puts
|
58
|
+
case get_numeric_input
|
59
|
+
when 1
|
60
|
+
display_top_tracks(artist)
|
61
|
+
when 2
|
62
|
+
display_genres(artist)
|
63
|
+
when 3
|
64
|
+
display_albums(artist)
|
65
|
+
when 4
|
66
|
+
display_related_artists(artist)
|
67
|
+
when 5
|
68
|
+
program_options
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def display_top_tracks(artist)
|
74
|
+
if artist.top_tracks
|
75
|
+
puts
|
76
|
+
puts "#{artist.name}'s top 10 tracks on Spotify are:"
|
77
|
+
print_numbered_list(artist.top_tracks)
|
78
|
+
puts
|
79
|
+
else
|
80
|
+
puts
|
81
|
+
puts "Top tracks not available for #{artist.name}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def display_genres(artist)
|
86
|
+
if artist.genres
|
87
|
+
puts
|
88
|
+
puts "Spotify classifies #{artist.name} as having the following genres:"
|
89
|
+
print_numbered_list(artist.genres)
|
90
|
+
puts
|
91
|
+
else
|
92
|
+
puts
|
93
|
+
puts "Genres not available for #{artist.name}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def display_albums(artist)
|
98
|
+
if artist.albums
|
99
|
+
puts
|
100
|
+
puts "#{artist.name}'s releases include the following albums (up to 20):"
|
101
|
+
print_numbered_list(artist.albums.uniq)
|
102
|
+
puts
|
103
|
+
else
|
104
|
+
puts
|
105
|
+
puts "Albums not available for #{artist.name}"
|
106
|
+
puts
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def display_related_artists(artist)
|
111
|
+
if artist.related_artists
|
112
|
+
puts
|
113
|
+
puts "Here is a list of artists related to #{artist.name}:"
|
114
|
+
print_numbered_list(artist.related_artists)
|
115
|
+
puts "Would you like to learn more about these artists? (Y/N)"
|
116
|
+
user_choice = get_user_input.capitalize
|
117
|
+
if user_choice[0] == "Y"
|
118
|
+
explore_related_artists(artist.related_artists)
|
119
|
+
end
|
120
|
+
else
|
121
|
+
puts
|
122
|
+
puts "Related artists not available for #{artist.name}"
|
123
|
+
puts
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def explore_related_artists(related_artists)
|
128
|
+
puts
|
129
|
+
puts "Choose one of the above artists by number"
|
130
|
+
user_input = get_numeric_input
|
131
|
+
if user_input >=1 && user_input <= 20
|
132
|
+
puts
|
133
|
+
search_artists(related_artists[user_input - 1])
|
134
|
+
else
|
135
|
+
puts "Number out of range (1-20)"
|
136
|
+
explore_related_artists(related_artists)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def view_all_artists
|
141
|
+
puts
|
142
|
+
puts "Artists explored in this session:"
|
143
|
+
MusicExplorer::Artist.all.sort_by {|artist| artist.name}.each_with_index do |artist, index|
|
144
|
+
puts "#{artist.name}"
|
145
|
+
end
|
146
|
+
puts
|
147
|
+
end
|
148
|
+
|
149
|
+
def get_user_input
|
150
|
+
gets.strip
|
151
|
+
end
|
152
|
+
|
153
|
+
def get_numeric_input
|
154
|
+
get_user_input.to_i
|
155
|
+
end
|
156
|
+
|
157
|
+
def print_numbered_list(array)
|
158
|
+
array.each_with_index do |item, index|
|
159
|
+
puts "#{index + 1}. #{item}"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def end_program
|
164
|
+
puts "Goodbye!"
|
165
|
+
exit
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'httparty'
|
3
|
+
require 'dotenv/load'
|
4
|
+
require 'rspotify'
|
5
|
+
|
6
|
+
require_relative "music_explorer/version"
|
7
|
+
require_relative "music_explorer/cli"
|
8
|
+
require_relative "music_explorer/api"
|
9
|
+
require_relative "music_explorer/artist"
|
10
|
+
|
11
|
+
|
12
|
+
module MusicExplorer
|
13
|
+
end
|
data/lib/test/cli.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'music_explorer/version.rb'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "music_explorer"
|
8
|
+
spec.version = MusicExplorer::VERSION
|
9
|
+
spec.authors = ["William Dewey"]
|
10
|
+
spec.email = ["wkdewey@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{This gem uses the Spotify API to explore music artists.}
|
13
|
+
spec.description = %q{Users can search for an artist on Spotify and discover their top tracks, albums, and similar artists.}
|
14
|
+
spec.homepage = "https://github.com/wkdewey/Music_Explorer_CLI-Data-Gem-Project"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
17
|
+
|
18
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
19
|
+
|
20
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
21
|
+
spec.metadata["source_code_uri"] = "https://github.com/wkdewey/Music_Explorer_CLI-Data-Gem-Project"
|
22
|
+
spec.metadata["changelog_uri"] = "https://github.com/wkdewey/Music_Explorer_CLI-Data-Gem-Project"
|
23
|
+
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_development_dependency "pry", "~> 0.13.1"
|
36
|
+
spec.add_dependency "httparty", "~> 0.17.3"
|
37
|
+
spec.add_dependency "dotenv", "~> 2.7.5"
|
38
|
+
spec.add_dependency "rspotify", "~> 2.8.0"
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: music_explorer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- William Dewey
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '12.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.13.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.13.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.17.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.17.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.7.5
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.7.5
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspotify
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.8.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.8.0
|
97
|
+
description: Users can search for an artist on Spotify and discover their top tracks,
|
98
|
+
albums, and similar artists.
|
99
|
+
email:
|
100
|
+
- wkdewey@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CODE_OF_CONDUCT.md
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/music_explorer
|
116
|
+
- bin/setup
|
117
|
+
- changelog.md
|
118
|
+
- db/students.sqlite
|
119
|
+
- lib/music_explorer.rb
|
120
|
+
- lib/music_explorer/api.rb
|
121
|
+
- lib/music_explorer/artist.rb
|
122
|
+
- lib/music_explorer/cli.rb
|
123
|
+
- lib/music_explorer/version.rb
|
124
|
+
- lib/test/cli.rb
|
125
|
+
- lib/test/cli/version.rb
|
126
|
+
- music_explorer.code-workspace
|
127
|
+
- music_explorer.gemspec
|
128
|
+
homepage: https://github.com/wkdewey/Music_Explorer_CLI-Data-Gem-Project
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata:
|
132
|
+
allowed_push_host: https://rubygems.org
|
133
|
+
homepage_uri: https://github.com/wkdewey/Music_Explorer_CLI-Data-Gem-Project
|
134
|
+
source_code_uri: https://github.com/wkdewey/Music_Explorer_CLI-Data-Gem-Project
|
135
|
+
changelog_uri: https://github.com/wkdewey/Music_Explorer_CLI-Data-Gem-Project
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 2.3.0
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubygems_version: 3.1.5
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: This gem uses the Spotify API to explore music artists.
|
155
|
+
test_files: []
|