postrocktues 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +9 -0
- data/.rspec.example +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +95 -0
- data/Rakefile +5 -0
- data/config.yml.example +5 -0
- data/lib/postrocktues.rb +3 -0
- data/lib/postrocktues/adapters/spotify.rb +44 -0
- data/lib/postrocktues/config.rb +23 -0
- data/lib/postrocktues/feed.rb +41 -0
- data/lib/postrocktues/fetcher.rb +33 -0
- data/lib/postrocktues/playlist.rb +45 -0
- data/lib/postrocktues/track.rb +34 -0
- data/lib/postrocktues/version.rb +3 -0
- data/postrocktues.gemspec +23 -0
- data/spec/postrocktues/adapters/spotify_spec.rb +22 -0
- data/spec/postrocktues/config_spec.rb +21 -0
- data/spec/postrocktues/feed_spec.rb +46 -0
- data/spec/postrocktues/fetcher_spec.rb +15 -0
- data/spec/postrocktues/playlist_spec.rb +55 -0
- data/spec/postrocktues/track_spec.rb +39 -0
- data/spec/support/spec_helper.rb +55 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTA5YmQ2NGYwYTQxMTgxNmE4NDZkYjQ2Y2EwMmI4YzRlYTNlNjZhOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTUwN2Q4OTYwYTUyZTVjNGZlNDlmYzJjYjAwZDIzNWY3MjU2MjlhMw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzVjNjI2OTYwY2IyNGM4OGRiMjI5NjZiM2E2OGY3NzdiMDJmZjVkNTJjYWU5
|
10
|
+
NDg5ZTdmMWZkNTE3YWJhNGI2YTU3M2UyNjFkOGY5YWVhYjhhZWY4YjUyMjE2
|
11
|
+
ZDBiYTMyOWMzMWJkMGViOTgyOWNhMzhiYTdhZjRkYTE5NmU0NTg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjAxZDcwMDgxMzg0MWNhZmQ5YWZjNjliZTlmYTMyZjgwZGYxN2Y1ZTE0Yjhm
|
14
|
+
MzU4Yjg2YzY5ZGRjNjYwMDc4NTdkNDIxNmRmMDJiMjFkZTBlZjAzMDEzNDZi
|
15
|
+
ZWU0OTc2NmFiZWQ0NTFmMmFmNDRkMzk3NzgyM2MwZjk0MDkzMzU=
|
data/.gitignore
ADDED
data/.rspec.example
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Teo Ljungberg
|
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,95 @@
|
|
1
|
+
# Postrocktues
|
2
|
+
[![Build Status](https://travis-ci.org/metamorfos/postrocktues.png)](https://travis-ci.org/metamorfos/postrocktues)
|
3
|
+
|
4
|
+
[Postrocktu.es](http://postrocktu.es) is a fantastic site
|
5
|
+
for getting inspiration for new postrock artists and tracks.
|
6
|
+
|
7
|
+
I use it every tuesday(when new tracks are released) so I
|
8
|
+
build this gem to get [Spotify][spotify_homepage] links
|
9
|
+
from the tracks. Oh how awesome!
|
10
|
+
Do you know what's even more awesome?! Creating a gorgeous
|
11
|
+
Postrock playlist out of this, oh yeah
|
12
|
+
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'postrocktues'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install postrocktues
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
### Setup
|
31
|
+
|
32
|
+
First of all, you need a [Spotify][spotify_homepage] premium
|
33
|
+
account, if you don't have one pay up and get one! You'll thank me later!!
|
34
|
+
|
35
|
+
1. Log into your account and get the appkey for this project to work.
|
36
|
+
Consult the documentation [here][dev_docs]
|
37
|
+
on how do do this.
|
38
|
+
2. Place the `app_key.key` file in the root of this project
|
39
|
+
3. Enter your [Spotify][spotify_homepage] credentials into the `config.yml` file,
|
40
|
+
there is an example provided.
|
41
|
+
4. Let's fire up irb/pry and get this working!
|
42
|
+
|
43
|
+
### Some code examples!
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'postrocktues'
|
47
|
+
feed = Postrocktues::Feed.new
|
48
|
+
tracks = feed.tracks
|
49
|
+
# This step unfortunatly takes a while..
|
50
|
+
# since it has to search for all of the tracks
|
51
|
+
track = tracks.last
|
52
|
+
track.name
|
53
|
+
#=> "Your Hand In Mine"
|
54
|
+
track.artist
|
55
|
+
#=> "Explosions in the Sky"
|
56
|
+
track.uri
|
57
|
+
#=> "spotify:track:2kZVhrdxG7BEIsyrTJYdq9"
|
58
|
+
track.url
|
59
|
+
#=> "http://open.spotify.com/track/2kZVhrdxG7BEIsyrTJYdq9"
|
60
|
+
```
|
61
|
+
|
62
|
+
Here's how you would create a playlist out of the tracks!
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
playlist = Postrocktues::Playlist.new
|
66
|
+
playlist.add tracks # tracks comes from the previous example
|
67
|
+
playlist.upload # uploads it to Spotify
|
68
|
+
```
|
69
|
+
|
70
|
+
Then just pop open [Spotify][spotify_homepage] and enjoy some glorious
|
71
|
+
Postrock.
|
72
|
+
|
73
|
+
## Note
|
74
|
+
Sadly, the whole creating tracks process is a bit slow.
|
75
|
+
It currently takes ~30 seconds to load up all of the tracks.
|
76
|
+
Since I first have to:
|
77
|
+
|
78
|
+
* Search for the tracks, remove tracks that can't be found
|
79
|
+
* Create track objects from the search result
|
80
|
+
|
81
|
+
It is a bit slow, but it's manageable! It will get faster, as soon
|
82
|
+
as I figure out how..
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
1. Fork it
|
87
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
88
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
89
|
+
4. Don't forget the tests! I won't accept a PR without any tests, sorry
|
90
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
91
|
+
6. Create new Pull Request
|
92
|
+
|
93
|
+
|
94
|
+
[spotify_homepage]: http://spotify.com
|
95
|
+
[dev_docs]: https://developer.spotify.com/technologies/libspotify/
|
data/Rakefile
ADDED
data/config.yml.example
ADDED
data/lib/postrocktues.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'postrocktues/config'
|
2
|
+
require 'hallon'
|
3
|
+
|
4
|
+
module Postrocktues
|
5
|
+
module Adapters
|
6
|
+
class Spotify
|
7
|
+
def init_hallon
|
8
|
+
if appkey = Postrocktues::Config.load.appkey
|
9
|
+
config = Postrocktues::Config.load
|
10
|
+
session = Hallon::Session.initialize IO.read(appkey)
|
11
|
+
session.login!(config.username, config.password)
|
12
|
+
self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def search query
|
17
|
+
result = search_wrapper query
|
18
|
+
valid_search?(result) ? result.first : nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def track uri
|
22
|
+
Hallon::Track.new uri
|
23
|
+
end
|
24
|
+
|
25
|
+
def playlist uri
|
26
|
+
Hallon::Playlist.new uri
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def search_wrapper query
|
32
|
+
Hallon::Search.new(query).load.tracks
|
33
|
+
end
|
34
|
+
|
35
|
+
def valid_search? result
|
36
|
+
!empty_search? result
|
37
|
+
end
|
38
|
+
|
39
|
+
def empty_search? tmp
|
40
|
+
tmp.empty?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Postrocktues
|
5
|
+
class Config < OpenStruct
|
6
|
+
class << self
|
7
|
+
def load path = default_config
|
8
|
+
raise FileNotFound unless File.exists? path
|
9
|
+
new YAML.load_file(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def default_config
|
15
|
+
File.expand_path 'config.yml'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class FileNotFound < Exception
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'postrocktues/adapters/spotify'
|
2
|
+
require 'postrocktues/fetcher'
|
3
|
+
require 'postrocktues/track'
|
4
|
+
|
5
|
+
module Postrocktues
|
6
|
+
class Feed
|
7
|
+
|
8
|
+
attr_reader :url, :spotify
|
9
|
+
|
10
|
+
def initialize opts = {}
|
11
|
+
@url = opts.fetch(:url) { fallback_url }
|
12
|
+
@spotify = opts.fetch(:spotify) { fallback_spotify }
|
13
|
+
end
|
14
|
+
|
15
|
+
def list_tracks
|
16
|
+
@list_tracks ||= fetcher.queries.map do |t|
|
17
|
+
track = spotify.search t
|
18
|
+
Postrocktues::Track.new(track) unless track.nil?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
alias_method :tracks, :list_tracks
|
22
|
+
|
23
|
+
def tracks_as_plaintext
|
24
|
+
@plaintext_tracks ||= fetcher.tracks.map &:to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def fallback_url
|
30
|
+
"http://postrocktu.es"
|
31
|
+
end
|
32
|
+
|
33
|
+
def fetcher
|
34
|
+
@fetcher ||= Postrocktues::Fetcher.new self
|
35
|
+
end
|
36
|
+
|
37
|
+
def fallback_spotify
|
38
|
+
@spotify ||= Postrocktues::Adapters::Spotify.new.init_hallon
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'postrocktues/feed'
|
2
|
+
require 'net/http'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Postrocktues
|
7
|
+
class Fetcher
|
8
|
+
|
9
|
+
attr_reader :feed
|
10
|
+
|
11
|
+
def initialize feed
|
12
|
+
@feed = feed
|
13
|
+
end
|
14
|
+
|
15
|
+
def queries
|
16
|
+
fetch_queries.reverse
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def fetch_queries
|
22
|
+
@fetch_queries ||= corpus.map { |e| "#{e['track_name']} #{e['artist_name']}" }
|
23
|
+
end
|
24
|
+
|
25
|
+
def raw_html
|
26
|
+
@raw_html ||= Net::HTTP.get URI(feed.url)
|
27
|
+
end
|
28
|
+
|
29
|
+
def corpus
|
30
|
+
JSON.parse raw_html.match(/postRockDays\.reset\((.+)\)/)[1]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'postrocktues/config'
|
2
|
+
|
3
|
+
module Postrocktues
|
4
|
+
class Playlist
|
5
|
+
|
6
|
+
attr_reader :uri, :spotify
|
7
|
+
|
8
|
+
def initialize opts = {}
|
9
|
+
config = opts.fetch(:config) { config_fallback }
|
10
|
+
@uri = opts.fetch(:uri) { config.playlist }
|
11
|
+
@spotify = opts.fetch(:spotify) { spotify_fallback }
|
12
|
+
end
|
13
|
+
|
14
|
+
def add tracks, place = 0
|
15
|
+
tracks.reverse.map { |t| playlist.insert place, spotify.track(t.uri) }
|
16
|
+
end
|
17
|
+
alias_method :<<, :add
|
18
|
+
|
19
|
+
def clear!
|
20
|
+
playlist.size.times { playlist.remove 0 }
|
21
|
+
end
|
22
|
+
|
23
|
+
def size
|
24
|
+
playlist.size
|
25
|
+
end
|
26
|
+
|
27
|
+
def upload
|
28
|
+
playlist.upload
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def playlist
|
34
|
+
@playlist ||= spotify.playlist(uri).load
|
35
|
+
end
|
36
|
+
|
37
|
+
def spotify_fallback
|
38
|
+
Postrocktues::Adapters::Spotify.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def config_fallback
|
42
|
+
Postrocktues::Config.load
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Postrocktues
|
2
|
+
class Track
|
3
|
+
|
4
|
+
attr_reader :track
|
5
|
+
|
6
|
+
def initialize track_obj
|
7
|
+
@track = track_obj
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
track.name
|
12
|
+
end
|
13
|
+
|
14
|
+
def artist
|
15
|
+
track.artist.name
|
16
|
+
end
|
17
|
+
|
18
|
+
def album
|
19
|
+
track.album.name
|
20
|
+
end
|
21
|
+
|
22
|
+
def uri
|
23
|
+
track.to_link.to_uri
|
24
|
+
end
|
25
|
+
|
26
|
+
def url
|
27
|
+
track.to_link.to_url
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
"#{track.name} by #{track.artist.name} (#{track.album.name})"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'postrocktues/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "postrocktues"
|
8
|
+
gem.version = Postrocktues::VERSION
|
9
|
+
gem.authors = ["Teo Ljungberg"]
|
10
|
+
gem.email = ["teo.ljungberg@gmail.com"]
|
11
|
+
gem.description = %q{From http://postrocktu.es into Spotify links and playlists}
|
12
|
+
gem.summary = %q{From http://postrocktu.es into Spotify links and playlists}
|
13
|
+
gem.homepage = "https://github.com/metamorfos/postrocktues"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_dependency 'hallon', "~> 0.18.1"
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
gem.add_development_dependency "pry"
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'postrocktues/adapters/spotify'
|
2
|
+
|
3
|
+
describe Postrocktues::Adapters::Spotify do
|
4
|
+
let(:spotify) { described_class.new }
|
5
|
+
|
6
|
+
describe '#init_hallon' do
|
7
|
+
before { spotify.stub(:init_hallon) { described_class } }
|
8
|
+
it { spotify.init_hallon.should eq Postrocktues::Adapters::Spotify }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#search" do
|
12
|
+
context "valid search" do
|
13
|
+
before { spotify.stub(:search).with('humbug') { 'A Humbug Search' } }
|
14
|
+
it { spotify.search('humbug').should eq 'A Humbug Search' }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'nonvalid search' do
|
18
|
+
before { spotify.stub(:search).with("something that doesn't exist") { nil } }
|
19
|
+
it { spotify.search("something that doesn't exist").should be_nil }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'postrocktues/config'
|
2
|
+
|
3
|
+
describe Postrocktues::Config do
|
4
|
+
let(:config) { described_class.load "config.yml.example" }
|
5
|
+
|
6
|
+
describe '.load' do
|
7
|
+
context 'the given file does not exist' do
|
8
|
+
let(:config) { described_class.load '/highway/to/hell' }
|
9
|
+
|
10
|
+
it { expect { config }.to raise_error Postrocktues::Config::FileNotFound }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#username' do
|
15
|
+
it { config.username.should eq "kinginthejungle" }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#password' do
|
19
|
+
it { config.password.should eq "sekkrit" }
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'support/spec_helper'
|
2
|
+
require 'postrocktues/feed'
|
3
|
+
|
4
|
+
describe Postrocktues::Feed do
|
5
|
+
describe '#initialize' do
|
6
|
+
context 'given url' do
|
7
|
+
let(:feed) { described_class.new url: 'http://monkeytown.com',
|
8
|
+
spotify: NullSpotify.new }
|
9
|
+
it { feed.url.should eq 'http://monkeytown.com' }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'fallback to url' do
|
13
|
+
let(:feed) { double('feed', url: Fallback.new) }
|
14
|
+
it { feed.url.should be_instance_of Fallback }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'given spotify object' do
|
18
|
+
let(:feed) { described_class.new spotify: NullSpotify.new,
|
19
|
+
url: 'http://monkeytown.com' }
|
20
|
+
it { feed.spotify.should be_instance_of NullSpotify }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'fallback to spotify object' do
|
24
|
+
let(:feed) { double('feed', spotify: Fallback.new) }
|
25
|
+
it { feed.spotify.should be_instance_of Fallback }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#list_tracks' do
|
30
|
+
let(:feed) { described_class.new spotify: NullSpotify.new }
|
31
|
+
|
32
|
+
it { feed.should respond_to(:tracks, :list_tracks) }
|
33
|
+
|
34
|
+
before { feed.stub(:list_tracks) { %w(track_obj1 track_obj2 track_obj3) } }
|
35
|
+
it { feed.list_tracks.should be_uniq }
|
36
|
+
it { feed.list_tracks.should include "track_obj1" }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#tracks_as_plaintext' do
|
40
|
+
let(:feed) { described_class.new spotify: NullSpotify.new }
|
41
|
+
|
42
|
+
before { feed.stub(:tracks_as_plaintext) { %w(foo bar) } }
|
43
|
+
it { feed.tracks_as_plaintext.should be_uniq }
|
44
|
+
it { feed.tracks_as_plaintext.should include "foo" }
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'postrocktues/fetcher'
|
2
|
+
require 'support/spec_helper'
|
3
|
+
|
4
|
+
describe Postrocktues::Fetcher do
|
5
|
+
let(:fetcher) { described_class.new NullFeed.new }
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
it { fetcher.feed.should be_instance_of NullFeed }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#queries' do
|
12
|
+
before { fetcher.stub(:queries) { ['track1 artist1', 'track2 artist2', 'track3 artist3'] } }
|
13
|
+
it { fetcher.queries.should include 'track3 artist3' }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'postrocktues/adapters/spotify'
|
2
|
+
require 'postrocktues/playlist'
|
3
|
+
require 'support/spec_helper'
|
4
|
+
|
5
|
+
describe Postrocktues::Playlist do
|
6
|
+
describe '#initialize' do
|
7
|
+
let(:playlist) { described_class.new uri: 'spotify:user:FOO:playlist:BAR', spotify: NullSpotify.new, config: NullConfig.new }
|
8
|
+
|
9
|
+
context 'provided uri' do
|
10
|
+
it { playlist.uri.should eq 'spotify:user:FOO:playlist:BAR' }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'fallback uri from config' do
|
14
|
+
let(:playlist) { described_class.new spotify: NullSpotify.new, config: NullConfig.new }
|
15
|
+
|
16
|
+
before { Postrocktues::Config.stub(new: stub(playlist: 'spotify:user:bob:playlist:keystring' )) }
|
17
|
+
it { playlist.uri.should eq 'spotify:user:bob:playlist:keystring' }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#add' do
|
22
|
+
context 'adding tracks' do
|
23
|
+
let(:playlist) { described_class.new spotify: NullSpotify.new, config: NullConfig.new }
|
24
|
+
before { Postrocktues::Config.stub(new: stub(playlist: 'spotify:user:bob:playlist:keystring' )) }
|
25
|
+
|
26
|
+
it { playlist.should respond_to(:<<, :add) }
|
27
|
+
|
28
|
+
before { playlist.stub(:size) { 3 } }
|
29
|
+
it 'adds 3 tracks' do
|
30
|
+
playlist.add %w(track1 track2 track3)
|
31
|
+
playlist.size.should eq 3
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#clear!' do
|
37
|
+
let(:playlist) { double('playlist', clear!: 0) }
|
38
|
+
|
39
|
+
context 'before clear' do
|
40
|
+
before { playlist.stub(:size) { 10 } }
|
41
|
+
it do
|
42
|
+
playlist.clear!
|
43
|
+
playlist.size.should eq 10
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'after clear' do
|
48
|
+
before { playlist.stub(:size) { 0 } }
|
49
|
+
it do
|
50
|
+
playlist.clear!
|
51
|
+
playlist.size.should eq 0
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'postrocktues/track'
|
3
|
+
|
4
|
+
describe Postrocktues::Track do
|
5
|
+
let(:track) do
|
6
|
+
double('track',
|
7
|
+
name: "This place Was a Shelter",
|
8
|
+
artist: "Ólafur Arnalds",
|
9
|
+
album: "For now I am winter",
|
10
|
+
uri: "an:arbitrary:spotify_url",
|
11
|
+
url: "http://open.spotify.com/track/spotify_url",
|
12
|
+
to_s: "This place Was a Shelter by Ólafur Arnalds (For now I am winter)"
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#name' do
|
17
|
+
it { track.name.should eq "This place Was a Shelter" }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#artist' do
|
21
|
+
it { track.artist.should eq "Ólafur Arnalds" }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#album' do
|
25
|
+
it { track.album.should eq "For now I am winter" }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#uri' do
|
29
|
+
it { track.uri.should eq "an:arbitrary:spotify_url" }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#url' do
|
33
|
+
it { track.url.should eq "http://open.spotify.com/track/spotify_url" }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#to_s' do
|
37
|
+
it { track.to_s.should eq "This place Was a Shelter by Ólafur Arnalds (For now I am winter)" }
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class Array
|
2
|
+
def uniq?
|
3
|
+
self.uniq.length == self.length
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class String
|
8
|
+
def uri
|
9
|
+
self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class NullSpotify
|
14
|
+
def method_missing(method, *args)
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def size
|
19
|
+
0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class NullConfig
|
24
|
+
def method_missing(method, *args)
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def playlist
|
29
|
+
"spotify:user:bob:playlist:keystring"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class NullTrack
|
34
|
+
def method_missing(method, *args)
|
35
|
+
self
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class NullFetcher
|
40
|
+
def method_missing(method, *args)
|
41
|
+
self
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class NullFeed
|
46
|
+
def method_missing(method, *args)
|
47
|
+
self
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Fallback
|
52
|
+
def method_missing(method, *args)
|
53
|
+
self
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: postrocktues
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Teo Ljungberg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
prerelease: false
|
15
|
+
name: hallon
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.18.1
|
21
|
+
requirement: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ~>
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.18.1
|
26
|
+
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
prerelease: false
|
29
|
+
name: rake
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
prerelease: false
|
43
|
+
name: rspec
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
prerelease: false
|
57
|
+
name: pry
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
description: From http://postrocktu.es into Spotify links and playlists
|
70
|
+
email:
|
71
|
+
- teo.ljungberg@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec.example
|
78
|
+
- .travis.yml
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- config.yml.example
|
84
|
+
- lib/postrocktues.rb
|
85
|
+
- lib/postrocktues/adapters/spotify.rb
|
86
|
+
- lib/postrocktues/config.rb
|
87
|
+
- lib/postrocktues/feed.rb
|
88
|
+
- lib/postrocktues/fetcher.rb
|
89
|
+
- lib/postrocktues/playlist.rb
|
90
|
+
- lib/postrocktues/track.rb
|
91
|
+
- lib/postrocktues/version.rb
|
92
|
+
- postrocktues.gemspec
|
93
|
+
- spec/postrocktues/adapters/spotify_spec.rb
|
94
|
+
- spec/postrocktues/config_spec.rb
|
95
|
+
- spec/postrocktues/feed_spec.rb
|
96
|
+
- spec/postrocktues/fetcher_spec.rb
|
97
|
+
- spec/postrocktues/playlist_spec.rb
|
98
|
+
- spec/postrocktues/track_spec.rb
|
99
|
+
- spec/support/spec_helper.rb
|
100
|
+
homepage: https://github.com/metamorfos/postrocktues
|
101
|
+
licenses: []
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.0.3
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: From http://postrocktu.es into Spotify links and playlists
|
123
|
+
test_files:
|
124
|
+
- spec/postrocktues/adapters/spotify_spec.rb
|
125
|
+
- spec/postrocktues/config_spec.rb
|
126
|
+
- spec/postrocktues/feed_spec.rb
|
127
|
+
- spec/postrocktues/fetcher_spec.rb
|
128
|
+
- spec/postrocktues/playlist_spec.rb
|
129
|
+
- spec/postrocktues/track_spec.rb
|
130
|
+
- spec/support/spec_helper.rb
|