homophone 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82b19502328a13ec7122d711ef3d87632f2f0304
4
- data.tar.gz: ef0fabfb33d1c6a0bc639fca6c36fdac65650722
3
+ metadata.gz: 3464d5a63f67b8875c50811be08e051e698b9a7c
4
+ data.tar.gz: d79333378e00d3166b9783b25a9e328add9632c8
5
5
  SHA512:
6
- metadata.gz: 3509b925b64fa53568bf045d1061acc1c7cae2325f61b79c06190895594b1d0cef8e3c6229c13c07f3e5501a61ed5c8332bf011e3c7716fb4a92233b653c05be
7
- data.tar.gz: 688aa82798d649fee8caaa94f66d387323a4a4fe0cf2ef8255e09ff0aab15da60f39a492751be98c95be8931ae95c771fbb79b6b14449e614441293809025eed
6
+ metadata.gz: 99c6e5bc7b2979a903e2ef2dbb09461a1eeaa9b6b853589dbac45b5a7946572b79f9e2b8239b33f5ad5e76994f483edb93a7c4e7be79e1d4653949f432da3e61
7
+ data.tar.gz: c9fdca238b8a0d0feaab1ea033479cc2e06cd6f2e1cd66f9435820fa63769bc88df71a9843b49b93700c7886196d5c7454e5c87ffe8ff71d86ce697413a4f80e
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 Michael Dippery <michael@monkey-robot.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/homophone.gemspec CHANGED
@@ -33,10 +33,11 @@ other artists that are similar to a given artist.
33
33
 
34
34
  spec.add_runtime_dependency('httparty', '~> 0.13.7')
35
35
  spec.add_runtime_dependency('json', '~> 1.8')
36
+ spec.add_runtime_dependency('slop', '~> 4.3')
36
37
 
37
38
  spec.add_development_dependency('aruba', '~> 0.14')
38
39
  spec.add_development_dependency('cucumber', '~> 2.3')
39
40
  spec.add_development_dependency('rspec', '~> 3.4')
40
41
  spec.add_development_dependency('vcr', '~> 3.0')
41
- spec.add_development_dependency('webmock', '~> 1.24')
42
+ spec.add_development_dependency('webmock', '~> 2.0')
42
43
  end
@@ -1,3 +1,4 @@
1
+ require 'slop'
1
2
  require 'homophone/version'
2
3
 
3
4
  module Homophone
@@ -8,16 +9,40 @@ module Homophone
8
9
  end
9
10
 
10
11
  class Application
12
+ def initialize
13
+ @show_genre = false
14
+ end
15
+
11
16
  def run(argv)
12
- onoe 127, 'no musician name provided' if argv.count < 1
13
- ohai "homophone v#{Homophone::VERSION}" if argv[0] == '--version'
17
+ opts = Slop.parse do |o|
18
+ o.banner = 'Usage: homophone [-g] ARTIST'
19
+ o.separator ''
20
+ o.separator 'Options:'
21
+
22
+ o.bool '-g', '--genre', 'Show artist genres'
23
+
24
+ o.on '-h', '--help' do
25
+ ohai o
26
+ end
27
+
28
+ o.on '--version' do
29
+ ohai "homophone v#{Homophone::VERSION}"
30
+ end
31
+ end
32
+
33
+ musician_name = opts.arguments.shift
34
+ onoe 127, 'No musician name provided' unless musician_name
35
+
36
+ @show_genre = opts.genre?
14
37
 
15
- musician_name = argv.shift
16
38
  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
39
+ onoe 126, %Q{No musician with name "#{musician_name}" found} if musician.nil?
40
+
41
+ puts "#{formatter.format(musician)}:\n\n" if show_genre?
42
+
43
+ artists = musician.related_artists.sort_by(&:name)
19
44
  artists.each do |artist|
20
- puts artist
45
+ puts formatter.format(artist)
21
46
  end
22
47
  end
23
48
 
@@ -25,13 +50,22 @@ module Homophone
25
50
  @service ||= (cucumber? ? Homophone::Service::DummySpotify : Homophone::Service::Spotify).new
26
51
  end
27
52
 
53
+ def show_genre?
54
+ !!@show_genre
55
+ end
56
+
57
+ def formatter
58
+ opts = {:show_genre => show_genre?}
59
+ @formatter ||= Homophone::Formatter::ConsoleFormatter.new(opts)
60
+ end
61
+
28
62
  def ohai(msg)
