musicz 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d6012913c5aa48d9616ed9c0c2a433b53f28778a40395eee7113b34e48cfb8bd
4
+ data.tar.gz: fa3d5f939da30dd8109d011275ab8c19c2d7a4346644d5513b4da58be4fdcc80
5
+ SHA512:
6
+ metadata.gz: 249192a32a98cfbcaea70a498d31281de7c24061f8a6f00b66b44ccf28f6fcb9d55f6d5c29080f65a40f25da92eb96d7422828b2091212acc074aa454c835caa
7
+ data.tar.gz: fa78d7af683f686e2bb57b83dc8466aa057d2126e4a334169255d26cc1db1193d2458a51a6d44563c66d3f6e92a5f51e00da891ab4c1fe69bebe55117cfe0b76
@@ -0,0 +1,20 @@
1
+ name: Specs
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v1
12
+ - name: Set up Ruby 2.6
13
+ uses: actions/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6.x
16
+ - name: Build and test with Rake
17
+ run: |
18
+ gem install bundler
19
+ bundle install --jobs 4 --retry 3
20
+ bundle exec rake
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.5
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at derrickplotsky@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in musicz.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Derrick Plotsky
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,73 @@
1
+ # Musicz
2
+ ![Specs](https://github.com/derrickp/musicz/workflows/Specs/badge.svg)
3
+
4
+ This will be a basic wrapper around the musicbrainz search API.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'musicz'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install musicz
21
+
22
+ ## Usage
23
+
24
+ Since it's still early stages, most things are not done, even the convenience methods.
25
+
26
+ But basic usage
27
+
28
+ ```ruby
29
+ require 'musicz'
30
+
31
+ Musicz.configure do |config|
32
+ config.app_name = 'APP_NAME'
33
+ config.contact = 'CONTACT_INFO'
34
+ end
35
+
36
+ artist_repo = Musicz::Search::ArtistRepository.new
37
+
38
+ # Search by ID
39
+ id_options = Musicz::Search::Options::IdSearch.new(id: 'ID')
40
+ artist = artist_repo.by_id(id_options)
41
+
42
+ # Search by term
43
+ term = 'SOME_BAND_NAME'
44
+ artist_list = artist_repo.by_term(term)
45
+ ```
46
+
47
+ Want to find an artist by term and then get some related information?
48
+
49
+ ```ruby
50
+ artist_repo = Musicz::Search::ArtistRepository.new
51
+ artist_list = artist_repo.by_term('A_BAND_NAME')
52
+ artist = artist_list.artists.first # Or get the one with the highest score
53
+ id_options = Musicz::Search::Options::IdSearch.new(id: artist.id, relationships: ['releases'])
54
+ full_artist = artist_repo.by_id(id_options)
55
+ ```
56
+
57
+ ## Development
58
+
59
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
60
+
61
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
62
+
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/derrickp/musicz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
66
+
67
+ ## License
68
+
69
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
70
+
71
+ ## Code of Conduct
72
+
73
+ Everyone interacting in the Musicz project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/derrickp/musicz/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'musicz'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/version"
4
+ require "musicz/configuration"
5
+ require "musicz/request"
6
+ require "musicz/entities"
7
+ require "musicz/search"
8
+
9
+ module Musicz
10
+ class Error < StandardError; end
11
+ # Your code goes here...
12
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Musicz
4
+ class Configuration
5
+ class NoConfigBlockGiven < RuntimeError; end
6
+
7
+ class InvalidConfiguration < RuntimeError; end
8
+
9
+ DEFAULT_BASE_URI = "https://musicbrainz.org/ws/2"
10
+ attr_accessor :base_uri, :app_name, :contact
11
+
12
+ def initialize(base_uri: DEFAULT_BASE_URI)
13
+ @base_uri = base_uri
14
+ end
15
+
16
+ def valid?
17
+ errors.empty?
18
+ end
19
+
20
+ def errors
21
+ [].tap do |arr|
22
+ arr << "No base_uri" if base_uri.nil?
23
+ arr << "No app_name" if app_name.nil?
24
+ arr << "No contact" if contact.nil?
25
+ end
26
+ end
27
+
28
+ def self.build_default
29
+ new.tap do |c|
30
+ c.app_name = "Musicz"
31
+ c.contact = "https://github.com/derrickp/musicz"
32
+ end
33
+ end
34
+ end
35
+
36
+ def self.clear
37
+ @config = nil
38
+ end
39
+
40
+ def self.config
41
+ @config
42
+ end
43
+
44
+ def self.config=(value)
45
+ unless value.is_a?(Configuration)
46
+ raise ArgumentError, "value is not a Configuration object"
47
+ end
48
+
49
+ raise ArgumentError, "invalid Configuration value" unless value.valid?
50
+
51
+ @config = value
52
+ end
53
+
54
+ def self.configure
55
+ raise Configuration::NoConfigBlockGiven unless block_given?
56
+
57
+ yield @config ||= Configuration.new
58
+ return if @config.valid?
59
+
60
+ raise Configuration::InvalidConfiguration, @config.errors
61
+ end
62
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entities/alias"
4
+ require "musicz/entities/area"
5
+ require "musicz/entities/artist_credit"
6
+ require "musicz/entities/artist_list"
7
+ require "musicz/entities/artist_reference"
8
+ require "musicz/entities/artist"
9
+ require "musicz/entities/disc_id"
10
+ require "musicz/entities/error"
11
+ require "musicz/entities/life_span"
12
+ require "musicz/entities/media"
13
+ require "musicz/entities/rating"
14
+ require "musicz/entities/recording_reference"
15
+ require "musicz/entities/recording"
16
+ require "musicz/entities/release_event"
17
+ require "musicz/entities/release_reference"
18
+ require "musicz/entities/release"
19
+ require "musicz/entities/tag"
20
+ require "musicz/entities/text_representation"
21
+ require "musicz/entities/track"
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+
5
+ module Musicz
6
+ module Entities
7
+ class Alias < Entity
8
+ attribute :name, Types::Strict::String
9
+ attribute :sort_name, Types::Strict::String
10
+ attribute? :locale, Types::Strict::String.optional
11
+ attribute :primary, Types::Strict::Bool.default(false)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+ require "musicz/entities/area_relation"
5
+
6
+ module Musicz
7
+ module Entities
8
+ class Area < Entity
9
+ attribute :id, Types::Strict::String
10
+ attribute :name, Types::Strict::String
11
+ attribute :sort_name, Types::Strict::String
12
+ attribute? :relations, Types::Array.of(AreaRelation).default([].freeze)
13
+ attribute :iso_3166_1_codes, Types::Array.of(Types::Strict::String)
14
+ .default([].freeze)
15
+ attribute? :disambiguation, Types::Strict::String.optional
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+
5
+ module Musicz
6
+ module Entities
7
+ class AreaReference < Entity
8
+ attribute :id, Types::Strict::String
9
+ attribute :name, Types::Strict::String
10
+ attribute :sort_name, Types::Strict::String
11
+ attribute? :disambiguation, Types::Strict::String.optional
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+ require "musicz/entities/area_reference"
5
+
6
+ module Musicz
7
+ module Entities
8
+ class AreaRelation < Entity
9
+ attribute? :attribute_ids, Types::Strict::Hash.optional
10
+ attribute :direction, Types::Strict::String
11
+ attribute :type_id, Types::Strict::String
12
+ attribute :ended, Types::Strict::Bool.default(false)
13
+ attribute? :end, Types::Strict::String.optional
14
+ attribute :area, AreaReference
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "musicz/entity"
4
+ require "musicz/entities/alias"
5
+ require "musicz/entities/life_span"
6
+ require "musicz/entities/rating"
7
+ require "musicz/entities/tag"
8
+ require "musicz/entities/release_reference"
9
+ require "musicz/entities/area"
10
+
11
+ module Musicz
12
+ module Entities
13
+ class Artist < Entity
14
+ attribute :id, Types::Strict::String
15
+ attribute :name, Types::Strict::String
16
+ attribute :sort_name, Types::Strict::String
17
+ attribute? :begin_area, Area.optional
18
+ attribute? :score, Types::Strict::Integer.optional
19
+ attribute? :country, Types::Strict::String.optional
20
+ attribute? :disambiguation, Types::Strict::String.optional
21
+ attribute? :type, Types::Strict::String.optional
22
+ attribute? :life_span, LifeSpan.optional
23
+ attribute :aliases, Types::Strict::Array.of(Alias).default([].freeze)
24
+ attribute :tags, Types::Strict::Array.of(Tag).default([].freeze)
25
+ attribute? :rating, Rating.optional
26
+ attribute? :releases, Types::Array.of(ReleaseReference).default([].freeze)
27
+ end
28
+ end
29
+ end