musicbrainz_wrapper 0.0.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.
- checksums.yaml +15 -0
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/lib/.DS_Store +0 -0
- data/lib/musicbrainz.rb +6 -0
- data/lib/musicbrainz_wrapper.rb +2 -0
- data/lib/musicbrainz_wrapper/version.rb +3 -0
- data/lib/wrapper/.DS_Store +0 -0
- data/lib/wrapper/resources/alias.rb +11 -0
- data/lib/wrapper/resources/area.rb +11 -0
- data/lib/wrapper/resources/artist.rb +36 -0
- data/lib/wrapper/resources/cover_art_archive.rb +11 -0
- data/lib/wrapper/resources/label.rb +26 -0
- data/lib/wrapper/resources/label_info.rb +12 -0
- data/lib/wrapper/resources/life_span.rb +11 -0
- data/lib/wrapper/resources/media.rb +11 -0
- data/lib/wrapper/resources/recording.rb +53 -0
- data/lib/wrapper/resources/relation.rb +18 -0
- data/lib/wrapper/resources/release.rb +64 -0
- data/lib/wrapper/resources/release_event.rb +12 -0
- data/lib/wrapper/resources/release_group.rb +42 -0
- data/lib/wrapper/resources/tag.rb +11 -0
- data/lib/wrapper/resources/text_representation.rb +11 -0
- data/lib/wrapper/resources/work.rb +20 -0
- data/lib/wrapper/wrapper.rb +217 -0
- data/musicbrainz_wrapper.gemspec +23 -0
- data/spec/musicbrainz_wrapper_spec.rb +5 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/wrapper/wrapper_spec.rb +164 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODllMmEwOGE4NzU5NjdiNGZhMTU0NGU4YzUzMzIyOWMxZmUxNGI2Yg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Y2YzNDVmYzhiM2JiMDFjZDA1YzFiZmQ5NzEwOGIyZWE3OTBhNzkxYQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODgxNjZkZDVjMWRiNzcxMWJjM2RjZGRjODg4ZjQ1M2Q2NDAyZWMxMmMzNjM1
|
10
|
+
N2ZkNzRkZjk2ZDE0MGM4YWVkNjBhZWI5OTk3ODViMjgyNmE2Y2I5Y2RjYWJi
|
11
|
+
ZjZjNjM2ZDdiODAwNzdkZWYyODg1YWJkNjM4OTgxNmNkNDJiOGQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Zjk3YjJhZTJmYWU5YWQ4ZjEzZDFmYzBiMTZhM2E5NWViMzM1MTdmNGU3MGFk
|
14
|
+
M2MyZTFlNDhjZTI0MjkxY2M1ODBiYWJkMzFlZjM5YWJmY2FmYzc1MTU5MzE0
|
15
|
+
YWM1NWMwNjZmNDg3Mzk0ZDAwYWFmZjA1OTJlODZiZDUyY2Q1MTA=
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 tomallen400
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# MusicbrainzWrapper
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'musicbrainz_wrapper'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install musicbrainz_wrapper
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/musicbrainz.rb
ADDED
Binary file
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Musicbrainz::Area
|
2
|
+
|
3
|
+
attr_accessor :id, :name, :sort_name, :disambiguation, :iso_3166_3_codes, :iso_3166_2_codes, :iso_3166_1_codes
|
4
|
+
|
5
|
+
def initialize args
|
6
|
+
args.each do |k, v|
|
7
|
+
instance_variable_set("@#{k.gsub('-', '_')}", v) unless v.nil?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Musicbrainz::Artist
|
2
|
+
|
3
|
+
attr_accessor :id, :name, :sort_name, :disambiguation, :ipis, :type, :country, :area, :begin_area, :life_span, :aliases, :tags
|
4
|
+
|
5
|
+
def initialize args
|
6
|
+
args.each do |k, v|
|
7
|
+
instance_variable_set("@#{k.gsub('-', '_')}", v) unless v.nil?
|
8
|
+
end
|
9
|
+
self.child_initializers
|
10
|
+
end
|
11
|
+
|
12
|
+
def child_initializers
|
13
|
+
self.area = Musicbrainz::Area.new(self.area) if self.area
|
14
|
+
self.begin_area = Musicbrainz::Area.new(self.begin_area) if self.begin_area
|
15
|
+
self.life_span = Musicbrainz::Area.new(self.life_span) if self.life_span
|
16
|
+
self.aliases_initialize if self.aliases
|
17
|
+
self.tags_initialize if self.tags
|
18
|
+
end
|
19
|
+
|
20
|
+
def aliases_initialize
|
21
|
+
array = []
|
22
|
+
self.aliases.each do |a|
|
23
|
+
array << Musicbrainz::Alias.new(a)
|
24
|
+
end
|
25
|
+
self.aliases = array
|
26
|
+
end
|
27
|
+
|
28
|
+
def tags_initialize
|
29
|
+
array = []
|
30
|
+
self.tags.each do |a|
|
31
|
+
array << Musicbrainz::Tag.new(a)
|
32
|
+
end
|
33
|
+
self.tags = array
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Musicbrainz::Label
|
2
|
+
|
3
|
+
attr_accessor :id, :name, :sort_name, :country, :disambiguation, :ipis, :type, :score, :label_code, :country, :area, :life_span, :tags
|
4
|
+
|
5
|
+
def initialize args
|
6
|
+
args.each do |k, v|
|
7
|
+
instance_variable_set("@#{k.gsub('-', '_')}", v) unless v.nil?
|
8
|
+
end
|
9
|
+
self.child_initializers
|
10
|
+
end
|
11
|
+
|
12
|
+
def child_initializers
|
13
|
+
self.area = Musicbrainz::Area.new(self.area) if self.area
|
14
|
+
self.life_span = Musicbrainz::Area.new(self.life_span) if self.life_span
|
15
|
+
self.tags_initialize if self.tags
|
16
|
+
end
|
17
|
+
|
18
|
+
def tags_initialize
|
19
|
+
array = []
|
20
|
+
self.tags.each do |a|
|
21
|
+
array << Musicbrainz::Tag.new(a)
|
22
|
+
end
|
23
|
+
self.tags = array
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Musicbrainz::LabelInfo
|
2
|
+
|
3
|
+
attr_accessor :catalog_number, :label
|
4
|
+
|
5
|
+
def initialize args
|
6
|
+
args.each do |k, v|
|
7
|
+
instance_variable_set("@#{k.gsub('-', '_')}", v) unless v.nil?
|
8
|
+
end
|
9
|
+
self.label = Musicbrainz::Label.new(self.label) if self.label
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class Musicbrainz::Recording
|
2
|
+
|
3
|
+
attr_accessor :id, :title, :disambiguation, :score, :length, :video, :artist_credit, :releases, :tags, :relations, :recording, :work
|
4
|
+
|
5
|
+
def initialize args
|
6
|
+
args.each do |k, v|
|
7
|
+
instance_variable_set("@#{k.gsub('-', '_')}", v) unless v.nil?
|
8
|
+
end
|
9
|
+
self.child_initializers
|
10
|
+
end
|
11
|
+
|
12
|
+
def child_initializers
|
13
|
+
self.recording = Musicbrainz::Recording.new(self.recording) if self.recording
|
14
|
+
self.work = Musicbrainz::Work.new(self.work) if self.work
|
15
|
+
self.artists_initialize if self.artist_credit
|
16
|
+
self.tags_initialize if self.tags
|
17
|
+
self.releases_initialize if self.releases
|
18
|
+
self.relations_initialize if self.relations
|
19
|
+
end
|
20
|
+
|
21
|
+
def artists_initialize
|
22
|
+
array = []
|
23
|
+
self.artist_credit.each do |a|
|
24
|
+
array << Musicbrainz::Artist.new(a["artist"]) if a["artist"]
|
25
|
+
end
|
26
|
+
self.artist_credit = array
|
27
|
+
end
|
28
|
+
|
29
|
+
def tags_initialize
|
30
|
+
array = []
|
31
|
+
self.tags.each do |a|
|
32
|
+
array << Musicbrainz::Tag.new(a)
|
33
|
+
end
|
34
|
+
self.tags = array
|
35
|
+
end
|
36
|
+
|
37
|
+
def releases_initialize
|
38
|
+
array = []
|
39
|
+
self.releases.each do |a|
|
40
|
+
array << Musicbrainz::Release.new(a)
|
41
|
+
end
|
42
|
+
self.releases = array
|
43
|
+
end
|
44
|
+
|
45
|
+
def relations_initialize
|
46
|
+
array = []
|
47
|
+
self.relations.each do |a|
|
48
|
+
array << Musicbrainz::Relation.new(a)
|
49
|
+
end
|
50
|
+
self.relations = array
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Musicbrainz::Relation
|
2
|
+
|
3
|
+
attr_accessor :type, :type_id, :direction, :artist, :end, :ended, :begin, :attributes, :work, :recording
|
4
|
+
|
5
|
+
def initialize args
|
6
|
+
args.each do |k, v|
|
7
|
+
instance_variable_set("@#{k.gsub('-', '_')}", v) unless v.nil?
|
8
|
+
end
|
9
|
+
self.child_initializers
|
10
|
+
end
|
11
|
+
|
12
|
+
def child_initializers
|
13
|
+
self.recording = Musicbrainz::Recording.new(self.recording) if self.recording
|
14
|
+
self.artist = Musicbrainz::Artist.new(self.artist) if self.artist
|
15
|
+
self.work = Musicbrainz::Work.new(self.work) if self.work
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class Musicbrainz::Release
|
2
|
+
|
3
|
+
attr_accessor :id, :title, :score, :count, :status, :text_representation, :artist_credit, :release_group, :area, :date, :country, :release_events, :label_info, :barcode, :asin, :track_count, :media, :cover_art_archive, :quality, :relations
|
4
|
+
|
5
|
+
def initialize args
|
6
|
+
args.each do |k, v|
|
7
|
+
instance_variable_set("@#{k.gsub('-', '_')}", v) unless v.nil?
|
8
|
+
end
|
9
|
+
self.child_initializers
|
10
|
+
end
|
11
|
+
|
12
|
+
def child_initializers
|
13
|
+
self.area = Musicbrainz::Area.new(self.area) if self.area
|
14
|
+
self.text_representation = Musicbrainz::TextRepresentation.new(self.text_representation) if self.text_representation
|
15
|
+
self.release_group = Musicbrainz::ReleaseGroup.new(self.release_group) if self.release_group
|
16
|
+
self.cover_art_archive = Musicbrainz::CoverArtArchive.new(self.cover_art_archive) if self.cover_art_archive
|
17
|
+
self.artists_initialize if self.artist_credit
|
18
|
+
self.media_initialize if self.media
|
19
|
+
self.label_info_initialize if self.label_info
|
20
|
+
self.release_events_initialize if self.release_events
|
21
|
+
self.relations_initialize if self.relations
|
22
|
+
end
|
23
|
+
|
24
|
+
def artists_initialize
|
25
|
+
array = []
|
26
|
+
self.artist_credit.each do |a|
|
27
|
+
array << Musicbrainz::Artist.new(a["artist"]) if a["artist"]
|
28
|
+
end
|
29
|
+
self.artist_credit = array
|
30
|
+
end
|
31
|
+
|
32
|
+
def media_initialize
|
33
|
+
array = []
|
34
|
+
self.media.each do |a|
|
35
|
+
array << Musicbrainz::Media.new(a)
|
36
|
+
end
|
37
|
+
self.media = array
|
38
|
+
end
|
39
|
+
|
40
|
+
def label_info_initialize
|
41
|
+
array = []
|
42
|
+
self.label_info.each do |a|
|
43
|
+
array << Musicbrainz::LabelInfo.new(a)
|
44
|
+
end
|
45
|
+
self.label_info = array
|
46
|
+
end
|
47
|
+
|
48
|
+
def release_events_initialize
|
49
|
+
array = []
|
50
|
+
self.release_events.each do |a|
|
51
|
+
array << Musicbrainz::ReleaseEvent.new(a)
|
52
|
+
end
|
53
|
+
self.release_events = array
|
54
|
+
end
|
55
|
+
|
56
|
+
def relations_initialize
|
57
|
+
array = []
|
58
|
+
self.relations.each do |a|
|
59
|
+
array << Musicbrainz::Relation.new(a)
|
60
|
+
end
|
61
|
+
self.relations = array
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Musicbrainz::ReleaseGroup
|
2
|
+
|
3
|
+
attr_accessor :id, :title, :count, :score, :primary_type, :secondary_types, :artist_credit, :disambiguation, :first_release_date, :releases, :tags
|
4
|
+
|
5
|
+
def initialize args
|
6
|
+
args.each do |k, v|
|
7
|
+
instance_variable_set("@#{k.gsub('-', '_')}", v) unless v.nil?
|
8
|
+
end
|
9
|
+
self.child_initializers
|
10
|
+
end
|
11
|
+
|
12
|
+
def child_initializers
|
13
|
+
self.artists_initialize if self.artist_credit
|
14
|
+
self.releases_initialize if self.releases
|
15
|
+
self.tags_initialize if self.tags
|
16
|
+
end
|
17
|
+
|
18
|
+
def artists_initialize
|
19
|
+
array = []
|
20
|
+
self.artist_credit.each do |a|
|
21
|
+
array << Musicbrainz::Artist.new(a["artist"]) if a["artist"]
|
22
|
+
end
|
23
|
+
self.artist_credit = array
|
24
|
+
end
|
25
|
+
|
26
|
+
def releases_initialize
|
27
|
+
array = []
|
28
|
+
self.releases.each do |a|
|
29
|
+
array << Musicbrainz::Release.new(a)
|
30
|
+
end
|
31
|
+
self.releases = array
|
32
|
+
end
|
33
|
+
|
34
|
+
def tags_initialize
|
35
|
+
array = []
|
36
|
+
self.tags.each do |a|
|
37
|
+
array << Musicbrainz::Tag.new(a)
|
38
|
+
end
|
39
|
+
self.tags = array
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Musicbrainz::Work
|
2
|
+
|
3
|
+
attr_accessor :id, :title, :type, :score, :language, :relations, :iswcs, :disambiguation
|
4
|
+
|
5
|
+
def initialize args
|
6
|
+
args.each do |k, v|
|
7
|
+
instance_variable_set("@#{k.gsub('-', '_')}", v) unless v.nil?
|
8
|
+
end
|
9
|
+
self.relations_initialize if self.relations
|
10
|
+
end
|
11
|
+
|
12
|
+
def relations_initialize
|
13
|
+
array = []
|
14
|
+
self.relations.each do |a|
|
15
|
+
array << Musicbrainz::Relation.new(a)
|
16
|
+
end
|
17
|
+
self.relations = array
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
class Musicbrainz::Wrapper
|
2
|
+
|
3
|
+
require 'net/https'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
attr_accessor :username, :password
|
8
|
+
|
9
|
+
@@api_url = "http://musicbrainz.org/ws/2/"
|
10
|
+
|
11
|
+
Dir[File.join(File.dirname(__FILE__), "resources", "*.rb")].each { |file| require file }
|
12
|
+
|
13
|
+
def initialize args
|
14
|
+
args.each do |k, v|
|
15
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# artist, label, recording, release, release-group, work, area, url, isrc, iswc, discid
|
20
|
+
# discids, media, isrcs, artist-credits, various-artists, aliases, annotation, tags, ratings, user-tags, user-ratings
|
21
|
+
# artist-rels, label-rels, recording-rels, release-rels, release-group-rels, url-rels, work-rels
|
22
|
+
# recording-level-rels, work-level-rels
|
23
|
+
|
24
|
+
def artist(params)
|
25
|
+
# artist(:id => "id", :inc => {:isrcs => true, :artist-rels => true})
|
26
|
+
response = self.query(Musicbrainz::Wrapper.create_query_string('artist', params), :single)
|
27
|
+
Musicbrainz::Artist.new(response) if !response.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def artists(params)
|
31
|
+
response = self.query(Musicbrainz::Wrapper.create_query_string('artist', params), :multiple)
|
32
|
+
if !response.nil?
|
33
|
+
array = []
|
34
|
+
response.each do |a|
|
35
|
+
array << Musicbrainz::Artist.new(a)
|
36
|
+
end
|
37
|
+
array
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def label(params)
|
42
|
+
response = self.query(Musicbrainz::Wrapper.create_query_string('label', params), :single)
|
43
|
+
Musicbrainz::Label.new(response) if !response.nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
def labels(params)
|
47
|
+
response = self.query(Musicbrainz::Wrapper.create_query_string('label', params), :multiple)
|
48
|
+
if !response.nil?
|
49
|
+
array = []
|
50
|
+
response.each do |a|
|
51
|
+
array << Musicbrainz::Label.new(a)
|
52
|
+
end
|
53
|
+
array
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def recording(params)
|
58
|
+
response = self.query(Musicbrainz::Wrapper.create_query_string('recording', params), :single)
|
59
|
+
Musicbrainz::Recording.new(response) if !response.nil?
|
60
|
+
end
|
61
|
+
|
62
|
+
def recordings(params)
|
63
|
+
response = self.query(Musicbrainz::Wrapper.create_query_string('recording', params), :multiple)
|
64
|
+
if !response.nil?
|
65
|
+
array = []
|
66
|
+
response.each do |a|
|
67
|
+
array << Musicbrainz::Recording.new(a)
|
68
|
+
end
|
69
|
+
array
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def release(params)
|
74
|
+
response = self.query(Musicbrainz::Wrapper.create_query_string('release', params), :single)
|
75
|
+
Musicbrainz::Release.new(response) if !response.nil?
|
76
|
+
end
|
77
|
+
|
78
|
+
def releases(params)
|
79
|
+
response = self.query(Musicbrainz::Wrapper.create_query_string('release', params), :multiple)
|
80
|
+
if !response.nil?
|
81
|
+
array = []
|
82
|
+
response.each do |a|
|
83
|
+
array << Musicbrainz::Release.new(a)
|
84
|
+
end
|
85
|
+
array
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def release_group(params)
|
90
|
+
response = self.query(Musicbrainz::Wrapper.create_query_string('release-group', params), :single)
|
91
|
+
Musicbrainz::ReleaseGroup.new(response) if !response.nil?
|
92
|
+
end
|
93
|
+
|
94
|
+
def release_groups(params)
|
95
|
+
response = self.query(Musicbrainz::Wrapper.create_query_string('release-group', params), :multiple)
|
96
|
+
if !response.nil?
|
97
|
+
array = []
|
98
|
+
response.each do |a|
|
99
|
+
array << Musicbrainz::ReleaseGroup.new(a)
|
100
|
+
end
|
101
|
+
array
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def work(params)
|
106
|
+
response = self.query(Musicbrainz::Wrapper.create_query_string('work', params), :single)
|
107
|
+
Musicbrainz::Work.new(response) if !response.nil?
|
108
|
+
end
|
109
|
+
|
110
|
+
def works(params)
|
111
|
+
response = self.query(Musicbrainz::Wrapper.create_query_string('work', params), :multiple)
|
112
|
+
if !response.nil?
|
113
|
+
array = []
|
114
|
+
response.each do |a|
|
115
|
+
array << Musicbrainz::Work.new(a)
|
116
|
+
end
|
117
|
+
array
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Query String
|
122
|
+
# releases(:artist => "The Rolling Stones", :release => "Sticky Fingers", :inc => {:isrcs => true, :artist-rels => true})
|
123
|
+
# release/?query=artist:The%20Rolling%20Stones+release=Sticky%20Fingers&inc=isrcs&fmt=json
|
124
|
+
# release(:id => "id", :inc => {:isrcs => true, :artist-rels => true})
|
125
|
+
# recording/8d2338a2-4acc-4d99-b2a7-1151f428cab6?inc=isrcs+artist-rels&fmt=json
|
126
|
+
def self.create_query_string(start, params)
|
127
|
+
if params.is_a?(Hash) && params.count > 0
|
128
|
+
ending = hash_to_query_string(params)
|
129
|
+
"#{start}/#{ending}#{question_mark_or_ampersand(ending)}fmt=json"
|
130
|
+
else
|
131
|
+
"#{start}/"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.hash_to_query_string(hash)
|
136
|
+
if hash[:id]
|
137
|
+
string = hash[:id]
|
138
|
+
else
|
139
|
+
string = '?query='
|
140
|
+
string += query_array(hash).join('+')
|
141
|
+
end
|
142
|
+
append_inc(string, hash)
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.query_array(hash)
|
146
|
+
array = []
|
147
|
+
hash.each do |k, v|
|
148
|
+
array << "#{k}:#{URI.encode(v, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}" unless k == :inc
|
149
|
+
end
|
150
|
+
array
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.append_inc(url, hash)
|
154
|
+
if hash[:inc]
|
155
|
+
"#{url}#{question_mark_or_ampersand(url)}inc=#{inc_values_array(hash[:inc]).join('+')}"
|
156
|
+
else
|
157
|
+
url
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.inc_values_array(hash)
|
162
|
+
array = []
|
163
|
+
hash.each do |k, v|
|
164
|
+
array << k.to_s.gsub('_', '-') if v == true
|
165
|
+
end
|
166
|
+
array
|
167
|
+
end
|
168
|
+
|
169
|
+
def self.question_mark_or_ampersand(string)
|
170
|
+
if string.include?('?')
|
171
|
+
'&'
|
172
|
+
else
|
173
|
+
'?'
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# Hit Musicbrainz API
|
178
|
+
def query(ending, type)
|
179
|
+
query = @@api_url + ending
|
180
|
+
response = self.send_query(query)
|
181
|
+
Musicbrainz::Wrapper.parse_response(response, type)
|
182
|
+
end
|
183
|
+
|
184
|
+
def send_query(query)
|
185
|
+
sleep 1
|
186
|
+
uri = URI.parse(query)
|
187
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
188
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
189
|
+
http.request(request)
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.parse_response(response, type)
|
193
|
+
if response.is_a?(Net::HTTPOK)
|
194
|
+
json = JSON.parse(response.body) rescue {}
|
195
|
+
if type == :multiple
|
196
|
+
if json["artist"]
|
197
|
+
json["artist"]
|
198
|
+
elsif json["labels"]
|
199
|
+
json["labels"]
|
200
|
+
elsif json["release-groups"]
|
201
|
+
json["release-groups"]
|
202
|
+
elsif json["releases"]
|
203
|
+
json["releases"]
|
204
|
+
elsif json["recording"]
|
205
|
+
json["recording"]
|
206
|
+
elsif json["work"]
|
207
|
+
json["work"]
|
208
|
+
else
|
209
|
+
json
|
210
|
+
end
|
211
|
+
else
|
212
|
+
json
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'musicbrainz_wrapper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "musicbrainz_wrapper"
|
8
|
+
spec.version = MusicbrainzWrapper::VERSION
|
9
|
+
spec.authors = ["tomallen400"]
|
10
|
+
spec.email = ["tomallen4000@gmail.com"]
|
11
|
+
spec.description = "A object orientated gem for the Musizbrainz API"
|
12
|
+
spec.summary = "A object orientated gem for the Musizbrainz API"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
config.color_enabled = true
|
12
|
+
|
13
|
+
# Run specs in random order to surface order dependencies. If you find an
|
14
|
+
# order dependency and want to debug it, you can fix the order by providing
|
15
|
+
# the seed, which is printed after each run.
|
16
|
+
# --seed 1234
|
17
|
+
config.order = 'random'
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'musicbrainz_wrapper'
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Musicbrainz::Wrapper do
|
4
|
+
|
5
|
+
let(:wrapper) { Musicbrainz::Wrapper.new(:username => 'username', :password => 'password') }
|
6
|
+
let(:api_point) { 'http://musicbrainz.org/ws/2/' }
|
7
|
+
let(:album_query) { 'release/d883e644-5ec0-4928-9ccd-fc78bc306a46?fmt=json' }
|
8
|
+
let(:albums_query) { 'release/?query=artist:The%20Rolling%20Stones&fmt=json' }
|
9
|
+
subject { wrapper }
|
10
|
+
|
11
|
+
it { should respond_to(:username) }
|
12
|
+
it { should respond_to(:password) }
|
13
|
+
|
14
|
+
# Query String
|
15
|
+
describe "create_query_string" do
|
16
|
+
subject { Musicbrainz::Wrapper.create_query_string('release', {:artist => "The Rolling Stones", :release => "Sticky Fingers", :inc => {:isrcs => true, :artist_rels => true}}) }
|
17
|
+
it { should be_an_instance_of String }
|
18
|
+
it { should include('artist:The%20Rolling%20Stones+release:Sticky%20Fingers') }
|
19
|
+
it "should add id to string preceded by a / if id supplied" do
|
20
|
+
Musicbrainz::Wrapper.create_query_string('release', {:id => "id", :inc => {:isrcs => true, :artist_rels => true}}).should include('/id')
|
21
|
+
end
|
22
|
+
it "should add each of the passed queries preceded by ?query= and separate with +s" do
|
23
|
+
should include('?query=artist:The%20Rolling%20Stones+release:Sticky%20Fingers')
|
24
|
+
end
|
25
|
+
it "should add all incs" do
|
26
|
+
should include('&inc=isrcs+artist-rels')
|
27
|
+
end
|
28
|
+
it "should add &fmt=json to end of string" do
|
29
|
+
should include('&fmt=json')
|
30
|
+
end
|
31
|
+
it "should return the start if passed blank hash" do
|
32
|
+
Musicbrainz::Wrapper.create_query_string('release', {}).should == 'release/'
|
33
|
+
end
|
34
|
+
it "should return the start if not passed hash" do
|
35
|
+
Musicbrainz::Wrapper.create_query_string('release', nil).should == 'release/'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "hash_to_query_string" do
|
40
|
+
it "should return a string" do
|
41
|
+
Musicbrainz::Wrapper.hash_to_query_string(:id => "123456").should be_an_instance_of String
|
42
|
+
end
|
43
|
+
it "should return id if id supplied" do
|
44
|
+
Musicbrainz::Wrapper.hash_to_query_string(:id => "123456").should == "123456"
|
45
|
+
end
|
46
|
+
it "should return ?query=queries if no id" do
|
47
|
+
Musicbrainz::Wrapper.hash_to_query_string(:artist => "The Rolling Stones", :release => "Sticky Fingers").should == "?query=artist:The%20Rolling%20Stones+release:Sticky%20Fingers"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "query_array" do
|
52
|
+
subject { Musicbrainz::Wrapper.query_array(:artist => "Stones", :release => "Sticky Fingers", :inc => {:isrcs => true, :artist_rels => true}) }
|
53
|
+
it { should be_an_instance_of Array }
|
54
|
+
it { subject.first.should be_an_instance_of String }
|
55
|
+
it { should have(2).Strings }
|
56
|
+
it { should include('artist:Stones') }
|
57
|
+
it { should include('release:Sticky%20Fingers') }
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "append_inc" do
|
61
|
+
subject { Musicbrainz::Wrapper.append_inc('string', {:artist => "The Rolling Stones", :release => "Sticky Fingers", :inc => {:isrcs => true, :artist_rels => true}}) }
|
62
|
+
it { should be_an_instance_of String }
|
63
|
+
context "when inc exists" do
|
64
|
+
it { should include('?inc=') }
|
65
|
+
it "should include &inc= if string does contain ?" do
|
66
|
+
Musicbrainz::Wrapper.append_inc('?string', {:artist => "The Rolling Stones", :release => "Sticky Fingers", :inc => {:isrcs => true, :artist_rels => true}}).should include('&inc=')
|
67
|
+
end
|
68
|
+
it { should include('inc=isrcs+artist-rels') }
|
69
|
+
end
|
70
|
+
context "when inc doesn't exist" do
|
71
|
+
it "should return the original string if inc does not exist" do
|
72
|
+
Musicbrainz::Wrapper.append_inc('string', {:artist => "The Rolling Stones", :release => "Sticky Fingers"}).should == 'string'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "inc_values_array" do
|
78
|
+
subject { Musicbrainz::Wrapper.inc_values_array(:isrcs => true, :artist_rels => true, :something_else => false) }
|
79
|
+
it { should be_an_instance_of Array }
|
80
|
+
it { subject.first.should be_an_instance_of String }
|
81
|
+
it "should have a value for each that has true" do
|
82
|
+
should have(2).Strings
|
83
|
+
end
|
84
|
+
it "should replace all _ with -" do
|
85
|
+
should include('artist-rels')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "question_mark_or_ampersand" do
|
90
|
+
it "should return a string" do
|
91
|
+
Musicbrainz::Wrapper.question_mark_or_ampersand("string").should be_an_instance_of String
|
92
|
+
end
|
93
|
+
it "should return a ? if one is not already in string" do
|
94
|
+
Musicbrainz::Wrapper.question_mark_or_ampersand("string").should == '?'
|
95
|
+
end
|
96
|
+
it "should return a & if a ? is in string" do
|
97
|
+
Musicbrainz::Wrapper.question_mark_or_ampersand("string?").should == '&'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Hit Musicbrainz API
|
102
|
+
describe "query", :slow => true do
|
103
|
+
context "is passed a plural object" do
|
104
|
+
it "should return an array" do
|
105
|
+
wrapper.query(albums_query).should be_an_instance_of Array
|
106
|
+
end
|
107
|
+
end
|
108
|
+
context "is passed a single object" do
|
109
|
+
it "should return a hash" do
|
110
|
+
wrapper.query(album_query).should be_an_instance_of Hash
|
111
|
+
end
|
112
|
+
end
|
113
|
+
context "is passed bad data" do
|
114
|
+
it "should return nil" do
|
115
|
+
wrapper.query("something_else").should be_nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "send_query", :slow => true do
|
121
|
+
context "when sent a good request" do
|
122
|
+
it "should return a Net::HTTPOK object" do
|
123
|
+
wrapper.send_query(api_point + album_query).should be_an_instance_of Net::HTTPOK
|
124
|
+
end
|
125
|
+
it "should return a string as the body" do
|
126
|
+
wrapper.send_query(api_point + album_query).body.should be_an_instance_of String
|
127
|
+
end
|
128
|
+
end
|
129
|
+
context "when sent a bad request" do
|
130
|
+
it "should return a Net::HTTPBadRequest object" do
|
131
|
+
wrapper.send_query(api_point + 'release/d8').should be_an_instance_of Net::HTTPBadRequest
|
132
|
+
end
|
133
|
+
end
|
134
|
+
context "when not finding an object" do
|
135
|
+
it "should return a Net::HTTPNotFound object" do
|
136
|
+
wrapper.send_query(api_point + 'release/d883e644-5ec0-4928-9ccd-fc78bc306a47').should be_an_instance_of Net::HTTPNotFound
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "parse_response", :slow => true do
|
142
|
+
context "when passed a good response" do
|
143
|
+
context "for a single object" do
|
144
|
+
it "should return a hash" do
|
145
|
+
response = wrapper.send_query(api_point + album_query)
|
146
|
+
Musicbrainz::Wrapper.parse_response(response).should be_an_instance_of Hash
|
147
|
+
end
|
148
|
+
end
|
149
|
+
context "for multiple objects" do
|
150
|
+
it "should return an array" do
|
151
|
+
response = wrapper.send_query(api_point + albums_query)
|
152
|
+
Musicbrainz::Wrapper.parse_response(response).should be_an_instance_of Array
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
context "when passed a bad response" do
|
157
|
+
it "should return nil" do
|
158
|
+
response = wrapper.send_query(api_point + 'release/d8')
|
159
|
+
Musicbrainz::Wrapper.parse_response(response).should be_nil
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: musicbrainz_wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tomallen400
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A object orientated gem for the Musizbrainz API
|
42
|
+
email:
|
43
|
+
- tomallen4000@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .DS_Store
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/.DS_Store
|
55
|
+
- lib/musicbrainz.rb
|
56
|
+
- lib/musicbrainz_wrapper.rb
|
57
|
+
- lib/musicbrainz_wrapper/version.rb
|
58
|
+
- lib/wrapper/.DS_Store
|
59
|
+
- lib/wrapper/resources/alias.rb
|
60
|
+
- lib/wrapper/resources/area.rb
|
61
|
+
- lib/wrapper/resources/artist.rb
|
62
|
+
- lib/wrapper/resources/cover_art_archive.rb
|
63
|
+
- lib/wrapper/resources/label.rb
|
64
|
+
- lib/wrapper/resources/label_info.rb
|
65
|
+
- lib/wrapper/resources/life_span.rb
|
66
|
+
- lib/wrapper/resources/media.rb
|
67
|
+
- lib/wrapper/resources/recording.rb
|
68
|
+
- lib/wrapper/resources/relation.rb
|
69
|
+
- lib/wrapper/resources/release.rb
|
70
|
+
- lib/wrapper/resources/release_event.rb
|
71
|
+
- lib/wrapper/resources/release_group.rb
|
72
|
+
- lib/wrapper/resources/tag.rb
|
73
|
+
- lib/wrapper/resources/text_representation.rb
|
74
|
+
- lib/wrapper/resources/work.rb
|
75
|
+
- lib/wrapper/wrapper.rb
|
76
|
+
- musicbrainz_wrapper.gemspec
|
77
|
+
- spec/musicbrainz_wrapper_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- spec/wrapper/wrapper_spec.rb
|
80
|
+
homepage: ''
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.0.3
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: A object orientated gem for the Musizbrainz API
|
104
|
+
test_files:
|
105
|
+
- spec/musicbrainz_wrapper_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/wrapper/wrapper_spec.rb
|