musicz 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.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +20 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +7 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +73 -0
  10. data/Rakefile +8 -0
  11. data/bin/console +15 -0
  12. data/bin/setup +8 -0
  13. data/lib/musicz.rb +12 -0
  14. data/lib/musicz/configuration.rb +62 -0
  15. data/lib/musicz/entities.rb +21 -0
  16. data/lib/musicz/entities/alias.rb +14 -0
  17. data/lib/musicz/entities/area.rb +18 -0
  18. data/lib/musicz/entities/area_reference.rb +14 -0
  19. data/lib/musicz/entities/area_relation.rb +17 -0
  20. data/lib/musicz/entities/artist.rb +29 -0
  21. data/lib/musicz/entities/artist_credit.rb +14 -0
  22. data/lib/musicz/entities/artist_list.rb +15 -0
  23. data/lib/musicz/entities/artist_reference.rb +14 -0
  24. data/lib/musicz/entities/disc_id.rb +12 -0
  25. data/lib/musicz/entities/error.rb +12 -0
  26. data/lib/musicz/entities/label_info_reference.rb +18 -0
  27. data/lib/musicz/entities/life_span.rb +13 -0
  28. data/lib/musicz/entities/media.rb +18 -0
  29. data/lib/musicz/entities/rating.rb +12 -0
  30. data/lib/musicz/entities/recording.rb +21 -0
  31. data/lib/musicz/entities/recording_list.rb +15 -0
  32. data/lib/musicz/entities/recording_reference.rb +13 -0
  33. data/lib/musicz/entities/release.rb +37 -0
  34. data/lib/musicz/entities/release_event.rb +13 -0
  35. data/lib/musicz/entities/release_group.rb +14 -0
  36. data/lib/musicz/entities/release_reference.rb +20 -0
  37. data/lib/musicz/entities/tag.rb +12 -0
  38. data/lib/musicz/entities/text_representation.rb +12 -0
  39. data/lib/musicz/entities/track.rb +17 -0
  40. data/lib/musicz/entity.rb +22 -0
  41. data/lib/musicz/request.rb +37 -0
  42. data/lib/musicz/search.rb +6 -0
  43. data/lib/musicz/search/area_repository.rb +16 -0
  44. data/lib/musicz/search/artist_repository.rb +36 -0
  45. data/lib/musicz/search/options/artist_query_terms.rb +29 -0
  46. data/lib/musicz/search/options/id_search.rb +15 -0
  47. data/lib/musicz/search/options/recording_query_terms.rb +14 -0
  48. data/lib/musicz/search/recording_repository.rb +36 -0
  49. data/lib/musicz/search/repository.rb +93 -0
  50. data/lib/musicz/types.rb +9 -0
  51. data/lib/musicz/version.rb +5 -0
  52. data/musicz.gemspec +43 -0
  53. metadata +236 -0
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+ require "musicz/entities/artist_reference"
5
+
6
+ module Musicz
7
+ module Entities
8
+ class ArtistCredit < Entity
9
+ attribute :name, Types::Strict::String
10
+ attribute? :joinphrase, Types::Strict::String.optional
11
+ attribute? :artist, ArtistReference
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+ require "musicz/entities/artist"
5
+
6
+ module Musicz
7
+ module Entities
8
+ class ArtistList < Entity
9
+ attribute :created, Types::Strict::String
10
+ attribute :count, Types::JSON::Decimal
11
+ attribute :offset, Types::JSON::Decimal
12
+ attribute :artists, Types::Array.of(Artist)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+
5
+ module Musicz
6
+ module Entities
7
+ class ArtistReference < Entity
8
+ attribute :id, Types::Strict::String
9
+ attribute :name, Types::Strict::String
10
+ attribute? :sort_name, Types::Strict::String.optional
11
+ attribute? :disambiguation, Types::Strict::String.optional
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+
5
+ module Musicz
6
+ module Entities
7
+ class DiscId < Entity
8
+ attribute :id, Types::Strict::String
9
+ attribute :sectors, Types::Strict::Integer
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+
5
+ module Musicz
6
+ module Entities
7
+ class Error < Entity
8
+ attribute :error, Types::Strict::String
9
+ attribute? :help, Types::Strict::String.optional
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+
5
+ module Musicz
6
+ module Entities
7
+ class LabelInfoReference < Entity
8
+ attribute :label do
9
+ attribute :id, Types::Strict::String
10
+ attribute :name, Types::Strict::String
11
+ attribute :sort_name, Types::Strict::String
12
+ attribute? :label_code, Types::Strict::String.optional
13
+ attribute? :disambiguation, Types::Strict::String.optional
14
+ end
15
+ attribute? :catalog_number, Types::Strict::String.optional
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+
5
+ module Musicz
6
+ module Entities
7
+ class LifeSpan < Entity
8
+ attribute :ended, Types::Strict::Bool.default(false)
9
+ attribute? :begin, Types::Strict::String.optional
10
+ attribute? :end, Types::Strict::String.optional
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+ require "musicz/entities/disc_id"
5
+ require "musicz/entities/track"
6
+
7
+ module Musicz
8
+ module Entities
9
+ class Media < Entity
10
+ attribute :track_offset, Types::Strict::Integer
11
+ attribute :track_count, Types::Strict::Integer
12
+ attribute :title, Types::Strict::String
13
+ attribute :format, Types::Strict::String
14
+ attribute :discids, Types::Array.of(DiscId).default([].freeze)
15
+ attribute :tracks, Types::Array.of(Track).default([].freeze)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+
5
+ module Musicz
6
+ module Entities
7
+ class Rating < Entity
8
+ attribute :votes_count, Types::Strict::Integer
9
+ attribute :value, Types::JSON::Decimal
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+ require "musicz/entities/artist_credit"
5
+ require "musicz/entities/release_reference"
6
+
7
+ module Musicz
8
+ module Entities
9
+ class Recording < Entity
10
+ attribute :id, Types::Strict::String
11
+ attribute :title, Types::Strict::String
12
+ attribute? :disambiguation, Types::Strict::String.optional
13
+ attribute? :score, Types::Strict::Integer.optional
14
+ attribute? :artist_credit, Types::Array.of(ArtistCredit)
15
+ attribute? :length, Types::JSON::Decimal.optional
16
+ attribute? :isrcs, Types::Array.of(Types::Strict::String)
17
+ .default([].freeze)
18
+ attribute? :releases, Types::Array.of(ReleaseReference)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+ require "musicz/entities/recording"
5
+
6
+ module Musicz
7
+ module Entities
8
+ class RecordingList < Entity
9
+ attribute :created, Types::Strict::String
10
+ attribute :count, Types::JSON::Decimal
11
+ attribute :offset, Types::JSON::Decimal
12
+ attribute :recordings, Types::Array.of(Recording)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+
5
+ module Musicz
6
+ module Entities
7
+ class RecordingReference < Entity
8
+ attribute :id, Types::Strict::String
9
+ attribute :title, Types::Strict::String
10
+ attribute? :disambiguation, Types::Strict::String.optional
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+ require "musicz/entities/text_representation"
5
+ require "musicz/entities/artist_credit"
6
+ require "musicz/entities/label_info_reference"
7
+ require "musicz/entities/media"
8
+
9
+ module Musicz
10
+ module Entities
11
+ class Release < Entity
12
+ attribute :id, Types::Strict::String
13
+ attribute :title, Types::Strict::String
14
+ attribute? :date, Types::Strict::String.optional
15
+ attribute? :text_representation, TextRepresentation.optional
16
+ attribute? :country, Types::Strict::String.optional
17
+ attribute? :status, Types::Strict::String.optional
18
+ attribute? :quality, Types::Strict::String.optional
19
+ attribute? :packaging, Types::Strict::String.optional
20
+ attribute? :barcode, Types::Strict::String.optional
21
+ attribute? :status_id, Types::Strict::String.optional
22
+ attribute? :artist_credit, Types::Array.of(ArtistCredit)
23
+ attribute? :label_info, Types::Array.of(LabelInfoReference)
24
+ attribute? :asin, Types::Strict::String.optional
25
+ attribute? :disambiguation, Types::Strict::String.optional
26
+ attribute? :media, Media.optional
27
+
28
+ attribute? :release_group do
29
+ attribute :id, Types::Strict::String
30
+ attribute :primary_type, Types::Strict::String
31
+ end
32
+
33
+ attribute :release_events, Types::Array.of(ReleaseEvent)
34
+ .default([].freeze)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+ require "musicz/entities/area"
5
+
6
+ module Musicz
7
+ module Entities
8
+ class ReleaseEvent < Entity
9
+ attribute :date, Types::Strict::String
10
+ attribute :area, Area
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+
5
+ module Musicz
6
+ module Entities
7
+ class ReleaseGroup < Entity
8
+ attribute :id, Types::Strict::String
9
+ attribute :type_id, Types::Strict::String
10
+ attribute? :title, Types::Strict::String.optional
11
+ attribute? :primary_type, Types::Strict::String.optional
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+ require "musicz/entities/text_representation"
5
+ require "musicz/entities/release_event"
6
+ require "musicz/entities/release_group"
7
+
8
+ module Musicz
9
+ module Entities
10
+ class ReleaseReference < Entity
11
+ attribute :id, Types::Strict::String
12
+ attribute :title, Types::Strict::String
13
+ attribute? :status, Types::Strict::String.optional
14
+ attribute? :disambiguation, Types::Strict::String.optional
15
+ attribute? :date, Types::Strict::String.optional
16
+ attribute? :country, Types::Strict::String.optional
17
+ attribute? :release_group, ReleaseGroup.optional
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+
5
+ module Musicz
6
+ module Entities
7
+ class Tag < Entity
8
+ attribute :count, Types::Strict::Integer
9
+ attribute :name, Types::Strict::String
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+
5
+ module Musicz
6
+ module Entities
7
+ class TextRepresentation < Entity
8
+ attribute :language, Types::Strict::String
9
+ attribute :script, Types::Strict::String
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+ require "musicz/entities/recording_reference"
5
+ require "musicz/entities/artist_credit"
6
+
7
+ module Musicz
8
+ module Entities
9
+ class Track < Entity
10
+ attribute :number, Types::Strict::String
11
+ attribute :length, Types::Strict::Integer
12
+ attribute :title, Types::Strict::String
13
+ attribute :recording, RecordingReference
14
+ attribute :artist_credit, ArtistCredit
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-struct"
4
+ require "musicz/types"
5
+
6
+ module Musicz
7
+ class Entity < Dry::Struct
8
+ transform_keys do |key|
9
+ key.to_s.tr("-", "_").to_sym
10
+ end
11
+
12
+ transform_types do |type|
13
+ if type.default?
14
+ type.constructor do |value|
15
+ value.nil? ? Dry::Types::Undefined : value
16
+ end
17
+ else
18
+ type
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "typhoeus"
5
+
6
+ module Musicz
7
+ class Request
8
+ def self.default_config
9
+ Musicz.config
10
+ end
11
+
12
+ def self.build(config: default_config)
13
+ new(config: config)
14
+ end
15
+
16
+ def initialize(config:)
17
+ @config = config
18
+ end
19
+
20
+ def get(endpoint:, parameters:)
21
+ url = "#{uri(endpoint)}?#{URI.encode_www_form(parameters)}"
22
+ Typhoeus.get(url, headers: headers)
23
+ end
24
+
25
+ private
26
+
27
+ def headers
28
+ {
29
+ "User-Agent" => "#{@config.app_name} #{@config.contact}"
30
+ }
31
+ end
32
+
33
+ def uri(endpoint)
34
+ "#{@config.base_uri}/#{endpoint}"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/search/options/id_search"
4
+ require "musicz/search/options/artist_query_terms"
5
+ require "musicz/search/repository"
6
+ require "musicz/search/artist_repository"
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/search/repository"
4
+ require "musicz/entities/area"
5
+
6
+ module Musicz
7
+ module Search
8
+ class AreaRepository < Repository
9
+ ENDPOINT = "area"
10
+
11
+ def by_id(id_options)
12
+ by_id_with_entity(id_options, ENDPOINT, Musicz::Entities::Area)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entities/artist_list"
4
+ require "musicz/entities/artist"
5
+ require "musicz/search/repository"
6
+
7
+ module Musicz
8
+ module Search
9
+ class ArtistRepository < Repository
10
+ ENDPOINT = "artist"
11
+
12
+ # @param id_options [Musicz::Search::Options::IdSearch]
13
+ def by_id(id_options)
14
+ by_id_with_entity(id_options, ENDPOINT, Musicz::Entities::Artist)
15
+ end
16
+
17
+ # @param term [String] The general term to searh MusicBrainz for
18
+ # This gets executed on the MusicBrainz server by querying
19
+ # the artist, sortname and alias fields
20
+ def by_term(term)
21
+ by_term_with_entity(term, ENDPOINT, Musicz::Entities::ArtistList)
22
+ end
23
+
24
+ # @param query_terms [Musicz::Search::Options::ArtistQueryTerms]
25
+ # This executes a generic query against the MusicBrainz API
26
+ # No support for paging, so use decently specific queries
27
+ def by_query(query_terms)
28
+ by_query_with_entity(
29
+ query_terms,
30
+ ENDPOINT,
31
+ Musicz::Entities::ArtistList
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end