amazon-album-art 0.3.0 → 0.3.1

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.
data/Gemfile CHANGED
@@ -12,4 +12,5 @@ group :development do
12
12
  gem "rcov", ">= 0"
13
13
  gem 'nokogiri', '>= 1.4.4'
14
14
  gem 'sucker', '>= 1.1.4'
15
+ gem 'json'
15
16
  end
data/Gemfile.lock CHANGED
@@ -8,6 +8,7 @@ GEM
8
8
  bundler (~> 1.0.0)
9
9
  git (>= 1.2.5)
10
10
  rake
11
+ json (1.4.6)
11
12
  nokogiri (1.4.4)
12
13
  rake (0.8.7)
13
14
  rcov (0.9.9)
@@ -23,6 +24,7 @@ PLATFORMS
23
24
  DEPENDENCIES
24
25
  bundler (~> 1.0.0)
25
26
  jeweler (~> 1.5.2)
27
+ json
26
28
  nokogiri (>= 1.4.4)
27
29
  rcov
28
30
  shoulda
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{amazon-album-art}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Allen"]
12
- s.date = %q{2011-01-17}
12
+ s.date = %q{2011-01-20}
13
13
  s.description = %q{A specialized Amazon AWS gem for finding Album Art running on top of the 'sucker' gem}
14
14
  s.email = %q{john@threedogconsulting.com}
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "amazon-album-art.gemspec",
28
28
  "lib/amazon-album-art.rb",
29
29
  "lib/amazon-album-art/client.rb",
30
+ "test/fixtures/albums.json",
30
31
  "test/helper.rb",
31
32
  "test/test_amazon-album-art.rb"
32
33
  ]
@@ -51,6 +52,7 @@ Gem::Specification.new do |s|
51
52
  s.add_development_dependency(%q<rcov>, [">= 0"])
52
53
  s.add_development_dependency(%q<nokogiri>, [">= 1.4.4"])
53
54
  s.add_development_dependency(%q<sucker>, [">= 1.1.4"])
55
+ s.add_development_dependency(%q<json>, [">= 0"])
54
56
  s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.4"])
55
57
  s.add_runtime_dependency(%q<sucker>, [">= 1.1.4"])
56
58
  else
@@ -60,6 +62,7 @@ Gem::Specification.new do |s|
60
62
  s.add_dependency(%q<rcov>, [">= 0"])
61
63
  s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
62
64
  s.add_dependency(%q<sucker>, [">= 1.1.4"])
65
+ s.add_dependency(%q<json>, [">= 0"])
63
66
  s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
64
67
  s.add_dependency(%q<sucker>, [">= 1.1.4"])
65
68
  end
@@ -70,6 +73,7 @@ Gem::Specification.new do |s|
70
73
  s.add_dependency(%q<rcov>, [">= 0"])
71
74
  s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
72
75
  s.add_dependency(%q<sucker>, [">= 1.1.4"])
76
+ s.add_dependency(%q<json>, [">= 0"])
73
77
  s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
74
78
  s.add_dependency(%q<sucker>, [">= 1.1.4"])
75
79
  end
@@ -22,6 +22,9 @@ module AmazonAlbumArt
22
22
  def search(artist, album, sizes = [:swatch, :small, :thumbnail, :tiny, :medium, :large])
23
23
  raise ArgumentError.new("An artist and album are required to search") if artist.blank? || album.blank?
24
24
 
25
+ # clean up params, this client may be used repeatedly
26
+ clean_params(%w{IdType ResponseGroup ItemId})
27
+
25
28
  # Prepare a request.
