spotify-charts 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +71 -0
- data/lib/spotify/charts.rb +40 -0
- data/lib/spotify/charts/client.rb +19 -0
- data/lib/spotify/charts/track.rb +19 -0
- data/lib/spotify/charts/track_parser.rb +29 -0
- data/lib/spotify/charts/version.rb +5 -0
- data/spec/lib/spotify/charts/client_spec.rb +29 -0
- data/spec/lib/spotify/charts/track_parser_spec.rb +86 -0
- data/spec/lib/spotify/charts/track_spec.rb +64 -0
- data/spec/lib/spotify/charts_spec.rb +168 -0
- data/spec/spec_helper.rb +11 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ebcb11a5d72b86567c8e0bd5bfdfe286e9ab44f
|
4
|
+
data.tar.gz: fa021838225282fe931e0e8937e522db344b30bc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e1ae5490d5de419000109b25530598232a9e081abf2f122c658bb9fea56f92cd1b98b901cb957971ed2160858fb1d5bb40beab25be71954b30a4a661561296fc
|
7
|
+
data.tar.gz: cc2a0840720b6df50762b62a86f9916ec2623c2d7272f0e8648d5c11f8304ce1dd6036f6a7603ca029509c5f875f14ed1bc934713f7bec9ca0e88bf5e2b0193a
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Falk Koeppe
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Spotify::Charts
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/spotify-charts)
|
4
|
+
[](https://codeclimate.com/github/murphyslaw/spotify-charts)
|
5
|
+
[](https://gemnasium.com/murphyslaw/spotify-charts)
|
6
|
+
[](https://travis-ci.org/murphyslaw/spotify-charts)
|
7
|
+
|
8
|
+
A Ruby wrapper for the public [Spotify Charts API](http://charts.spotify.com/) to retrieve the
|
9
|
+
top 50 shared or streamed tracks on Spotify.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'spotify-charts'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install spotify-charts
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Retrieve **Available Countries**
|
28
|
+
|
29
|
+
```
|
30
|
+
Spotify::Charts.available_countries
|
31
|
+
```
|
32
|
+
|
33
|
+
Retrieve **Available Dates** for a given country. The country needs to be in the format returned
|
34
|
+
by `available_countries` method.
|
35
|
+
|
36
|
+
```
|
37
|
+
Spotify::Charts.available_dates(country)
|
38
|
+
```
|
39
|
+
|
40
|
+
Retrieve **Most Shared** tracks for a given country and date. The country and date need to be in the
|
41
|
+
format returned by `available_countries` and `availabe_dates` methods.
|
42
|
+
|
43
|
+
```
|
44
|
+
Spotify::Charts.most_shared(country, date)
|
45
|
+
```
|
46
|
+
|
47
|
+
Retrieve **Most Streamed** tracks for a given country and date. The country and date need to be in
|
48
|
+
the format returned by `available_countries` and `availabe_dates` methods.
|
49
|
+
|
50
|
+
```
|
51
|
+
Spotify::Charts.most_streamed(country, date)
|
52
|
+
```
|
53
|
+
|
54
|
+
## Testing
|
55
|
+
|
56
|
+
The default `rake` task is configured to run all tests.
|
57
|
+
|
58
|
+
```
|
59
|
+
rake
|
60
|
+
```
|
61
|
+
|
62
|
+
`ZenTest` is used for continous testing. Run `autotest` to start.
|
63
|
+
`simplecov` is used for test coverage. Run `open coverage/index.html` to open the results.
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
1. Fork it (https://github.com/murphyslaw/spotify-charts/fork)
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spotify/charts/version'
|
2
|
+
require 'spotify/charts/client'
|
3
|
+
require 'spotify/charts/track'
|
4
|
+
require 'spotify/charts/track_parser'
|
5
|
+
|
6
|
+
module Spotify
|
7
|
+
module Charts
|
8
|
+
class << self
|
9
|
+
def available_countries
|
10
|
+
client.request('/most_shared/')
|
11
|
+
end
|
12
|
+
|
13
|
+
def available_dates(country)
|
14
|
+
client.request("/most_shared/#{country}/")
|
15
|
+
end
|
16
|
+
|
17
|
+
def most_shared(country, date)
|
18
|
+
extract_tracks("/most_shared/#{country}/#{date}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def most_streamed(country, date)
|
22
|
+
extract_tracks("/most_streamed/#{country}/#{date}")
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def client
|
28
|
+
@client ||= Spotify::Charts::Client.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def extract_tracks(endpoint)
|
32
|
+
json = client.request(endpoint)['tracks']
|
33
|
+
|
34
|
+
json.inject([]) do |tracks, item|
|
35
|
+
tracks << TrackParser.new(item).track
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Spotify
|
6
|
+
module Charts
|
7
|
+
class Client
|
8
|
+
def self.base_uri
|
9
|
+
'http://charts.spotify.com/api/charts'
|
10
|
+
end
|
11
|
+
|
12
|
+
def request(endpoint)
|
13
|
+
uri = URI(self.class.base_uri + endpoint)
|
14
|
+
response = Net::HTTP.get(uri)
|
15
|
+
JSON.parse(response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spotify
|
2
|
+
module Charts
|
3
|
+
class Track
|
4
|
+
attr_accessor :date, :country, :track_url, :track_name, :artist_name, :artist_url,
|
5
|
+
:album_name, :album_url, :artwork_url, :num_streams
|
6
|
+
|
7
|
+
def ==(other)
|
8
|
+
other.class == self.class && other.state == state
|
9
|
+
end
|
10
|
+
alias_method :eql?, :==
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def state
|
15
|
+
[date, country, track_url, track_name, artist_name, album_name, artwork_url, num_streams]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Spotify
|
5
|
+
module Charts
|
6
|
+
class TrackParser
|
7
|
+
attr_reader :attributes
|
8
|
+
|
9
|
+
def initialize(attributes)
|
10
|
+
@attributes = attributes
|
11
|
+
end
|
12
|
+
|
13
|
+
def track
|
14
|
+
Track.new.tap do |t|
|
15
|
+
t.date = Date.parse(attributes['date'])
|
16
|
+
t.country = attributes['country']
|
17
|
+
t.track_url = URI(attributes['track_url'])
|
18
|
+
t.track_name = attributes['track_name']
|
19
|
+
t.artist_name = attributes['artist_name']
|
20
|
+
t.artist_url = URI(attributes['artist_url'])
|
21
|
+
t.album_name = attributes['album_name']
|
22
|
+
t.album_url = URI(attributes['album_url'])
|
23
|
+
t.artwork_url = URI(attributes['artwork_url'])
|
24
|
+
t.num_streams = attributes['num_streams']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
require 'spec_helper.rb'
|
5
|
+
|
6
|
+
module Spotify
|
7
|
+
module Charts
|
8
|
+
describe Client do
|
9
|
+
describe '.base_uri' do
|
10
|
+
it 'returns the Spotify Charts API base uri' do
|
11
|
+
expect(subject.class.base_uri).to eq('http://charts.spotify.com/api/charts')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#request' do
|
16
|
+
let(:endpoint) { '/most_shared/global/latest' }
|
17
|
+
|
18
|
+
before do
|
19
|
+
uri = URI(subject.class.base_uri + endpoint)
|
20
|
+
allow(Net::HTTP).to receive(:get).with(uri).once { '{"example":"json"}' }
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'parses JSON response' do
|
24
|
+
expect(subject.request(endpoint)).to eq({'example' => 'json'})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
module Spotify
|
4
|
+
module Charts
|
5
|
+
describe TrackParser do
|
6
|
+
subject { TrackParser.new('example') }
|
7
|
+
|
8
|
+
it 'stores the attributes' do
|
9
|
+
expect(subject.attributes).to eq('example')
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#track' do
|
13
|
+
subject { TrackParser.new(attributes).track }
|
14
|
+
|
15
|
+
let(:attributes) {
|
16
|
+
{
|
17
|
+
'date' => '2013-12-15',
|
18
|
+
'country' => 'global',
|
19
|
+
'track_url' => 'https://play.spotify.com/track/7DyuZtvlGT0z5Xz8peiLN7',
|
20
|
+
'track_name' => 'I See Fire',
|
21
|
+
'artist_name' => 'Howard Shore',
|
22
|
+
'artist_url' => 'https://play.spotify.com/artist/6eUKZXaKkcviH0Ku9w2n3V',
|
23
|
+
'album_name' => 'The Hobbit: The Desolation of Smaug (Original Motion Picture Soundtrack)',
|
24
|
+
'album_url' => 'https://play.spotify.com/album/5kqgALc3cz9P3VclmSmHfr',
|
25
|
+
'artwork_url' => 'http://o.scdn.co/300/be7d523ea35aeb10f561712420d3429f0ec68eec',
|
26
|
+
'num_streams' => 515608,
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
it 'creates a track from JSON data' do
|
31
|
+
expect(subject).to be_a(Track)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'transforms the date' do
|
35
|
+
expect(subject.date).to be_a(Date)
|
36
|
+
expect(subject.date).to eq(Date.parse('2013-12-15'))
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'transforms the country' do
|
40
|
+
expect(subject.country).to be_a(String)
|
41
|
+
expect(subject.country).to eq('global')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'transforms the track url' do
|
45
|
+
expect(subject.track_url).to be_a(URI)
|
46
|
+
expect(subject.track_url).to eq(URI('https://play.spotify.com/track/7DyuZtvlGT0z5Xz8peiLN7'))
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'transforms the track name' do
|
50
|
+
expect(subject.track_name).to be_a(String)
|
51
|
+
expect(subject.track_name).to eq('I See Fire')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'transforms the artist name' do
|
55
|
+
expect(subject.artist_name).to be_a(String)
|
56
|
+
expect(subject.artist_name).to eq('Howard Shore')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'transforms the artist url' do
|
60
|
+
expect(subject.artist_url).to be_a(URI)
|
61
|
+
expect(subject.artist_url).to eq(URI('https://play.spotify.com/artist/6eUKZXaKkcviH0Ku9w2n3V'))
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'transforms the album name' do
|
65
|
+
expect(subject.album_name).to be_a(String)
|
66
|
+
expect(subject.album_name).to eq('The Hobbit: The Desolation of Smaug (Original Motion Picture Soundtrack)')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'transforms the album url' do
|
70
|
+
expect(subject.album_url).to be_a(URI)
|
71
|
+
expect(subject.album_url).to eq(URI('https://play.spotify.com/album/5kqgALc3cz9P3VclmSmHfr'))
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'transforms the artwork url' do
|
75
|
+
expect(subject.artwork_url).to be_a(URI)
|
76
|
+
expect(subject.artwork_url).to eq(URI('http://o.scdn.co/300/be7d523ea35aeb10f561712420d3429f0ec68eec'))
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'transforms the num_streams' do
|
80
|
+
expect(subject.num_streams).to be_a(Integer)
|
81
|
+
expect(subject.num_streams).to eq(515608)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
require 'spec_helper.rb'
|
4
|
+
|
5
|
+
module Spotify
|
6
|
+
module Charts
|
7
|
+
describe Track do
|
8
|
+
subject {
|
9
|
+
Track.new.tap do |t|
|
10
|
+
t.date = Date.parse('2013-12-15')
|
11
|
+
t.country = 'global'
|
12
|
+
t.track_url = URI('https://play.spotify.com/track/7DyuZtvlGT0z5Xz8peiLN7')
|
13
|
+
t.track_name = 'I See Fire'
|
14
|
+
t.artist_name = 'Howard Shore'
|
15
|
+
t.artist_url = URI('https://play.spotify.com/artist/6eUKZXaKkcviH0Ku9w2n3V')
|
16
|
+
t.album_name = 'The Hobbit: The Desolation of Smaug (Original Motion Picture Soundtrack)'
|
17
|
+
t.album_url = URI('https://play.spotify.com/album/5kqgALc3cz9P3VclmSmHfr')
|
18
|
+
t.artwork_url = URI('http://o.scdn.co/300/be7d523ea35aeb10f561712420d3429f0ec68eec')
|
19
|
+
t.num_streams = 515608
|
20
|
+
end
|
21
|
+
}
|
22
|
+
|
23
|
+
it 'initializes the date' do
|
24
|
+
expect(subject.date).to eq(Date.parse('2013-12-15'))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'initializes the country' do
|
28
|
+
expect(subject.country).to eq('global')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'initializes the track url' do
|
32
|
+
expect(subject.track_url).to eq(URI('https://play.spotify.com/track/7DyuZtvlGT0z5Xz8peiLN7'))
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'initializes the track name' do
|
36
|
+
expect(subject.track_name).to eq('I See Fire')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'initializes the artist name' do
|
40
|
+
expect(subject.artist_name).to eq('Howard Shore')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'initializes the artist url' do
|
44
|
+
expect(subject.artist_url).to eq(URI('https://play.spotify.com/artist/6eUKZXaKkcviH0Ku9w2n3V'))
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'initializes the album name' do
|
48
|
+
expect(subject.album_name).to eq('The Hobbit: The Desolation of Smaug (Original Motion Picture Soundtrack)')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'initializes the album url' do
|
52
|
+
expect(subject.album_url).to eq(URI('https://play.spotify.com/album/5kqgALc3cz9P3VclmSmHfr'))
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'initializes the artwork url' do
|
56
|
+
expect(subject.artwork_url).to eq(URI('http://o.scdn.co/300/be7d523ea35aeb10f561712420d3429f0ec68eec'))
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'initializes the number of streams' do
|
60
|
+
expect(subject.num_streams).to eq(515608)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
require 'spec_helper.rb'
|
4
|
+
|
5
|
+
module Spotify
|
6
|
+
describe Charts do
|
7
|
+
subject { Charts }
|
8
|
+
|
9
|
+
describe '.available_countries' do
|
10
|
+
let(:response) {
|
11
|
+
%w(ar at au be bg ch cl co cr cz de dk ec ee es fi fr gb gr gt hk hu ie is it li lt lu lv mx
|
12
|
+
my nl no nz pe pl pt se sg sk sv tr tw us uy global)
|
13
|
+
}
|
14
|
+
|
15
|
+
before do
|
16
|
+
allow_any_instance_of(Charts::Client).to receive(:request)
|
17
|
+
.with('/most_shared/') { response }
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'lists available countries' do
|
21
|
+
expect(subject.available_countries).to be_a(Enumerable)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'includes the "global" country' do
|
25
|
+
expect(subject.available_countries).to include('global')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.available_dates' do
|
30
|
+
let(:response) {
|
31
|
+
%w(latest 2013-12-08 2013-12-01 2013-11-24 2013-11-17 2013-11-10 2013-11-03 2013-10-27
|
32
|
+
2013-10-20 2013-10-13 2013-10-06 2013-09-29 2013-09-22 2013-09-15 2013-09-08 2013-09-01
|
33
|
+
2013-08-25 2013-08-18 2013-08-11 2013-08-04 2013-07-28 2013-07-21 2013-07-14 2013-07-07
|
34
|
+
2013-06-30 2013-06-23 2013-06-16 2013-06-09 2013-06-02 2013-05-26 2013-05-19 2013-05-12
|
35
|
+
2013-05-05 2013-04-28)
|
36
|
+
}
|
37
|
+
|
38
|
+
before do
|
39
|
+
allow_any_instance_of(Charts::Client).to receive(:request)
|
40
|
+
.with('/most_shared/global/') { response }
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'lists available dates' do
|
44
|
+
expect(subject.available_dates('global')).to be_a(Enumerable)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'includes the "latest" date' do
|
48
|
+
expect(subject.available_dates('global')).to include('latest')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '.most shared' do
|
53
|
+
subject { Charts.most_shared('global', 'latest') }
|
54
|
+
|
55
|
+
let(:response) {
|
56
|
+
{
|
57
|
+
'tracks' => [
|
58
|
+
{
|
59
|
+
'date' => '2013-12-15',
|
60
|
+
'country' => 'global',
|
61
|
+
'track_url' => 'https://play.spotify.com/track/7DyuZtvlGT0z5Xz8peiLN7',
|
62
|
+
'track_name' => 'I See Fire',
|
63
|
+
'artist_name' => 'Howard Shore',
|
64
|
+
'artist_url' => 'https://play.spotify.com/artist/6eUKZXaKkcviH0Ku9w2n3V',
|
65
|
+
'album_name' => 'The Hobbit: The Desolation of Smaug (Original Motion Picture Soundtrack)',
|
66
|
+
'album_url' => 'https://play.spotify.com/album/5kqgALc3cz9P3VclmSmHfr',
|
67
|
+
'artwork_url' => 'http://o.scdn.co/300/be7d523ea35aeb10f561712420d3429f0ec68eec',
|
68
|
+
'num_streams' => 515608
|
69
|
+
},
|
70
|
+
{
|
71
|
+
'date' => '2013-12-15',
|
72
|
+
'country' => 'global',
|
73
|
+
'track_url' => 'https://play.spotify.com/track/44GgIVlmRsD1qMWONOWOS3',
|
74
|
+
'track_name' => 'Waiting Game',
|
75
|
+
'artist_name' => 'BANKS',
|
76
|
+
'artist_url' => 'https://play.spotify.com/artist/2xe8IXgCTpwHE3eA9hTs4n',
|
77
|
+
'album_name' => 'LONDON',
|
78
|
+
'album_url' => 'https://play.spotify.com/album/4xG1FKMIQPGYRujVBtMAqm',
|
79
|
+
'artwork_url' => 'http://o.scdn.co/300/4027ebaa3c0ff4161020cb37a546f25929249166',
|
80
|
+
'num_streams' => 182325
|
81
|
+
}
|
82
|
+
]
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
let(:tracks) {
|
87
|
+
response['tracks'].inject([]) do |tracks, item|
|
88
|
+
tracks << Charts::TrackParser.new(item).track
|
89
|
+
end
|
90
|
+
}
|
91
|
+
|
92
|
+
before do
|
93
|
+
allow_any_instance_of(Charts::Client).to receive(:request)
|
94
|
+
.with('/most_shared/global/latest') { response }
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns a list of tracks' do
|
98
|
+
subject.each do |track|
|
99
|
+
expect(track).to be_a(Charts::Track)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'tracks correspond to webservice response' do
|
104
|
+
subject.each_with_index do |track, index|
|
105
|
+
expect(track).to eq(tracks[index])
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '.most streamed' do
|
111
|
+
subject { Charts.most_streamed('global', 'latest') }
|
112
|
+
|
113
|
+
let(:response) {
|
114
|
+
{
|
115
|
+
'tracks' => [
|
116
|
+
{
|
117
|
+
'date' => '2013-12-15',
|
118
|
+
'country' => 'global',
|
119
|
+
'track_url' => 'https://play.spotify.com/track/7DyuZtvlGT0z5Xz8peiLN7',
|
120
|
+
'track_name' => 'I See Fire',
|
121
|
+
'artist_name' => 'Howard Shore',
|
122
|
+
'artist_url' => 'https://play.spotify.com/artist/6eUKZXaKkcviH0Ku9w2n3V',
|
123
|
+
'album_name' => 'The Hobbit: The Desolation of Smaug (Original Motion Picture Soundtrack)',
|
124
|
+
'album_url' => 'https://play.spotify.com/album/5kqgALc3cz9P3VclmSmHfr',
|
125
|
+
'artwork_url' => 'http://o.scdn.co/300/be7d523ea35aeb10f561712420d3429f0ec68eec',
|
126
|
+
'num_streams' => 515608
|
127
|
+
},
|
128
|
+
{
|
129
|
+
'date' => '2013-12-15',
|
130
|
+
'country' => 'global',
|
131
|
+
'track_url' => 'https://play.spotify.com/track/44GgIVlmRsD1qMWONOWOS3',
|
132
|
+
'track_name' => 'Waiting Game',
|
133
|
+
'artist_name' => 'BANKS',
|
134
|
+
'artist_url' => 'https://play.spotify.com/artist/2xe8IXgCTpwHE3eA9hTs4n',
|
135
|
+
'album_name' => 'LONDON',
|
136
|
+
'album_url' => 'https://play.spotify.com/album/4xG1FKMIQPGYRujVBtMAqm',
|
137
|
+
'artwork_url' => 'http://o.scdn.co/300/4027ebaa3c0ff4161020cb37a546f25929249166',
|
138
|
+
'num_streams' => 182325
|
139
|
+
}
|
140
|
+
]
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
let(:tracks) {
|
145
|
+
response['tracks'].inject([]) do |tracks, item|
|
146
|
+
tracks << Charts::TrackParser.new(item).track
|
147
|
+
end
|
148
|
+
}
|
149
|
+
|
150
|
+
before do
|
151
|
+
allow_any_instance_of(Charts::Client).to receive(:request)
|
152
|
+
.with('/most_streamed/global/latest') { response }
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'returns a list of tracks' do
|
156
|
+
subject.each do |track|
|
157
|
+
expect(track).to be_a(Charts::Track)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'tracks correspond to webservice response' do
|
162
|
+
subject.each_with_index do |track, index|
|
163
|
+
expect(track).to eq(tracks[index])
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'spotify/charts'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
config.filter_run :focus
|
10
|
+
config.order = 'random'
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spotify-charts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Falk Koeppe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: autotest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Ruby wrapper for the Spotify Charts API
|
98
|
+
email:
|
99
|
+
- falk.koeppe@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- LICENSE
|
105
|
+
- README.md
|
106
|
+
- lib/spotify/charts.rb
|
107
|
+
- lib/spotify/charts/client.rb
|
108
|
+
- lib/spotify/charts/track.rb
|
109
|
+
- lib/spotify/charts/track_parser.rb
|
110
|
+
- lib/spotify/charts/version.rb
|
111
|
+
- spec/lib/spotify/charts/client_spec.rb
|
112
|
+
- spec/lib/spotify/charts/track_parser_spec.rb
|
113
|
+
- spec/lib/spotify/charts/track_spec.rb
|
114
|
+
- spec/lib/spotify/charts_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
homepage: http://github.com/murphyslaw/spotify-charts
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.2.2
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Ruby wrapper for the Spotify Charts API
|
140
|
+
test_files:
|
141
|
+
- spec/lib/spotify/charts/client_spec.rb
|
142
|
+
- spec/lib/spotify/charts/track_parser_spec.rb
|
143
|
+
- spec/lib/spotify/charts/track_spec.rb
|
144
|
+
- spec/lib/spotify/charts_spec.rb
|
145
|
+
- spec/spec_helper.rb
|