homophone 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 82b19502328a13ec7122d711ef3d87632f2f0304
4
+ data.tar.gz: ef0fabfb33d1c6a0bc639fca6c36fdac65650722
5
+ SHA512:
6
+ metadata.gz: 3509b925b64fa53568bf045d1061acc1c7cae2325f61b79c06190895594b1d0cef8e3c6229c13c07f3e5501a61ed5c8332bf011e3c7716fb4a92233b653c05be
7
+ data.tar.gz: 688aa82798d649fee8caaa94f66d387323a4a4fe0cf2ef8255e09ff0aab15da60f39a492751be98c95be8931ae95c771fbb79b6b14449e614441293809025eed
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'homophone/version'
4
+
5
+ GEMSPEC = `git ls-files | grep gemspec`.chomp
6
+ GEM = "homophone-#{Homophone::VERSION}.gem"
7
+
8
+ desc "Build gem"
9
+ task :build => :perms do
10
+ system "gem", "build", GEMSPEC
11
+ end
12
+
13
+ desc "Ensure correct permissions for gem"
14
+ task :perms do
15
+ system "chmod", "-R", "a+rX", *`git ls-files`.chomp.split("\n")
16
+ end
17
+
18
+ desc "Tag the latest version of gem"
19
+ task :tag do
20
+ system "git", "tag", "-s", "-m", "homophone v#{Homophone::VERSION}", "v#{Homophone::VERSION}"
21
+ end
22
+
23
+ desc "Install gem"
24
+ task :install => :build do
25
+ system "gem", "install", GEM
26
+ end
27
+
28
+ desc "Push gem to RubyGems"
29
+ task :release => [:tag, :build] do
30
+ fail 'Cannot release a dev version' if Homophone::VERSION.end_with?('dev')
31
+ system "gem", "push", GEM
32
+ end
33
+
34
+ desc "Clean built products"
35
+ task :clean do
36
+ rm Dir.glob("*.gem"), :verbose => true
37
+ end
38
+
39
+ task :default => :build
data/exe/homophone ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'homophone'
4
+
5
+ Homophone.application.run(ARGV)
data/homophone.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'homophone/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'homophone'
9
+ spec.version = Homophone::VERSION
10
+ spec.licenses = 'MIT'
11
+ spec.authors = ['Michael Dippery']
12
+ spec.email = ['michael@monkey-robot.com']
13
+
14
+ spec.summary = 'Find related artists for a band'
15
+ spec.description = <<-DESC
16
+ Find related artists for your favorite band. Queries the Spotify API to find
17
+ other artists that are similar to a given artist.
18
+ DESC
19
+ spec.homepage = 'https://github.com/mdippery/homophone'
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.metadata = {
27
+ 'build_date' => Time.now.strftime('%Y-%m-%d %H:%M:%S %Z'),
28
+ 'commit' => `git describe 2>/dev/null`.chomp,
29
+ 'commit_hash' => `git rev-parse HEAD`.chomp,
30
+ }
31
+
32
+ spec.required_ruby_version = '>= 1.9.3'
33
+
34
+ spec.add_runtime_dependency('httparty', '~> 0.13.7')
35
+ spec.add_runtime_dependency('json', '~> 1.8')
36
+
37
+ spec.add_development_dependency('aruba', '~> 0.14')
38
+ spec.add_development_dependency('cucumber', '~> 2.3')
39
+ spec.add_development_dependency('rspec', '~> 3.4')
40
+ spec.add_development_dependency('vcr', '~> 3.0')
41
+ spec.add_development_dependency('webmock', '~> 1.24')
42
+ end
data/lib/homophone.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'homophone/application'
2
+ require 'homophone/service'
@@ -0,0 +1,44 @@
1
+ require 'homophone/version'
2
+
3
+ module Homophone
4
+ class << self
5
+ def application
6
+ @application ||= Application.new
7
+ end
8
+ end
9
+
10
+ class Application
11
+ def run(argv)
12
+ onoe 127, 'no musician name provided' if argv.count < 1
13
+ ohai "homophone v#{Homophone::VERSION}" if argv[0] == '--version'
14
+
15
+ musician_name = argv.shift
16
+ musician = spotify_service.musician(musician_name)
17
+ onoe 126, %Q{no musician with name "#{musician_name}" found} if musician.nil?
18
+ artists = musician.related_artists.map(&:name).sort
19
+ artists.each do |artist|
20
+ puts artist
21
+ end
22
+ end
23
+
24
+ def spotify_service
25
+ @service ||= (cucumber? ? Homophone::Service::DummySpotify : Homophone::Service::Spotify).new
26
+ end
27
+
28
+ def ohai(msg)
29
+ puts msg
30
+ exit 0
31
+ end
32
+
33
+ def onoe(exit_code, msg)
34
+ STDERR.puts "homophone: #{msg}"
35
+ exit exit_code
36
+ end
37
+
38
+ private
39
+
40
+ def cucumber?
41
+ ENV['HOMOPHONE_ENV'] == 'cucumber'
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,73 @@
1
+ require 'cgi'
2
+ require 'httparty'
3
+ require 'json'
4
+ require 'uri'
5
+ require 'yaml'
6
+
7
+ module Homophone
8
+ module Service
9
+ module MusicianRetriever
10
+ def musician(name)
11
+ data = get("/search?type=artist&q=#{name}")['artists']['items']
12
+ return nil unless data.count > 0
13
+ data = data[0]
14
+ Musician.new(self, data)
15
+ end
16
+ end
17
+
18
+ class Spotify
19
+ include Homophone::Service::MusicianRetriever
20
+ include HTTParty
21
+ base_uri 'https://api.spotify.com/v1'
22
+
23
+ def get(url)
24
+ JSON.parse(self.class.get(url).body)
25
+ end
26
+ end
27
+
28
+ class DummySpotify
29
+ include Homophone::Service::MusicianRetriever
30
+
31
+ def get(url)
32
+ uri = URI(url)
33
+ path_parts = uri.path.split('/').reject { |p| p == '' }
34
+ path_base = path_parts.first
35
+ path = case path_base
36
+ when 'search'
37
+ params = CGI::parse(uri.query)
38
+ type = params['type'].first
39
+ name = params['q'].first.gsub(/[+ ]/, '_')
40
+ "search/#{type}/#{name}"
41
+ when 'artists'
42
+ "artists/#{path_parts.last}/#{path_parts[1]}"
43
+ else
44
+ nil
45
+ end
46
+ raise ArgumentError, "No cassette for #{url}" unless path
47
+ path = File.join(source_path, "#{path}.yml")
48
+ JSON.load(YAML.load(IO.read(path))['http_interactions'][0]['response']['body']['string'])
49
+ end
50
+
51
+ private
52
+
53
+ def source_path
54
+ File.join(File.dirname(__FILE__), '..', '..', 'features', 'fixtures', 'cassettes')
55
+ end
56
+ end
57
+ end
58
+
59
+ class Musician
60
+ attr_reader :spotify_id, :name
61
+
62
+ def initialize(service, blob)
63
+ @service = service
64
+ @spotify_id = blob['id']
65
+ @name = blob['name']
66
+ end
67
+
68
+ def related_artists
69
+ data = @service.get("/artists/#{spotify_id}/related-artists")['artists']
70
+ data.map { |e| Musician.new(@service, e) }
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module Homophone
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: homophone
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Dippery
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aruba
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cucumber
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.24'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.24'
111
+ description: |
112
+ Find related artists for your favorite band. Queries the Spotify API to find
113
+ other artists that are similar to a given artist.
114
+ email:
115
+ - michael@monkey-robot.com
116
+ executables:
117
+ - homophone
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".gitignore"
122
+ - Gemfile
123
+ - Rakefile
124
+ - exe/homophone
125
+ - homophone.gemspec
126
+ - lib/homophone.rb
127
+ - lib/homophone/application.rb
128
+ - lib/homophone/service.rb
129
+ - lib/homophone/version.rb
130
+ homepage: https://github.com/mdippery/homophone
131
+ licenses:
132
+ - MIT
133
+ metadata:
134
+ build_date: 2016-04-06 19:32:51 PDT
135
+ commit: v1.0.0
136
+ commit_hash: 3f64945aa6d8860cc6675ce0bb4496c13fcd6e4c
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 1.9.3
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.4.5.1
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Find related artists for a band
157
+ test_files: []