29
63
  puts msg
30
64
  exit 0
31
65
  end
32
66
 
33
67
  def onoe(exit_code, msg)
34
- STDERR.puts "homophone: #{msg}"
68
+ STDERR.puts msg
35
69
  exit exit_code
36
70
  end
37
71
 
@@ -0,0 +1,21 @@
1
+ module Homophone
2
+ module Formatter
3
+ class ConsoleFormatter
4
+ def initialize(opts = {})
5
+ @show_genre = !!opts[:show_genre]
6
+ end
7
+
8
+ def format(artist)
9
+ if show_genre?
10
+ "#{artist.name} (#{artist.genres.join(', ')})".sub(/ \(\)/, '')
11
+ else
12
+ artist.name
13
+ end
14
+ end
15
+
16
+ def show_genre?
17
+ @show_genre
18
+ end
19
+ end
20
+ end
21
+ end
@@ -30,19 +30,9 @@ module Homophone
30
30
 
31
31
  def get(url)
32
32
  uri = URI(url)
33
+ params = begin CGI::parse(uri.query) rescue nil end
33
34
  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
35
+ path = cassette_path(path_parts, params)
46
36
  raise ArgumentError, "No cassette for #{url}" unless path
47
37
  path = File.join(source_path, "#{path}.yml")
48
38
  JSON.load(YAML.load(IO.read(path))['http_interactions'][0]['response']['body']['string'])
@@ -53,16 +43,30 @@ module Homophone
53
43
  def source_path
54
44
  File.join(File.dirname(__FILE__), '..', '..', 'features', 'fixtures', 'cassettes')
55
45
  end
46
+
47
+ def cassette_path(components, params)
48
+ case components.first
49
+ when 'search'
50
+ type = params['type'].first
51
+ name = params['q'].first.gsub(/[+ ]/, '_')
52
+ "search/#{type}/#{name}"
53
+ when 'artists'
54
+ "artists/#{components.last}/#{components[1]}"
55
+ else
56
+ nil
57
+ end
58
+ end
56
59
  end
57
60
  end
58
61
 
59
62
  class Musician
60
- attr_reader :spotify_id, :name
63
+ attr_reader :spotify_id, :name, :genres
61
64
 
62
65
  def initialize(service, blob)
63
66
  @service = service
64
67
  @spotify_id = blob['id']
65
68
  @name = blob['name']
69
+ @genres = blob['genres']
66
70
  end
67
71
 
68
72
  def related_artists
@@ -1,3 +1,3 @@
1
1
  module Homophone
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/homophone.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'homophone/application'
2
+ require 'homophone/formatter'
2
3
  require 'homophone/service'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: homophone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Dippery
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-07 00:00:00.000000000 Z
11
+ date: 2016-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: slop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.3'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: aruba
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +114,14 @@ dependencies:
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '1.24'
117
+ version: '2.0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '1.24'
124
+ version: '2.0'
111
125
  description: |
112
126
  Find related artists for your favorite band. Queries the Spotify API to find
113
127
  other artists that are similar to a given artist.
@@ -120,20 +134,22 @@ extra_rdoc_files: []
120
134
  files:
121
135
  - ".gitignore"
122
136
  - Gemfile
137
+ - LICENSE
123
138
  - Rakefile
124
139
  - exe/homophone
125
140
  - homophone.gemspec
126
141
  - lib/homophone.rb
127
142
  - lib/homophone/application.rb
143
+ - lib/homophone/formatter.rb
128
144
  - lib/homophone/service.rb
129
145
  - lib/homophone/version.rb
130
146
  homepage: https://github.com/mdippery/homophone
131
147
  licenses:
132
148
  - MIT
133
149
  metadata:
134
- build_date: 2016-04-06 19:32:51 PDT
135
- commit: v1.0.0
136
- commit_hash: 3f64945aa6d8860cc6675ce0bb4496c13fcd6e4c
150
+ build_date: 2016-05-04 19:08:25 PDT
151
+ commit: v1.1.0
152
+ commit_hash: 46d49fa0f0f6cdd3e9f5ba1c763c0fb34d252803
137
153
  post_install_message:
138
154
  rdoc_options: []
139
155
  require_paths: