amazon-album-art 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -4
- data/Gemfile.lock +9 -0
- data/VERSION +1 -1
- data/amazon-album-art.gemspec +8 -2
- data/lib/amazon-album-art/client.rb +25 -15
- data/test/helper.rb +2 -3
- data/test/test_amazon-album-art.rb +60 -50
- metadata +37 -7
data/Gemfile
CHANGED
@@ -3,10 +3,6 @@ source "http://rubygems.org"
|
|
3
3
|
# Example:
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
5
|
|
6
|
-
# gem 'nokogiri', '>= 1.4.4'
|
7
|
-
# gem 'sucker', '>= 1.1.4'
|
8
|
-
|
9
|
-
|
10
6
|
# Add dependencies to develop your gem here.
|
11
7
|
# Include everything needed to run rake, tests, features, etc.
|
12
8
|
group :development do
|
@@ -14,4 +10,6 @@ group :development do
|
|
14
10
|
gem "bundler", "~> 1.0.0"
|
15
11
|
gem "jeweler", "~> 1.5.2"
|
16
12
|
gem "rcov", ">= 0"
|
13
|
+
gem 'nokogiri', '>= 1.4.4'
|
14
|
+
gem 'sucker', '>= 1.1.4'
|
17
15
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
activesupport (3.0.3)
|
5
|
+
curb (0.7.9)
|
4
6
|
git (1.2.5)
|
5
7
|
jeweler (1.5.2)
|
6
8
|
bundler (~> 1.0.0)
|
7
9
|
git (>= 1.2.5)
|
8
10
|
rake
|
11
|
+
nokogiri (1.4.4)
|
9
12
|
rake (0.8.7)
|
10
13
|
rcov (0.9.9)
|
11
14
|
shoulda (2.11.3)
|
15
|
+
sucker (1.1.4)
|
16
|
+
activesupport (>= 2.3.2)
|
17
|
+
curb (~> 0.7.0)
|
18
|
+
nokogiri (~> 1.4.0)
|
12
19
|
|
13
20
|
PLATFORMS
|
14
21
|
ruby
|
@@ -16,5 +23,7 @@ PLATFORMS
|
|
16
23
|
DEPENDENCIES
|
17
24
|
bundler (~> 1.0.0)
|
18
25
|
jeweler (~> 1.5.2)
|
26
|
+
nokogiri (>= 1.4.4)
|
19
27
|
rcov
|
20
28
|
shoulda
|
29
|
+
sucker (>= 1.1.4)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/amazon-album-art.gemspec
CHANGED
@@ -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.
|
8
|
+
s.version = "0.3.0"
|
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-
|
12
|
+
s.date = %q{2011-01-17}
|
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 = [
|
@@ -49,6 +49,8 @@ Gem::Specification.new do |s|
|
|
49
49
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
50
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
51
51
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<nokogiri>, [">= 1.4.4"])
|
53
|
+
s.add_development_dependency(%q<sucker>, [">= 1.1.4"])
|
52
54
|
s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.4"])
|
53
55
|
s.add_runtime_dependency(%q<sucker>, [">= 1.1.4"])
|
54
56
|
else
|
@@ -58,6 +60,8 @@ Gem::Specification.new do |s|
|
|
58
60
|
s.add_dependency(%q<rcov>, [">= 0"])
|
59
61
|
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
60
62
|
s.add_dependency(%q<sucker>, [">= 1.1.4"])
|
63
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
64
|
+
s.add_dependency(%q<sucker>, [">= 1.1.4"])
|
61
65
|
end
|
62
66
|
else
|
63
67
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
@@ -66,6 +70,8 @@ Gem::Specification.new do |s|
|
|
66
70
|
s.add_dependency(%q<rcov>, [">= 0"])
|
67
71
|
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
68
72
|
s.add_dependency(%q<sucker>, [">= 1.1.4"])
|
73
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
74
|
+
s.add_dependency(%q<sucker>, [">= 1.1.4"])
|
69
75
|
end
|
70
76
|
end
|
71
77
|
|
@@ -34,15 +34,18 @@ module AmazonAlbumArt
|
|
34
34
|
results = @worker.get
|
35
35
|
|
36
36
|
# Make sure nothing went awry.
|
37
|
-
|
37
|
+
check_response(results, "Error finding album")
|
38
38
|
|
39
39
|
# Now parse it.
|
40
40
|
results.map("Item") do |match|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
begin
|
42
|
+
attribs = match['ItemAttributes']
|
43
|
+
# grab values that were returned
|
44
|
+
found_artist, found_album = (attribs['Artist'] ||= attribs['Author'] ||= (attribs.has_key?("Creator") ? attribs["Creator"]["__content__"] : "")), match['ItemAttributes']['Title']
|
45
|
+
rescue StandardError => bang
|
46
|
+
# getting unhandled error from Sucker in some cases
|
47
|
+
next
|
48
|
+
end
|
46
49
|
# check to see if we have a reasonable match
|
47
50
|
next unless !found_album.blank? && !found_artist.blank? && matches?(album, found_album) && matches?(artist, found_artist)
|
48
51
|
|
@@ -61,22 +64,16 @@ module AmazonAlbumArt
|
|
61
64
|
images = @worker.get
|
62
65
|
|
63
66
|
# Make sure nothing went awry.
|
64
|
-
|
67
|
+
check_response(results, "Error finding images")
|
65
68
|
|
66
69
|
# parse response
|
67
70
|
doc = Nokogiri::XML.parse(images.body)
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
# build the hash with requested values
|
72
|
-
sizes.each do |size|
|
73
|
-
urls.merge!({ size => doc.css("Item > ImageSets > ImageSet[@Category=\"primary\"] > #{size.to_s.capitalize}Image > URL").text })
|
74
|
-
end
|
75
|
-
|
76
|
-
return { :artist => found_artist, :album => found_album, :images => urls }
|
72
|
+
return { :artist => found_artist, :album => found_album, :images => load_images(doc, sizes) }
|
77
73
|
end
|
78
74
|
end
|
79
75
|
|
76
|
+
private
|
80
77
|
def matches?(s1, s2, tolerance = 2)
|
81
78
|
s1 == s2 ||
|
82
79
|
s1 =~ /#{Regexp.escape s2}/i ||
|
@@ -103,6 +100,19 @@ module AmazonAlbumArt
|
|
103
100
|
end
|
104
101
|
return x
|
105
102
|
end
|
103
|
+
|
104
|
+
def load_images(doc, sizes)
|
105
|
+
# build the hash with requested values
|
106
|
+
{}.tap do |urls|
|
107
|
+
sizes.each do |size|
|
108
|
+
urls.merge!({ size => doc.css("Item > ImageSets > ImageSet[@Category=\"primary\"] > #{size.to_s.capitalize}Image > URL").text })
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def check_response(results, msg)
|
114
|
+
raise AmazonAlbumArtError.new(msg) unless results.valid? || results.find("Error").size > 0
|
115
|
+
end
|
106
116
|
end
|
107
117
|
|
108
118
|
class AmazonAlbumArtError < StandardError
|
data/test/helper.rb
CHANGED
@@ -2,65 +2,75 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestAmazonAlbumArt < Test::Unit::TestCase
|
4
4
|
context "amazon-album-art module" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
5
|
+
should "create a new client" do
|
6
|
+
c = AmazonAlbumArt.new(api_key, secret_key)
|
7
|
+
assert_equal AmazonAlbumArt::Client, c.class
|
9
8
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
should "return a hash" do
|
20
|
-
assert_kind_of Hash, @result
|
21
|
-
end
|
22
|
-
should "include the found artists name" do
|
23
|
-
assert_equal "Phish", @result[:artist]
|
24
|
-
end
|
25
|
-
should "include the found artists name" do
|
26
|
-
assert_equal "Rift", @result[:album]
|
27
|
-
end
|
28
|
-
should "include an images key" do
|
29
|
-
assert @result.has_key?(:images)
|
30
|
-
end
|
31
|
-
setup do
|
32
|
-
@images = @result[:images]
|
33
|
-
end
|
34
|
-
should "include include all image sizes" do
|
35
|
-
[:swatch, :small, :thumbnail, :tiny, :medium, :large].each do |key|
|
36
|
-
assert @images.has_key?(key)
|
37
|
-
end
|
38
|
-
end
|
9
|
+
end
|
10
|
+
context "using the amazon-amazon-art client" do
|
11
|
+
setup do
|
12
|
+
@client = AmazonAlbumArt.new(api_key, secret_key)
|
13
|
+
end
|
14
|
+
context "search for known items" do
|
15
|
+
context "and for all images sizes" do
|
16
|
+
setup do
|
17
|
+
@result = @client.search("phish", "rift")
|
39
18
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
19
|
+
should "return a hash" do
|
20
|
+
assert_kind_of Hash, @result
|
21
|
+
end
|
22
|
+
should "include the found artists name" do
|
23
|
+
assert_equal "Phish", @result[:artist]
|
24
|
+
end
|
25
|
+
should "include the found artists name" do
|
26
|
+
assert_equal "Rift", @result[:album]
|
27
|
+
end
|
28
|
+
should "include an images key" do
|
29
|
+
assert @result.has_key?(:images)
|
30
|
+
end
|
31
|
+
setup do
|
32
|
+
@images = @result[:images]
|
33
|
+
end
|
34
|
+
should "include include all image sizes" do
|
35
|
+
[:swatch, :small, :thumbnail, :tiny, :medium, :large].each do |key|
|
36
|
+
assert @images.has_key?(key)
|
48
37
|
end
|
49
38
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
39
|
+
end
|
40
|
+
context "and just a medium search" do
|
41
|
+
setup do
|
42
|
+
@result = @client.search("phish", "rift", [:medium])
|
43
|
+
end
|
44
|
+
context "just a medium image" do
|
45
|
+
should "include a medium image url" do
|
46
|
+
assert_equal "http://ecx.images-amazon.com/images/I/511RmbQV7dL._SL160_.jpg", @result[:images][:medium]
|
55
47
|
end
|
56
48
|
end
|
57
49
|
end
|
58
50
|
end
|
59
|
-
context "
|
60
|
-
|
61
|
-
|
62
|
-
|
51
|
+
context "search for problematic items" do
|
52
|
+
setup do
|
53
|
+
@result = @client.search("Mya", "A Cinderella Story")
|
54
|
+
end
|
55
|
+
context "found something for mya" do
|
56
|
+
should "not be nil" do
|
57
|
+
assert_not_nil @result
|
58
|
+
end
|
59
|
+
end
|
60
|
+
context "no search values" do
|
61
|
+
should "raise an ArgumentError" do
|
62
|
+
assert_raise ArgumentError do
|
63
|
+
@client.search
|
64
|
+
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
68
|
+
end
|
69
|
+
context "no keys" do
|
70
|
+
should "raise an ArgumentError" do
|
71
|
+
assert_raise ArgumentError do
|
72
|
+
AmazonAlbumArt.new
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
66
76
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
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
|
+
date: 2011-01-17 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -85,7 +85,7 @@ dependencies:
|
|
85
85
|
- 4
|
86
86
|
- 4
|
87
87
|
version: 1.4.4
|
88
|
-
type: :
|
88
|
+
type: :development
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: *id005
|
91
91
|
- !ruby/object:Gem::Dependency
|
@@ -100,9 +100,39 @@ dependencies:
|
|
100
100
|
- 1
|
101
101
|
- 4
|
102
102
|
version: 1.1.4
|
103
|
-
type: :
|
103
|
+
type: :development
|
104
104
|
prerelease: false
|
105
105
|
version_requirements: *id006
|
106
|
+
- !ruby/object:Gem::Dependency
|
107
|
+
name: nokogiri
|
108
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
segments:
|
114
|
+
- 1
|
115
|
+
- 4
|
116
|
+
- 4
|
117
|
+
version: 1.4.4
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: *id007
|
121
|
+
- !ruby/object:Gem::Dependency
|
122
|
+
name: sucker
|
123
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
segments:
|
129
|
+
- 1
|
130
|
+
- 1
|
131
|
+
- 4
|
132
|
+
version: 1.1.4
|
133
|
+
type: :runtime
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: *id008
|
106
136
|
description: A specialized Amazon AWS gem for finding Album Art running on top of the 'sucker' gem
|
107
137
|
email: john@threedogconsulting.com
|
108
138
|
executables: []
|
@@ -139,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
169
|
requirements:
|
140
170
|
- - ">="
|
141
171
|
- !ruby/object:Gem::Version
|
142
|
-
hash: -
|
172
|
+
hash: -2297918951107509842
|
143
173
|
segments:
|
144
174
|
- 0
|
145
175
|
version: "0"
|