spot_tracks 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c29f96934a558b8b35c7908c36673091e5aa0780
4
+ data.tar.gz: cd1bd699b5df6052fcb191ebf71d563d1f1dd46a
5
+ SHA512:
6
+ metadata.gz: 34e6c9092096196faa0993e64f9415b0a90f38f1b92bd4eee897c29d5f416c7581537de501ba1258988968e7f4c8fa36d2fafda675d070844c5dc55f6851e425
7
+ data.tar.gz: 75cb56b98bcb30d2f796a30530d6f6012f549f937da458c40910882735290a99b01f4df4f3897fb6fb0a14822729731e6f8d307ddffd82c24db2c84f8377d50f
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spot_tracks.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Matthew Werner
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.
@@ -0,0 +1,29 @@
1
+ # SpotTracks
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'spot_tracks'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install spot_tracks
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/spot_tracks/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ require 'spot_tracks'
2
+
3
+ puts SpotTracks::Feed.new('mttwrnr').to_json
@@ -0,0 +1,6 @@
1
+ require "spot_tracks/version"
2
+
3
+ module SpotTracks
4
+ autoload :Feed, 'spot_tracks/feed'
5
+ autoload :Player, 'spot_tracks/player'
6
+ end
@@ -0,0 +1,55 @@
1
+ require 'feedjira'
2
+
3
+ module SpotTracks
4
+ class Feed
5
+ attr_reader :username
6
+
7
+ HOST = 'http://ws.audioscrobbler.com'
8
+
9
+ def initialize(username)
10
+ @username = username
11
+ end
12
+
13
+ def title
14
+ client.title
15
+ end
16
+
17
+ def url
18
+ client.url
19
+ end
20
+
21
+ def entries
22
+ client.entries.map do |entry|
23
+ {
24
+ title: entry.title,
25
+ urls: {
26
+ lastfm: entry.url,
27
+ spotify: player.spotify_uri(entry.title)
28
+ }
29
+ }
30
+ end
31
+ end
32
+
33
+ def to_json
34
+ {
35
+ title: title,
36
+ url: url,
37
+ entries: entries
38
+ }.to_json
39
+ end
40
+
41
+ private
42
+
43
+ def client
44
+ @client ||= Feedjira::Feed.fetch_and_parse(rss_url)
45
+ end
46
+
47
+ def rss_url
48
+ "#{HOST}/1.0/user/#{username}/recenttracks.rss"
49
+ end
50
+
51
+ def player
52
+ @player ||= SpotTracks::Player.new
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+ module SpotTracks
5
+ class Player
6
+ HOST = 'https://api.spotify.com'
7
+
8
+ def spotify_uri(title)
9
+ data = search(title)
10
+ return unless data.is_a?(Hash)
11
+
12
+ tracks = data['tracks'] || {}
13
+ items = tracks['items'] || [{}]
14
+
15
+ items.first['uri']
16
+ end
17
+
18
+ def search(term)
19
+ path = "v1/search?q=#{CGI.escape(term)}&type=track"
20
+ api_data("#{HOST}/#{path}")
21
+ end
22
+
23
+ private
24
+
25
+ def api_data(url)
26
+ JSON.parse(get(url))
27
+ end
28
+
29
+ def get(url)
30
+ open(url).read
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module SpotTracks
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'rspec'
5
+ require 'spot_tracks'
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpotTracks::Feed do
4
+ let(:user){ 'mttwrnr' }
5
+ let(:subject){ SpotTracks::Feed.new(user) }
6
+ let(:data){
7
+ {
8
+ title: 'baz',
9
+ urls: {
10
+ lastfm: 'qux',
11
+ spotify: 'spotify:track:qux'
12
+ }
13
+ }
14
+ }
15
+ let(:entry){ double(title: 'baz', url: 'qux')}
16
+ let(:player){ double(spotify_uri: 'spotify:track:qux') }
17
+ let(:client){ double(title: 'foo', url: 'http://bar', entries: [entry]) }
18
+ let(:rss_url){ "http://ws.audioscrobbler.com/1.0/user/#{user}/recenttracks.rss" }
19
+
20
+ before do
21
+ Feedjira::Feed.stub(:fetch_and_parse).with(rss_url){ client }
22
+ SpotTracks::Player.stub(:new){ player }
23
+ end
24
+
25
+ context 'attributes' do
26
+ it 'should establish a username' do
27
+ subject.username.should eq('mttwrnr')
28
+ end
29
+
30
+ it 'should return rss title' do
31
+ subject.title.should eq('foo')
32
+ end
33
+
34
+ it 'should return rss url' do
35
+ subject.url.should eq('http://bar')
36
+ end
37
+ end
38
+
39
+ context '#entries' do
40
+ it 'should return a mapped set of values' do
41
+ subject.entries.should eq([data])
42
+ end
43
+ end
44
+
45
+ context '#to_json' do
46
+ it 'should return a json version of entries values' do
47
+ result = "{\"title\":\"foo\",\"url\":\"http://bar\",\"entries\":[{\"title\":\"baz\",\"urls\":{\"lastfm\":\"qux\",\"spotify\":\"spotify:track:qux\"}}]}"
48
+ subject.to_json.should eq(result)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpotTracks::Player do
4
+ let(:json){ "{\"tracks\":{\"items\":[{\"uri\":\"spotify:track:foo\"}]}}" }
5
+ let(:subject){ SpotTracks::Player.new }
6
+
7
+ context '#spotify_uri' do
8
+ it 'should return a spotify uri' do
9
+ subject.stub(:open){ double(read: json) }
10
+ subject.spotify_uri('track').should match(/^spotify:.*/)
11
+ end
12
+
13
+ it 'should handle a missing uri' do
14
+ subject.stub(:get){ "{\"tracks\":{\"items\":[{}]}}" }
15
+ subject.spotify_uri('track').should be_nil
16
+ end
17
+
18
+ it 'should handle missing items' do
19
+ subject.stub(:get){ "{\"tracks\":{}}" }
20
+ subject.spotify_uri('track').should be_nil
21
+ end
22
+
23
+ it 'should handle missing tracks' do
24
+ subject.stub(:get){ "{}" }
25
+ subject.spotify_uri('track').should be_nil
26
+ end
27
+
28
+ it 'should handle missing data' do
29
+ subject.stub(:get){ "[]" }
30
+ subject.spotify_uri('track').should be_nil
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spot_tracks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spot_tracks"
8
+ spec.version = SpotTracks::VERSION
9
+ spec.authors = ["Matthew Werner"]
10
+ spec.email = ["m@mjw.io"]
11
+ spec.summary = %q{A small gem to get recent spotify tracks}
12
+ spec.description = %q{Get your recent Last.fm tracks with spotify links}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "simplecov", '~> 0.7'
22
+ spec.add_development_dependency "rspec", '~> 2.13'
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+
26
+ spec.add_dependency 'feedjira', '~> 1.3'
27
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spot_tracks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Werner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simplecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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: feedjira
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ description: Get your recent Last.fm tracks with spotify links
84
+ email:
85
+ - m@mjw.io
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - examples/basic.rb
97
+ - lib/spot_tracks.rb
98
+ - lib/spot_tracks/feed.rb
99
+ - lib/spot_tracks/player.rb
100
+ - lib/spot_tracks/version.rb
101
+ - spec/spec_helper.rb
102
+ - spec/spot_tracks/feed_spec.rb
103
+ - spec/spot_tracks/player_spec.rb
104
+ - spot_tracks.gemspec
105
+ homepage: ''
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A small gem to get recent spotify tracks
129
+ test_files:
130
+ - spec/spec_helper.rb
131
+ - spec/spot_tracks/feed_spec.rb
132
+ - spec/spot_tracks/player_spec.rb