notu 1.0.2 → 1.0.3
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 +4 -4
- data/VERSION +1 -1
- data/notu.gemspec +1 -2
- metadata +3 -73
- data/.gitignore +0 -5
- data/.rspec +0 -2
- data/Gemfile +0 -3
- data/Rakefile +0 -10
- data/spec/cassettes/Notu_HtmlDocument/_get/follows_redirects.yml +0 -167
- data/spec/cassettes/Notu_HtmlDocument/_get/raise_a_NetworkError_on_404.yml +0 -71
- data/spec/cassettes/Notu_HtmlDocument/_get/raise_a_ParseError_if_not_a_valid_document.yml +0 -365
- data/spec/cassettes/Notu_HtmlDocument/_get/returns_document_parsed.yml +0 -125
- data/spec/cassettes/Notu_HttpDownload/_get/accepts_HTTPS_URL.yml +0 -125
- data/spec/cassettes/Notu_HttpDownload/_get/follow_redirects.yml +0 -167
- data/spec/cassettes/Notu_HttpDownload/_get/raise_a_NetworkError_if_too_many_redirects.yml +0 -45
- data/spec/cassettes/Notu_HttpDownload/_get/raise_a_NetworkError_on_404.yml +0 -71
- data/spec/cassettes/Notu_HttpDownload/_get/retrives_document_from_given_URL.yml +0 -125
- data/spec/cassettes/Notu_LovedTracks/_each/returns_nil.yml +0 -7013
- data/spec/cassettes/Notu_LovedTracks/_each/returns_some_tracks.yml +0 -14021
- data/spec/cassettes/Notu_LovedTracks/_page_urls/is_correct.yml +0 -14019
- data/spec/cassettes/Notu_LovedTracks/_pages_count/is_correct.yml +0 -7011
- data/spec/cassettes/Notu_MostPlayedTracks/_each/returns_nil.yml +0 -22449
- data/spec/cassettes/Notu_MostPlayedTracks/_each/returns_some_tracks.yml +0 -16108
- data/spec/cassettes/Notu_MostPlayedTracks/_page_urls/is_correct.yml +0 -16473
- data/spec/cassettes/Notu_MostPlayedTracks/_pages_count/is_correct.yml +0 -8529
- data/spec/cassettes/Notu_PlayedTracks/_each/returns_nil.yml +0 -7917
- data/spec/cassettes/Notu_PlayedTracks/_each/returns_some_tracks.yml +0 -15829
- data/spec/cassettes/Notu_PlayedTracks/_page_urls/is_correct.yml +0 -15827
- data/spec/cassettes/Notu_PlayedTracks/_pages_count/is_correct.yml +0 -7915
- data/spec/notu/error_spec.rb +0 -40
- data/spec/notu/html_document_spec.rb +0 -31
- data/spec/notu/http_download_spec.rb +0 -39
- data/spec/notu/library_spec.rb +0 -138
- data/spec/notu/loved_tracks_spec.rb +0 -77
- data/spec/notu/most_played_tracks_spec.rb +0 -101
- data/spec/notu/network_error_spec.rb +0 -15
- data/spec/notu/parse_error_spec.rb +0 -15
- data/spec/notu/played_tracks_spec.rb +0 -62
- data/spec/notu/track_spec.rb +0 -141
- data/spec/spec_helper.rb +0 -10
- data/spec/support/vcr.rb +0 -8
data/spec/notu/error_spec.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Notu::Error do
|
4
|
-
|
5
|
-
let(:error) { Notu::Error.new('BAM!') }
|
6
|
-
let(:original) { StandardError.new('BIM!') }
|
7
|
-
|
8
|
-
describe '#message' do
|
9
|
-
|
10
|
-
it 'is message set at initialization' do
|
11
|
-
expect(error.message).to eq('BAM!')
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'message is squished' do
|
15
|
-
expect(Notu::Error.new(" hello \n world").message).to eq('hello world')
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'default one if blank' do
|
19
|
-
expect(Notu::Error.new(" ").message).to eq('Notu::Error')
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#original' do
|
25
|
-
|
26
|
-
it 'is nil by default' do
|
27
|
-
expect(error.original).to be_nil
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'is exception given at initialization' do
|
31
|
-
expect(Notu::Error.new(original).original).to be(original)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'sets message from original' do
|
35
|
-
expect(Notu::Error.new(original).message).to eq('BIM!')
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Notu::HtmlDocument, :vcr do
|
4
|
-
|
5
|
-
describe '.get' do
|
6
|
-
|
7
|
-
it 'returns document parsed' do
|
8
|
-
document = Notu::HtmlDocument.get('http://alweb.org')
|
9
|
-
expect((document/'title').text).to eq('Alexis Toulotte')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'follows redirects' do
|
13
|
-
document = Notu::HtmlDocument.get('http://www.alweb.org')
|
14
|
-
expect((document/'title').text).to eq('Alexis Toulotte')
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'raise a NetworkError on 404' do
|
18
|
-
expect {
|
19
|
-
Notu::HtmlDocument.get('http://alweb.org/foo')
|
20
|
-
}.to raise_error(Notu::NetworkError, '404 "Not Found"')
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'raise a ParseError if not a valid document' do
|
24
|
-
expect {
|
25
|
-
Notu::HtmlDocument.get('http://alweb.org/avatar')
|
26
|
-
}.to raise_error(Notu::ParseError, 'Invalid HTML document')
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Notu::HttpDownload, :vcr do
|
4
|
-
|
5
|
-
describe '.get' do
|
6
|
-
|
7
|
-
it 'retrives document from given URL' do
|
8
|
-
expect(Notu::HttpDownload.get('http://alweb.org')).to include('<title>Alexis Toulotte</title>')
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'accepts HTTPS URL' do
|
12
|
-
expect(Notu::HttpDownload.get('https://alweb.org')).to include('<title>Alexis Toulotte</title>')
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'follow redirects' do
|
16
|
-
expect(Notu::HttpDownload.get('http://www.alweb.org')).to include('<title>Alexis Toulotte</title>')
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'raise an error if an invalid URL is given' do
|
20
|
-
expect {
|
21
|
-
Notu::HttpDownload.get('ftp://www.alweb.org')
|
22
|
-
}.to raise_error(Notu::NetworkError, 'Invalid URL: "ftp://www.alweb.org"')
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'raise a NetworkError on 404' do
|
26
|
-
expect {
|
27
|
-
Notu::HttpDownload.get('http://alweb.org/foo', max_retries: 0)
|
28
|
-
}.to raise_error(Notu::NetworkError, '404 "Not Found"')
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'raise a NetworkError if too many redirects' do
|
32
|
-
expect {
|
33
|
-
Notu::HttpDownload.get('http://www.alweb.org', max_redirects: 0, max_retries: 0)
|
34
|
-
}.to raise_error(Notu::NetworkError, 'Max redirects has been reached')
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
data/spec/notu/library_spec.rb
DELETED
@@ -1,138 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Notu::Library do
|
4
|
-
|
5
|
-
let(:library) { Notu::Library.new(username: 'alexistoulotte') }
|
6
|
-
|
7
|
-
describe '#host' do
|
8
|
-
|
9
|
-
it 'is "www.last.fm" by default' do
|
10
|
-
expect(library.host).to eq('www.last.fm')
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'can be specified via option' do
|
14
|
-
expect(Notu::Library.new(host: 'www.lastfm.fr', username: 'alex').host).to eq('www.lastfm.fr')
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'can be specified via option (as string)' do
|
18
|
-
expect(Notu::Library.new('host' => 'www.lastfm.fr', username: 'alex').host).to eq('www.lastfm.fr')
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'is default host if blank' do
|
22
|
-
expect(Notu::Library.new(host: ' ', username: 'alex').host).to eq('www.last.fm')
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '#loved_tracks' do
|
28
|
-
|
29
|
-
it 'returns a LovedTracks object' do
|
30
|
-
expect(library.loved_tracks).to be_a(Notu::LovedTracks)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#most_played_tracks' do
|
36
|
-
|
37
|
-
it 'returns a LovedTracks object' do
|
38
|
-
most_played_tracks = library.most_played_tracks
|
39
|
-
expect(most_played_tracks).to be_a(Notu::MostPlayedTracks)
|
40
|
-
expect(most_played_tracks.period).to eq('7 days')
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'accepts options' do
|
44
|
-
expect(library.most_played_tracks(period: '30 days').period).to eq('30 days')
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#played_tracks' do
|
50
|
-
|
51
|
-
it 'returns a PlayedTrack object' do
|
52
|
-
expect(library.played_tracks).to be_a(Notu::PlayedTracks)
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#username' do
|
58
|
-
|
59
|
-
it 'is username set at initialization' do
|
60
|
-
expect(library.username).to eq('alexistoulotte')
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'can be specified as string' do
|
64
|
-
expect(Notu::Library.new('username' => 'john42').username).to eq('john42')
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'raise an error if nil' do
|
68
|
-
expect {
|
69
|
-
Notu::Library.new(username: nil)
|
70
|
-
}.to raise_error(Notu::Error, 'Invalid Last.fm username: nil')
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'raise an error if blank' do
|
74
|
-
expect {
|
75
|
-
Notu::Library.new(username: ' ')
|
76
|
-
}.to raise_error(Notu::Error, 'Invalid Last.fm username: " "')
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'raise an error if it contains spaces' do
|
80
|
-
expect {
|
81
|
-
Notu::Library.new(username: 'alexis toulotte')
|
82
|
-
}.to raise_error(Notu::Error, 'Invalid Last.fm username: "alexis toulotte"')
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'raise an error if invalid' do
|
86
|
-
expect {
|
87
|
-
Notu::Library.new(username: 'alex$')
|
88
|
-
}.to raise_error(Notu::Error, 'Invalid Last.fm username: "alex$"')
|
89
|
-
|
90
|
-
expect {
|
91
|
-
Notu::Library.new(username: 'ALex^')
|
92
|
-
}.to raise_error(Notu::Error, 'Invalid Last.fm username: "ALex^"')
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'is stripped' do
|
96
|
-
expect(Notu::Library.new(username: " alexis42 \n").username).to eq('alexis42')
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'is downcased' do
|
100
|
-
expect(Notu::Library.new(username: 'AlexIsT').username).to eq('alexist')
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
describe '#url' do
|
106
|
-
|
107
|
-
it 'returns default url if path not given' do
|
108
|
-
expect(library.url).to eq('https://www.last.fm/user/alexistoulotte')
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'returns default url if path is blank' do
|
112
|
-
expect(library.url(path: ' ')).to eq('https://www.last.fm/user/alexistoulotte')
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'accepts path option as string' do
|
116
|
-
expect(library.url('path' => '/library/loved')).to eq('https://www.last.fm/user/alexistoulotte/library/loved')
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'returns URL and path if given' do
|
120
|
-
expect(library.url(path: '/library/loved')).to eq('https://www.last.fm/user/alexistoulotte/library/loved')
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'adds first / to given path' do
|
124
|
-
expect(library.url(path: 'library/loved')).to eq('https://www.last.fm/user/alexistoulotte/library/loved')
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'use :host option set at initialization' do
|
128
|
-
library = Notu::Library.new(host: 'www.lastfm.fr', username: 'albundy02')
|
129
|
-
expect(library.url).to eq('https://www.lastfm.fr/user/albundy02')
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'accepts query option' do
|
133
|
-
expect(library.url(query: { bar: 42, 'baz' => 'hello&world' })).to eq('https://www.last.fm/user/alexistoulotte?bar=42&baz=hello%26world')
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Notu::LovedTracks, :vcr do
|
4
|
-
|
5
|
-
let(:library) { Notu::Library.new(username: 'alexistoulotte') }
|
6
|
-
let(:loved_tracks) { Notu::LovedTracks.new(library) }
|
7
|
-
|
8
|
-
describe '#each' do
|
9
|
-
|
10
|
-
it 'returns some tracks' do
|
11
|
-
tracks = loved_tracks.take(42)
|
12
|
-
expect(tracks.size).to eq(42)
|
13
|
-
tracks.each do |track|
|
14
|
-
expect(track).to be_a(Notu::Track)
|
15
|
-
expect(track.artist).to be_present
|
16
|
-
expect(track.plays_count).to be_nil
|
17
|
-
expect(track.title).to be_present
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'returns nil' do
|
22
|
-
allow(loved_tracks).to receive(:pages_count).and_return(1)
|
23
|
-
expect(loved_tracks.each {}).to be_nil
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#library' do
|
29
|
-
|
30
|
-
it 'is library given at initialization' do
|
31
|
-
expect(loved_tracks.library).to be(library)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'raise an error if library is nil' do
|
35
|
-
expect {
|
36
|
-
Notu::LovedTracks.new(nil)
|
37
|
-
}.to raise_error(ArgumentError, 'Notu::LovedTracks#library must be a library, nil given')
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#page_urls' do
|
43
|
-
|
44
|
-
it 'is correct' do
|
45
|
-
urls = loved_tracks.page_urls
|
46
|
-
expect(urls.size).to eq(loved_tracks.pages_count)
|
47
|
-
expect(urls).to include('https://www.last.fm/user/alexistoulotte/loved?page=12')
|
48
|
-
expect(urls).to include('https://www.last.fm/user/alexistoulotte/loved?page=3')
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#pages_count' do
|
54
|
-
|
55
|
-
it 'is correct' do
|
56
|
-
expect(loved_tracks.pages_count).to be_within(10).of(30)
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
describe '#params' do
|
62
|
-
|
63
|
-
it 'is an empty hash' do
|
64
|
-
expect(loved_tracks.params).to eq({})
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '#path' do
|
70
|
-
|
71
|
-
it 'is "loved"' do
|
72
|
-
expect(loved_tracks.path).to eq('loved')
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Notu::MostPlayedTracks, :vcr do
|
4
|
-
|
5
|
-
let(:library) { Notu::Library.new(username: 'alexistoulotte') }
|
6
|
-
let(:most_played_tracks) { Notu::MostPlayedTracks.new(library) }
|
7
|
-
|
8
|
-
describe '#library' do
|
9
|
-
|
10
|
-
it 'is library given at initialization' do
|
11
|
-
expect(most_played_tracks.library).to be(library)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'raise an error if library is nil' do
|
15
|
-
expect {
|
16
|
-
Notu::MostPlayedTracks.new(nil)
|
17
|
-
}.to raise_error(ArgumentError, 'Notu::MostPlayedTracks#library must be a library, nil given')
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#each' do
|
23
|
-
|
24
|
-
it 'returns some tracks' do
|
25
|
-
allow(most_played_tracks).to receive(:period).and_return('90 days')
|
26
|
-
tracks = most_played_tracks.take(28)
|
27
|
-
expect(tracks.size).to eq(28)
|
28
|
-
tracks.each do |track|
|
29
|
-
expect(track).to be_a(Notu::Track)
|
30
|
-
expect(track.artist).to be_present
|
31
|
-
expect(track.plays_count).to be > 0
|
32
|
-
expect(track.title).to be_present
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns nil' do
|
37
|
-
expect(most_played_tracks.each {}).to be_nil
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#page_urls' do
|
43
|
-
|
44
|
-
it 'is correct' do
|
45
|
-
allow(most_played_tracks).to receive(:period).and_return('365 days')
|
46
|
-
urls = most_played_tracks.page_urls
|
47
|
-
expect(urls.size).to eq(most_played_tracks.pages_count)
|
48
|
-
expect(urls).to include('https://www.last.fm/user/alexistoulotte/library/tracks?date_preset=LAST_365_DAYS&page=5')
|
49
|
-
expect(urls).to include('https://www.last.fm/user/alexistoulotte/library/tracks?date_preset=LAST_365_DAYS&page=2')
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
describe '#pages_count' do
|
55
|
-
|
56
|
-
it 'is correct' do
|
57
|
-
allow(most_played_tracks).to receive(:period).and_return('Overall')
|
58
|
-
expect(most_played_tracks.pages_count).to be_within(150).of(250)
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
describe '#params' do
|
64
|
-
|
65
|
-
it 'includes period' do
|
66
|
-
expect(most_played_tracks.params).to eq({ 'date_preset' => 'LAST_7_DAYS' })
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
describe '#path' do
|
72
|
-
|
73
|
-
it 'is "library/tracks"' do
|
74
|
-
expect(most_played_tracks.path).to eq('library/tracks')
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
describe '#period' do
|
80
|
-
|
81
|
-
it 'is "7 days" by default' do
|
82
|
-
expect(most_played_tracks.period).to eq('7 days')
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'can be specified via option' do
|
86
|
-
expect(Notu::MostPlayedTracks.new(library, period: '90 days').period).to eq('90 days')
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'can be specified via option (as string)' do
|
90
|
-
expect(Notu::MostPlayedTracks.new(library, 'period' => '90 days').period).to eq('90 days')
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'raise an error if invalid' do
|
94
|
-
expect {
|
95
|
-
Notu::MostPlayedTracks.new(library, period: '180 days')
|
96
|
-
}.to raise_error(ArgumentError, 'Notu::MostPlayedTracks#period is invalid: "180 days"')
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|