26
29
  @worker << {
27
30
  "Operation" => "ItemSearch",
@@ -34,23 +37,24 @@ module AmazonAlbumArt
34
37
  results = @worker.get
35
38
 
36
39
  # Make sure nothing went awry.
37
- check_response(results, "Error finding album")
40
+ return nil if !check_response?(results, "Error finding album")
38
41
 
39
42
  # Now parse it.
40
43
  results.map("Item") do |match|
41
44
  begin
42
45
  attribs = match['ItemAttributes']
43
46
  # grab values that were returned
44
- found_artist, found_album = (attribs['Artist'] ||= attribs['Author'] ||= (attribs.has_key?("Creator") ? attribs["Creator"]["__content__"] : "")), match['ItemAttributes']['Title']
47
+ found_artist, found_album = load_artist(attribs), load_album(attribs)
45
48
  rescue StandardError => bang
46
- # getting unhandled error from Sucker in some cases
49
+ # handled error from Sucker in some cases
47
50
  next
48
51
  end
49
52
  # check to see if we have a reasonable match
50
53
  next unless !found_album.blank? && !found_artist.blank? && matches?(album, found_album) && matches?(artist, found_artist)
51
54
 
52
55
  # remove params not used for image search
53
- @worker.parameters.delete_if { |k,v| %w{SearchIndex Title Artist}.include? k }
56
+ # @worker.parameters.delete_if { |k,v| %w{SearchIndex Title Artist}.include? k }
57
+ clean_params(%w{SearchIndex Title Artist})
54
58
 
55
59
  # fetch images
56
60
  @worker << {
@@ -64,13 +68,15 @@ module AmazonAlbumArt
64
68
  images = @worker.get
65
69
 
66
70
  # Make sure nothing went awry.
67
- check_response(results, "Error finding images")
71
+ return nil if !check_response?(results, "Error finding images")
68
72
 
69
73
  # parse response
70
74
  doc = Nokogiri::XML.parse(images.body)
71
75
 
72
76
  return { :artist => found_artist, :album => found_album, :images => load_images(doc, sizes) }
73
77
  end
78
+
79
+ return nil # nothing found
74
80
  end
75
81
 
76
82
  private
@@ -101,6 +107,24 @@ module AmazonAlbumArt
101
107
  return x
102
108
  end
103
109
 
110
+ def clean_params(params)
111
+ # remove given params so worker can be reused
112
+ @worker.parameters.delete_if { |k,v| params.include? k }
113
+ end
114
+
115
+ def load_artist(attribs)
116
+ # found artists are returned in many different permutations
117
+ return attribs['Artist'] if attribs.has_key?('Artist')
118
+ return attribs['Author'] if attribs.has_key?('Author')
119
+ return attribs['Creator'].map { |item| item["__content__"] if item.has_key?("__content__") }.join(" and ") if attribs.has_key?("Creator") && attribs['Creator'].is_a?(Array)
120
+ return attribs["Creator"]["__content__"] if attribs.has_key?("Creator") && attribs["Creator"].has_key?('__content__')
121
+ return nil
122
+ end
123
+
124
+ def load_album(attribs)
125
+ attribs.has_key?('Title') ? attribs['Title'] : ""
126
+ end
127
+
104
128
  def load_images(doc, sizes)
105
129
  # build the hash with requested values
106
130
  {}.tap do |urls|
@@ -110,8 +134,9 @@ module AmazonAlbumArt
110
134
  end
111
135
  end
112
136
 
113
- def check_response(results, msg)
114
- raise AmazonAlbumArtError.new(msg) unless results.valid? || results.find("Error").size > 0
137
+ def check_response?(results, msg)
138
+ # raise AmazonAlbumArtError.new(msg) unless results.valid? || results.find("Error").size > 0
139
+ results.valid? || results.find("Error").size == 0
115
140
  end
116
141
  end
117
142
 
@@ -0,0 +1,101 @@
1
+ [{"artist":"Rihanna", "album":"A Girl Like Me"},
2
+ {"artist":"Swing Out Sister", "album":"20th Century Masters - The Millennium Collection: The Best Of Swing Out Sister"},
3
+ {"artist":"Eddie Kendricks", "album":"20th Century Masters: The Millenium Collection"},
4
+ {"artist":"Brainstorm", "album":"54: Music From The Miramax Motion Picture, Vol. 2"},
5
+ {"artist":"Edgar Winter Group", "album":"70's Pop Hits"},
6
+ {"artist":"Collective Soul", "album":"7even Year Itch: Greatest Hits, 1994-2001"},
7
+ {"artist":"Breakfast Club", "album":"'80s Hits Back Vol. 3"},
8
+ {"artist":"Billy Squier", "album":"80's Rock, Vol. 1"},
9
+ {"artist":"Hilary Duff And Haylie Duff", "album":"A Cinderella Story"},
10
+ {"artist":"Mya", "album":"A Cinderella Story"},
11
+ {"artist":"Snow Patrol", "album":"A Hundred Million Suns"},
12
+ {"artist":"Jonas Brothers", "album":"A Little Bit Longer"},
13
+ {"artist":"Don Henley", "album":"Actual Miles: Henley's Greatest Hits"},
14
+ {"artist":"Lisa Stansfield", "album":"Affection"},
15
+ {"artist":"Tower Of Power", "album":"Ain't Nothin' Stoppin' Us Now"},
16
+ {"artist":"Al Green", "album":"Al Green's Greatest Hits"},
17
+ {"artist":"Sum 41", "album":"All Killer No Filler"},
18
+ {"artist":"Smash Mouth", "album":"All Star Smash Hits"},
19
+ {"artist":"Santana feat. Michelle Branch And The Wreckers", "album":"All That I Am"},
20
+ {"artist":"Killers", "album":"All These Things That I've Done"},
21
+ {"artist":"Crystal Waters", "album":"All Ultimate Dance"},
22
+ {"artist":"Josh Kelley", "album":"Almost Honest"},
23
+ {"artist":"Al Stewart", "album":"American Woman And Other Hits Of The '70s"},
24
+ {"artist":"Real McCoy", "album":"Another Night"},
25
+ {"artist":"Guns N' Roses", "album":"Appetite For Destruction"},
26
+ {"artist":"Bodyrockers", "album":"Aquamarine: Music From The Motion Picture"},
27
+ {"artist":"Barenaked Ladies", "album":"Are Me"},
28
+ {"artist":"Aretha Franklin", "album":"Aretha's Best"},
29
+ {"artist":"Aretha Franklin and George Michael", "album":"Aretha's Best"},
30
+ {"artist":"Stevie Wonder", "album":"At The Close Of A Century"},
31
+ {"artist":"Average White Band", "album":"AWB"},
32
+ {"artist":"Lenny Kravitz", "album":"Baptism"},
33
+ {"artist":"Nick Lowe", "album":"Basher: The Best of Nick Lowe"},
34
+ {"artist":"English Beat", "album":"Beat This!: The Best Of The English Beat"},
35
+ {"artist":"Jesse McCartney", "album":"Beautiful Soul"},
36
+ {"artist":"Big Mountain", "album":"Best of Big Mountain"},
37
+ {"artist":"Blur", "album":"Best of Blur"},
38
+ {"artist":"David Bowie", "album":"Best Of Bowie"},
39
+ {"artist":"David Bowie and Mick Jagger", "album":"Best Of Bowie"},
40
+ {"artist":"Brothers Johnson", "album":"Best Of Brothers Johnson"},
41
+ {"artist":"En Vogue", "album":"Best Of En Vogue"},
42
+ {"artist":"Pablo Cruise", "album":"Best Of Pablo Cruise"},
43
+ {"artist":"Ziggy Marley And The Melody Makers", "album":"Best of Ziggy Marley and the Melody Makers (1988-1993)"},
44
+ {"artist":"Van Halen", "album":"Best Of, Vol. 1"},
45
+ {"artist":"Outfield", "album":"Big Innings: Best Of The Outfield"},
46
+ {"artist":"Atlantic Starr", "album":"Billboard Hot R&B Hits: 1982"},
47
+ {"artist":"Brothers Johnson", "album":"Billboard Top Dance Hits - 1980"},
48
+ {"artist":"Heatwave", "album":"Billboard Top Hits: 1977"},
49
+ {"artist":"Jackson 5", "album":"Billboard Top Rock 'n' Roll Hits: 1974"},
50
+ {"artist":"Billy Idol", "album":"Billy Idol's Greatest Hits"},
51
+ {"artist":"Alana Davis", "album":"Blame It On Me"},
52
+ {"artist":"Jimmy Eat World", "album":"Bleed American"},
53
+ {"artist":"Blink-182", "album":"Blink-182 Greatest Hits"},
54
+ {"artist":"Boney M", "album":"Boney M - The Greatest Hits"},
55
+ {"artist":"Rick Springfield", "album":"Boogie Nights No. 2: More Music From The Original Motion Picture"},
56
+ {"artist":"Shaggy", "album":"Boombastic"},
57
+ {"artist":"Bonnie Raitt", "album":"Boys On The Side"},
58
+ {"artist":"Sting", "album":"Brand New Day - The Remixes"},
59
+ {"artist":"Kelly Clarkson", "album":"Breakaway"},
60
+ {"artist":"Miley Cyrus", "album":"Breakout"},
61
+ {"artist":"Wallflowers", "album":"Bringing Down The Horse"},
62
+ {"artist":"Raconteurs", "album":"Broken Boy Soldiers"},
63
+ {"artist":"Bachman-Turner Overdrive", "album":"BTO's Greatest"},
64
+ {"artist":"Red Hot Chili Peppers", "album":"By The Way"},
65
+ {"artist":"Marc Broussard", "album":"Carencro"},
66
+ {"artist":"C And C Music Factory", "album":"Casey Kasem Presents America's Top Ten Through The Years: 90s"},
67
+ {"artist":"Gavin DeGraw", "album":"Chariot"},
68
+ {"artist":"Andy Gibb", "album":"Charlie's Angels: Full Throttle"},
69
+ {"artist":"Blackbyrds", "album":"Chart Toppers: Dance Hits of the 70's"},
70
+ {"artist":"Cheap Trick", "album":"Cheap Trick's Greatest Hits"},
71
+ {"artist":"Elton John", "album":"Chicken Soup for the Soul: The Triumph of the Spirit"},
72
+ {"artist":"Christina Aguilera", "album":"Christina Aguilera"},
73
+ {"artist":"James Taylor", "album":"Classic Songs"},
74
+ {"artist":"George Harrison", "album":"Cloud Nine"},
75
+ {"artist":"Heatwave", "album":"Club Epic: A Collection Of Classic Dance Mixes, Vol.1"},
76
+ {"artist":"Jack Johnson", "album":"Curious George: Sing-A-Longs And Lullabies For The Film"},
77
+ {"artist":"Barry White", "album":"Dance Fever : Hits of the 70's"},
78
+ {"artist":"Vicki Sue Robinson", "album":"Dance Floor Divas: The 70's"},
79
+ {"artist":"Phil Collins", "album":"Dance Into The Light"},
80
+ {"artist":"Dan Hartman", "album":"Dancin' 'N' Disco"},
81
+ {"artist":"Daughtry", "album":"Daughtry"},
82
+ {"artist":"Janet Jackson", "album":"Design Of A Decade"},
83
+ {"artist":"Eagle-Eye Cherry", "album":"Desireless"},
84
+ {"artist":"Barenaked Ladies", "album":"Disc One: All Their Greatest Hits"},
85
+ {"artist":"Van Halen", "album":"Diver Down"},
86
+ {"artist":"Donavon Frankenreiter feat. Jack Johnson", "album":"Donavon Frankenreiter"},
87
+ {"artist":"Bobby Brown", "album":"Don't Be Cruel"},
88
+ {"artist":"Replacements", "album":"Don't You Know Who I Think I Was?: The Best Of The Replacements"},
89
+ {"artist":"Doobie Brothers", "album":"Doobie Brothers' Greatest Hits"},
90
+ {"artist":"Green Day", "album":"Dookie"},
91
+ {"artist":"KT Tunstall", "album":"Drastic Fantastic"},
92
+ {"artist":"Corrs", "album":"Dreams: The Ultimate Corrs Collection"},
93
+ {"artist":"Whispers", "album":"Drivin' Soul"},
94
+ {"artist":"Duran Duran", "album":"Duran Duran: Greatest"},
95
+ {"artist":"Eagles", "album":"Eagles Greatest Hits, Vol. 2"},
96
+ {"artist":"Culture Club", "album":"Eighties Complete Vol. #2"},
97
+ {"artist":"R.E.M.", "album":"Eponymous"},
98
+ {"artist":"Clash", "album":"Essential Clash"},
99
+ {"artist":"Eiffel 65", "album":"Europop"},
100
+ {"artist":"Vertical Horizon", "album":"Everything You Want"}
101
+ ]
data/test/helper.rb CHANGED
@@ -14,11 +14,14 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
14
  $LOAD_PATH.unshift(File.dirname(__FILE__))
15
15
  require 'amazon-album-art'
16
16
 
17
- class Test::Unit::TestCase
18
- def api_key
19
- 'api-key'
20
- end
21
- def secret_key
22
- "secret-key"
23
- end
17
+ def api_key
18
+ 'api-key'
19
+ end
20
+ def secret_key
21
+ "secret-key"
22
+ end
23
+ def fixture_file(filename)
24
+ return '' if filename == ''
25
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
26
+ File.read(file_path)
24
27
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Allen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-17 00:00:00 -05:00
17
+ date: 2011-01-20 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -104,8 +104,21 @@ dependencies:
104
104
  prerelease: false
105
105
  version_requirements: *id006
106
106
  - !ruby/object:Gem::Dependency
107
- name: nokogiri
107
+ name: json
108
108
  requirement: &id007 !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: *id007
119
+ - !ruby/object:Gem::Dependency
120
+ name: nokogiri
121
+ requirement: &id008 !ruby/object:Gem::Requirement
109
122
  none: false
110
123
  requirements:
111
124
  - - ">="
@@ -117,10 +130,10 @@ dependencies:
117
130
  version: 1.4.4
118
131
  type: :runtime
119
132
  prerelease: false
120
- version_requirements: *id007
133
+ version_requirements: *id008
121
134
  - !ruby/object:Gem::Dependency
122
135
  name: sucker
123
- requirement: &id008 !ruby/object:Gem::Requirement
136
+ requirement: &id009 !ruby/object:Gem::Requirement
124
137
  none: false
125
138
  requirements:
126
139
  - - ">="
@@ -132,7 +145,7 @@ dependencies:
132
145
  version: 1.1.4
133
146
  type: :runtime
134
147
  prerelease: false
135
- version_requirements: *id008
148
+ version_requirements: *id009
136
149
  description: A specialized Amazon AWS gem for finding Album Art running on top of the 'sucker' gem
137
150
  email: john@threedogconsulting.com
138
151
  executables: []
@@ -153,6 +166,7 @@ files:
153
166
  - amazon-album-art.gemspec
154
167
  - lib/amazon-album-art.rb
155
168
  - lib/amazon-album-art/client.rb
169
+ - test/fixtures/albums.json
156
170
  - test/helper.rb
157
171
  - test/test_amazon-album-art.rb
158
172
  has_rdoc: true
@@ -169,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
183
  requirements:
170
184
  - - ">="
171
185
  - !ruby/object:Gem::Version
172
- hash: -2297918951107509842
186
+ hash: 3587697543368286211
173
187
  segments:
174
188
  - 0
175
189
  version: "0"