metal_archives 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +47 -1
- data/README.md +1 -3
- data/lib/metal_archives/configuration.rb +0 -8
- data/lib/metal_archives/http_client.rb +1 -0
- data/lib/metal_archives/middleware/cache_check.rb +20 -0
- data/lib/metal_archives/middleware/rewrite_endpoint.rb +1 -1
- data/lib/metal_archives/models/artist.rb +3 -3
- data/lib/metal_archives/models/band.rb +1 -1
- data/lib/metal_archives/models/label.rb +28 -4
- data/lib/metal_archives/parsers/artist.rb +12 -2
- data/lib/metal_archives/utils/nil_date.rb +40 -0
- data/lib/metal_archives/version.rb +1 -1
- data/lib/metal_archives.rb +1 -0
- data/spec/configuration_spec.rb +0 -5
- data/spec/models/artist_spec.rb +7 -11
- data/spec/support/metal_archives.rb +2 -4
- data/spec/utils/nil_date_spec.rb +50 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '00870c0edc861f8ff624c887f5a83346e1d2cba6'
|
4
|
+
data.tar.gz: 19f0e38a29a17f35604ae692c5773c8bcee0cede
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2499d481e8719a3913504a826214824b7871004ffabed9661e1bb623510bdc3d4cbd9a80499d8b7a2888d24b0314334d6fb29dad12f033057a23fe2e7bcb7949
|
7
|
+
data.tar.gz: d6825c4a2172caa7b37d3080154e653961c3e456e3018f20b283b286a493064a5401a00348752d3f207fb5af7a1b272df9d9145b136e922e3662b515fe499012
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,51 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 0.0
|
3
|
+
## 1.0.0
|
4
|
+
|
5
|
+
- Add `Artist#photo`
|
6
|
+
- Return URI instead of String for `Artist#photo`, `Band#logo` and `Band#photo`
|
7
|
+
- Allow specifying endpoint
|
8
|
+
- Allow specifying additional Faraday middleware
|
9
|
+
- Implement `NilDate` class allowing year, month or date to be `nil`
|
10
|
+
- Add `#cached?` and `#loaded?`
|
11
|
+
- Add verbose output option
|
12
|
+
- Return `MetalArchives::Errors::TypeError` in certain cases
|
13
|
+
- Migrate tests to RSpec
|
14
|
+
|
15
|
+
## 0.8.0
|
16
|
+
|
17
|
+
- Add configurable endpoint
|
18
|
+
|
19
|
+
## 0.7.0
|
20
|
+
|
21
|
+
- Add `Band#all` and `Artist#all`
|
22
|
+
|
23
|
+
## 0.6.0
|
24
|
+
|
25
|
+
- Add LRU object cache
|
26
|
+
- Remove HTTP cache due to uncacheable response headers
|
27
|
+
- Add `Band#find_by!` and `Artist#find_by!`
|
28
|
+
|
29
|
+
## 0.5.0
|
30
|
+
|
31
|
+
- Fix dependency versions
|
32
|
+
|
33
|
+
## 0.4.0
|
34
|
+
|
35
|
+
- Bubble errors up
|
36
|
+
- Add `find!`
|
37
|
+
|
38
|
+
## 0.3.0
|
39
|
+
|
40
|
+
- Add `Collection` iterator
|
41
|
+
|
42
|
+
## 0.2.1
|
43
|
+
|
44
|
+
- Add correct license
|
45
|
+
- Lock dependency versions
|
46
|
+
|
47
|
+
## 0.2.0
|
48
|
+
|
49
|
+
## 0.1.0
|
4
50
|
|
5
51
|
Initial release
|
data/README.md
CHANGED
@@ -27,8 +27,6 @@ module MetalArchives
|
|
27
27
|
@config = MetalArchives::Configuration.new
|
28
28
|
yield @config
|
29
29
|
|
30
|
-
@config.logger.level = @config.debug ? Logger::DEBUG : Logger::WARN
|
31
|
-
|
32
30
|
raise MetalArchives::Errors::InvalidConfigurationError, 'app_name has not been configured' unless MetalArchives.config.app_name && !MetalArchives.config.app_name.empty?
|
33
31
|
raise MetalArchives::Errors::InvalidConfigurationError, 'app_version has not been configured' unless MetalArchives.config.app_version && !MetalArchives.config.app_version.empty?
|
34
32
|
raise MetalArchives::Errors::InvalidConfigurationError, 'app_contact has not been configured' unless MetalArchives.config.app_contact && !MetalArchives.config.app_contact.empty?
|
@@ -80,11 +78,6 @@ module MetalArchives
|
|
80
78
|
#
|
81
79
|
attr_accessor :logger
|
82
80
|
|
83
|
-
##
|
84
|
-
# Verbose output
|
85
|
-
#
|
86
|
-
attr_accessor :debug
|
87
|
-
|
88
81
|
##
|
89
82
|
# Cache size (per object class)
|
90
83
|
#
|
@@ -98,7 +91,6 @@ module MetalArchives
|
|
98
91
|
@throttle_rate = 1
|
99
92
|
@throttle_wait = 3
|
100
93
|
@logger = Logger.new STDOUT
|
101
|
-
@debug = false
|
102
94
|
@cache_size = 100
|
103
95
|
end
|
104
96
|
end
|
@@ -41,6 +41,7 @@ module MetalArchives
|
|
41
41
|
f.response :logger, MetalArchives.config.logger
|
42
42
|
|
43
43
|
f.use MetalArchives::Middleware::Headers
|
44
|
+
f.use MetalArchives::Middleware::CacheCheck
|
44
45
|
f.use MetalArchives::Middleware::RewriteEndpoint
|
45
46
|
|
46
47
|
MetalArchives.config.middleware.each { |m| f.use m } if MetalArchives.config.middleware
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
|
5
|
+
module MetalArchives
|
6
|
+
module Middleware
|
7
|
+
##
|
8
|
+
# Log cache status
|
9
|
+
#
|
10
|
+
class CacheCheck < Faraday::Response::Middleware # :nodoc:
|
11
|
+
def on_complete(env)
|
12
|
+
return unless MetalArchives.config.endpoint
|
13
|
+
|
14
|
+
if env[:response_headers].has_key? 'x-cache-status'
|
15
|
+
MetalArchives.config.logger.info "Cache #{env[:response_headers]['x-cache-status'].downcase} for #{env.url.to_s}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -68,18 +68,18 @@ module MetalArchives
|
|
68
68
|
# - rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
|
69
69
|
# - rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
|
70
70
|
#
|
71
|
-
property :date_of_birth, :type =>
|
71
|
+
property :date_of_birth, :type => NilDate
|
72
72
|
|
73
73
|
##
|
74
74
|
# :attr_reader: date_of_death
|
75
75
|
#
|
76
|
-
# Returns
|
76
|
+
# Returns rdoc-ref:NilDate
|
77
77
|
#
|
78
78
|
# [Raises]
|
79
79
|
# - rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
|
80
80
|
# - rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
|
81
81
|
#
|
82
|
-
property :date_of_death, :type =>
|
82
|
+
property :date_of_death, :type => NilDate
|
83
83
|
|
84
84
|
##
|
85
85
|
# :attr_reader: cause_of_death
|
@@ -7,19 +7,23 @@ module MetalArchives
|
|
7
7
|
##
|
8
8
|
# Represents a record label
|
9
9
|
#
|
10
|
-
class Label < BaseModel
|
10
|
+
class Label < MetalArchives::BaseModel
|
11
11
|
##
|
12
12
|
# :attr_reader: id
|
13
13
|
#
|
14
14
|
# Returns +Integer+
|
15
15
|
#
|
16
|
-
property :id
|
16
|
+
property :id, :type => Integer
|
17
17
|
|
18
18
|
##
|
19
19
|
# :attr_reader: name
|
20
20
|
#
|
21
21
|
# Returns +String+
|
22
22
|
#
|
23
|
+
# [Raises]
|
24
|
+
# - rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
|
25
|
+
# - rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
|
26
|
+
#
|
23
27
|
property :name
|
24
28
|
|
25
29
|
##
|
@@ -27,6 +31,10 @@ module MetalArchives
|
|
27
31
|
#
|
28
32
|
# Returns multiline +String+
|
29
33
|
#
|
34
|
+
# [Raises]
|
35
|
+
# - rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
|
36
|
+
# - rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
|
37
|
+
#
|
30
38
|
property :address
|
31
39
|
|
32
40
|
##
|
@@ -34,6 +42,10 @@ module MetalArchives
|
|
34
42
|
#
|
35
43
|
# Returns +ISO316::Country+
|
36
44
|
#
|
45
|
+
# [Raises]
|
46
|
+
# - rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
|
47
|
+
# - rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
|
48
|
+
#
|
37
49
|
property :country, :type => ISO3166::Country
|
38
50
|
|
39
51
|
##
|
@@ -41,6 +53,10 @@ module MetalArchives
|
|
41
53
|
#
|
42
54
|
# Returns +String+
|
43
55
|
#
|
56
|
+
# [Raises]
|
57
|
+
# - rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
|
58
|
+
# - rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
|
59
|
+
#
|
44
60
|
property :phone
|
45
61
|
|
46
62
|
##
|
@@ -48,14 +64,22 @@ module MetalArchives
|
|
48
64
|
#
|
49
65
|
# Returns +Array+ of +String+
|
50
66
|
#
|
67
|
+
# [Raises]
|
68
|
+
# - rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
|
69
|
+
# - rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
|
70
|
+
#
|
51
71
|
property :specializations, :multiple => true
|
52
72
|
|
53
73
|
##
|
54
74
|
# :attr_reader: date_founded
|
55
75
|
#
|
56
|
-
# Returns +
|
76
|
+
# Returns +NilDate+
|
77
|
+
#
|
78
|
+
# [Raises]
|
79
|
+
# - rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
|
80
|
+
# - rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
|
57
81
|
#
|
58
|
-
property :date_founded, :type =>
|
82
|
+
property :date_founded, :type => NilDate
|
59
83
|
|
60
84
|
##
|
61
85
|
# :attr_reader: sub_labels
|
@@ -58,9 +58,19 @@ module MetalArchives
|
|
58
58
|
props[:name] = content
|
59
59
|
when 'Age:'
|
60
60
|
date = content.strip.gsub(/[0-9]* *\(born ([^\)]*)\)/, '\1')
|
61
|
-
|
61
|
+
begin
|
62
|
+
props[:date_of_birth] = NilDate.parse date
|
63
|
+
rescue MetalArchives::Errors::ArgumentError => e
|
64
|
+
dob = Date.parse date
|
65
|
+
props[:date_of_birth] = NilDate.new dob.year, dob.month, dob.day
|
66
|
+
end
|
62
67
|
when 'R.I.P.:'
|
63
|
-
|
68
|
+
begin
|
69
|
+
dod = Date.parse content
|
70
|
+
props[:date_of_death] = NilDate.new dod.year, dod.month, dod.day
|
71
|
+
rescue ArgumentError => e
|
72
|
+
props[:date_of_death] = NilDate.parse content
|
73
|
+
end
|
64
74
|
when 'Died of:'
|
65
75
|
props[:cause_of_death] = content
|
66
76
|
when 'Place of origin:'
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'date'
|
4
|
+
|
3
5
|
module MetalArchives
|
4
6
|
##
|
5
7
|
# Date with nullable year, month and day
|
@@ -7,6 +9,8 @@ module MetalArchives
|
|
7
9
|
# WARNING: No validation on actual date is performed
|
8
10
|
#
|
9
11
|
class NilDate
|
12
|
+
include Comparable
|
13
|
+
|
10
14
|
attr_accessor :year, :month, :day
|
11
15
|
|
12
16
|
def initialize(year = nil, month = nil, day = nil)
|
@@ -50,5 +54,41 @@ module MetalArchives
|
|
50
54
|
rescue
|
51
55
|
raise MetalArchives::Errors::ArgumentError, 'invalid date'
|
52
56
|
end
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
year = (@year || 0).to_s.rjust 2, '0'
|
60
|
+
month = (@month || 0).to_s.rjust 2, '0'
|
61
|
+
day = (@day || 0).to_s.rjust 2, '0'
|
62
|
+
|
63
|
+
"#{year}-#{month}-#{day}"
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Comparison operator
|
68
|
+
#
|
69
|
+
def <=>(other)
|
70
|
+
return nil if other.nil?
|
71
|
+
|
72
|
+
# Return nil if one of the two years is nil
|
73
|
+
return nil if (@year.nil? && !other.year.nil?) || !@year.nil? && other.year.nil?
|
74
|
+
|
75
|
+
# Return nil if one of the two months is nil
|
76
|
+
return nil if (@month.nil? && !other.month.nil?) || !@month.nil? && other.month.nil?
|
77
|
+
|
78
|
+
# Return nil if one of the two months is nil
|
79
|
+
return nil if (@day.nil? && !other.day.nil?) || !@day.nil? && other.day.nil?
|
80
|
+
|
81
|
+
comp_year = @year <=> other.year
|
82
|
+
if comp_year == 0
|
83
|
+
comp_month = @month <=> other.month
|
84
|
+
if comp_month == 0
|
85
|
+
return @day <=> other.day
|
86
|
+
else
|
87
|
+
return comp_month
|
88
|
+
end
|
89
|
+
else
|
90
|
+
comp_year
|
91
|
+
end
|
92
|
+
end
|
53
93
|
end
|
54
94
|
end
|
data/lib/metal_archives.rb
CHANGED
data/spec/configuration_spec.rb
CHANGED
@@ -20,8 +20,6 @@ RSpec.describe MetalArchives::Configuration do
|
|
20
20
|
expect(subject).to respond_to :request_timeout=
|
21
21
|
expect(subject).to respond_to :logger
|
22
22
|
expect(subject).to respond_to :logger=
|
23
|
-
expect(subject).to respond_to :debug
|
24
|
-
expect(subject).to respond_to :debug=
|
25
23
|
expect(subject).to respond_to :cache_size
|
26
24
|
expect(subject).to respond_to :cache_size=
|
27
25
|
end
|
@@ -29,7 +27,6 @@ RSpec.describe MetalArchives::Configuration do
|
|
29
27
|
it 'has default properties' do
|
30
28
|
expect(subject.default_endpoint).to eq 'https://www.metal-archives.com/'
|
31
29
|
expect(subject.logger).not_to be_nil
|
32
|
-
expect(subject.debug).to be false
|
33
30
|
expect(subject.cache_size).to be_an Integer
|
34
31
|
end
|
35
32
|
|
@@ -37,12 +34,10 @@ RSpec.describe MetalArchives::Configuration do
|
|
37
34
|
subject.endpoint = 'http://my-proxy.com/'
|
38
35
|
logger = Logger.new STDERR
|
39
36
|
subject.logger = logger
|
40
|
-
subject.debug = true
|
41
37
|
subject.cache_size = 0
|
42
38
|
|
43
39
|
expect(subject.endpoint).to eq 'http://my-proxy.com/'
|
44
40
|
expect(subject.logger).to be logger
|
45
|
-
expect(subject.debug).to be true
|
46
41
|
expect(subject.cache_size).to eq 0
|
47
42
|
end
|
48
43
|
end
|
data/spec/models/artist_spec.rb
CHANGED
@@ -11,7 +11,7 @@ RSpec.describe MetalArchives::Artist do
|
|
11
11
|
expect(artist.aliases).to be_empty
|
12
12
|
expect(artist.country).to eq ISO3166::Country['ES']
|
13
13
|
expect(artist.location).to eq 'Oviedo, Asturias'
|
14
|
-
expect(artist.date_of_birth).to eq
|
14
|
+
expect(artist.date_of_birth).to eq MetalArchives::NilDate.new(1972, 9, 2)
|
15
15
|
expect(artist.gender).to eq :male
|
16
16
|
expect(artist.biography).to match 'Avalanch'
|
17
17
|
expect(artist.trivia).to match 'Sanctuarium Estudios'
|
@@ -25,7 +25,7 @@ RSpec.describe MetalArchives::Artist do
|
|
25
25
|
expect(artist).to be_instance_of MetalArchives::Artist
|
26
26
|
expect(artist.name).to eq 'Ian Fraser Kilmister'
|
27
27
|
expect(artist.aliases).to include 'Lemmy Kilmister'
|
28
|
-
expect(artist.date_of_death).to eq
|
28
|
+
expect(artist.date_of_death).to eq MetalArchives::NilDate.new(2015, 12, 28)
|
29
29
|
expect(artist.links.length).to eq 5
|
30
30
|
expect(artist.links.count { |l| l[:type] == :official }).to eq 1
|
31
31
|
expect(artist.links.count { |l| l[:type] == :unofficial }).to eq 2
|
@@ -38,16 +38,12 @@ RSpec.describe MetalArchives::Artist do
|
|
38
38
|
expect(MetalArchives::Parsers::Artist.map_params(:name => 'name')[:query]).to eq 'name'
|
39
39
|
end
|
40
40
|
|
41
|
-
it '
|
42
|
-
|
43
|
-
MetalArchives.config.endpoint = 'https://foo.bar/'
|
41
|
+
it 'uses NilDate' do
|
42
|
+
artist = MetalArchives::Artist.find 35049
|
44
43
|
|
45
|
-
artist
|
46
|
-
|
47
|
-
expect(artist.
|
48
|
-
expect(artist.photo.host).to eq 'foo.bar'
|
49
|
-
|
50
|
-
MetalArchives.config.endpoint = old_endpoint
|
44
|
+
expect(artist.name).to eq 'Johan Johansson'
|
45
|
+
expect(artist.date_of_birth).to be_instance_of MetalArchives::NilDate
|
46
|
+
expect(artist.date_of_birth).to eq MetalArchives::NilDate.new(1975, nil, nil)
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
data/spec/utils/nil_date_spec.rb
CHANGED
@@ -95,4 +95,54 @@ RSpec.describe MetalArchives::NilDate do
|
|
95
95
|
expect(-> { described_class.parse "This isn't a date" }).to raise_error MetalArchives::Errors::ArgumentError
|
96
96
|
end
|
97
97
|
end
|
98
|
+
|
99
|
+
it 'includes comparable' do
|
100
|
+
date1 = described_class.new 2015, 01, 01
|
101
|
+
date2 = described_class.new 2015, 01, 02
|
102
|
+
date3 = described_class.new 2015, 02, 01
|
103
|
+
date4 = described_class.new 2016, 01, 02
|
104
|
+
date5 = described_class.new 2015, 01, 01
|
105
|
+
date6 = described_class.new 2014, 12, 31
|
106
|
+
date7 = described_class.new 2015, 01, nil
|
107
|
+
date8 = described_class.new 2015, 01, nil
|
108
|
+
date9 = described_class.new 2015, 02, nil
|
109
|
+
date10 = described_class.new 2015, nil, nil
|
110
|
+
date11 = described_class.new 2016, nil, nil
|
111
|
+
|
112
|
+
expect(date1 <=> date2).to eq -1
|
113
|
+
expect(date2 <=> date1).to eq 1
|
114
|
+
expect(date1 <=> date3).to eq -1
|
115
|
+
expect(date3 <=> date1).to eq 1
|
116
|
+
expect(date1 <=> date4).to eq -1
|
117
|
+
expect(date4 <=> date1).to eq 1
|
118
|
+
expect(date1 <=> date5).to eq 0
|
119
|
+
expect(date5 <=> date1).to eq 0
|
120
|
+
expect(date6 <=> date1).to eq -1
|
121
|
+
expect(date1 <=> date6).to eq 1
|
122
|
+
|
123
|
+
expect(date1 <=> date7).to eq nil
|
124
|
+
expect(date7 <=> date1).to eq nil
|
125
|
+
expect(date1 <=> date9).to eq nil
|
126
|
+
expect(date9 <=> date1).to eq nil
|
127
|
+
expect(date7 <=> date8).to eq 0
|
128
|
+
expect(date8 <=> date7).to eq 0
|
129
|
+
expect(date7 <=> date9).to eq -1
|
130
|
+
expect(date9 <=> date7).to eq 1
|
131
|
+
expect(date7 <=> date10).to eq nil
|
132
|
+
expect(date10 <=> date7).to eq nil
|
133
|
+
expect(date10 <=> date11).to eq -1
|
134
|
+
expect(date11 <=> date10).to eq 1
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'prints to string' do
|
138
|
+
date1 = described_class.new 2015, nil, nil
|
139
|
+
date2 = described_class.new 2015, 01, nil
|
140
|
+
date3 = described_class.new 2015, 01, 01
|
141
|
+
date4 = described_class.new 2015, nil, 01
|
142
|
+
|
143
|
+
expect(date1.to_s).to eq '2015-00-00'
|
144
|
+
expect(date2.to_s).to eq '2015-01-00'
|
145
|
+
expect(date3.to_s).to eq '2015-01-01'
|
146
|
+
expect(date4.to_s).to eq '2015-00-01'
|
147
|
+
end
|
98
148
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metal_archives
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Dejonckheere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- lib/metal_archives/configuration.rb
|
213
213
|
- lib/metal_archives/error.rb
|
214
214
|
- lib/metal_archives/http_client.rb
|
215
|
+
- lib/metal_archives/middleware/cache_check.rb
|
215
216
|
- lib/metal_archives/middleware/headers.rb
|
216
217
|
- lib/metal_archives/middleware/rewrite_endpoint.rb
|
217
218
|
- lib/metal_archives/models/artist.rb
|