Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Scraping sites is one way to get data but many times, companies will expose more
## Instructions
* This is a test-driven lab so just get those specs to pass. Remember to start with the first specs then move to the later ones as they build on each other!
* If you get stuck, refer to the [docs](http://charts.spotify.com/docs), the resources below, and take a look at these urls and try to pattern match:
* [http://charts.spotify.com/api/charts/]( http://charts.spotify.com/api/charts/)
* [http://charts.spotify.com/api/charts/most_shared](http://charts.spotify.com/api/charts/most_shared)
* [http://charts.spotify.com/api/tracks/most_streamed/](http://charts.spotify.com/api/tracks/most_streamed/)
* [http://charts.spotify.com/api/tracks/most_streamed/us/](http://charts.spotify.com/api/tracks/most_streamed/us/)

## Bonus
* Make a command line app that interacts with the API.
Expand Down
8 changes: 2 additions & 6 deletions lib/spotify_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@

class SpotifyChart

attr_reader :base_url

def initialize
@base_url = "?"
end
BASE_URL = "?"

def get_url(preference, region)
# return a string that is the base url + / + preference + / + region + / + latest
# return a string that is the base url + / + preference + / + region + / + weekly + / + latest
end

def get_json(url)
Expand Down
31 changes: 16 additions & 15 deletions spec/spotify_chart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
expect { SpotifyChart.new }.to_not raise_error
end

it "sets a variable 'base_url' as the root url of the Spotify Chart API" do
expect(SpotifyChart.new.base_url).to eq("http://charts.spotify.com/api/charts/")
it "sets a constant 'base_url' as the root url of the Spotify Chart API" do
expect(SpotifyChart::BASE_URL).to eq("http://charts.spotify.com/api/tracks/")
end
end

Expand All @@ -30,27 +30,28 @@
followed by a slash
then the second argument
followed by a slash
ending with 'latest' " do
ending with 'weekly/latest' " do

regex = /http:\/\/charts.spotify.com\/api\/charts\/most_streamed\//
regex_results = [regex.match(gb_most_streamed), /\/latest/.match(gb_most_streamed), /gb/.match(gb_most_streamed)]
regex = /http:\/\/charts.spotify.com\/api\/tracks\/most_streamed\//
regex_results = [regex.match(gb_most_streamed), /\/weekly\/latest/.match(gb_most_streamed), /gb/.match(gb_most_streamed)]
regex_results.each do |match|
expect(match).to_not be_nil
end

regex = /http:\/\/charts.spotify.com\/api\/charts\/most_shared\//
regex_results = [regex.match(us_most_shared), /\/latest/.match(us_most_shared), /us/.match(us_most_shared)]
regex = /http:\/\/charts.spotify.com\/api\/tracks\/most_shared\//
regex_results = [regex.match(us_most_shared), /\/weekly\/latest/.match(us_most_shared), /us/.match(us_most_shared)]
regex_results.each do |match|
expect(match).to_not be_nil
end
end

it "- returns the correct url for querying the API based on most shared/streamed and region abbreviation" do
expect(gb_most_streamed).to eq("http://charts.spotify.com/api/charts/most_streamed/gb/latest")
expect(us_most_shared).to eq("http://charts.spotify.com/api/charts/most_shared/us/latest")
it "- returns the correct url for querying the API based on
most shared/streamed and region abbreviation" do
expect(gb_most_streamed).to eq("http://charts.spotify.com/api/tracks/most_streamed/gb/weekly/latest")
expect(us_most_shared).to eq("http://charts.spotify.com/api/tracks/most_shared/us/weekly/latest")
end

end # get_url
end

describe "#get_json" do
let(:url) { "http://api.openweathermap.org/data/2.5/weather?q=NewYork" }
Expand All @@ -70,18 +71,18 @@

describe "#fetch_track_album_artist" do

let(:json) { JSON.parse( IO.read("spec/support/us_most_streamed.json")) }
let(:us_most_streamed) { JSON.parse( IO.read("spec/support/us_most_streamed.json")) }

it "accepts one argument, a hash object" do
expect { spotify_chart.fetch_track_album_artist(json) }.to_not raise_error
expect { spotify_chart.fetch_track_album_artist(us_most_streamed) }.to_not raise_error
end

it "returns a string" do
expect(spotify_chart.fetch_track_album_artist(json).class).to eq(String)
expect(spotify_chart.fetch_track_album_artist(us_most_streamed).class).to eq(String)
end

it "returns '<song>' by <artist> from the album <album>" do
expect(spotify_chart.fetch_track_album_artist(json)).to eq("'All About That Bass' by Meghan Trainor from the album Title")
expect(spotify_chart.fetch_track_album_artist(us_most_streamed)).to eq("'All About That Bass' by Meghan Trainor from the album Title")
end
end

Expand Down