rubybrainz 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5a743e9be2b430c52023a7fe2b7d511f63c4391da7b5b8486df514db443a5ec2
4
+ data.tar.gz: 4ec6526f27f7cbf06ef80ae9e62d6cd07173e8d1230baef69dcb0b3ea93649e0
5
+ SHA512:
6
+ metadata.gz: 4e3751963c975823eda63fccbaf2f961c5c0ca7ebfa07c93ae3b23e3a5e5b26b58471781747f39d27f48d906c87543a6ab7f623af4a5adcf65b8b6137b088b06
7
+ data.tar.gz: d2a8e98da5ae848ba5e70534568056963d2e6cb42b31681433f6ba67473c9a2fc8995a8b2692c4d876024501dbfe7b3d0bb317ae3f5f0084d81ff9c7aa5aab2e
@@ -0,0 +1,11 @@
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
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,14 @@
1
+ Metrics/MethodLength:
2
+ Max: 30
3
+
4
+ AllCops:
5
+ NewCops: enable
6
+
7
+ Metrics/LineLength:
8
+ Max: 100
9
+
10
+ Metrics/BlockLength:
11
+ Max: 50
12
+
13
+ Metrics/AbcSize:
14
+ Enabled: false
@@ -0,0 +1,16 @@
1
+ ---
2
+ env: SKIP_INTERPRETER=true
3
+ sudo: false
4
+ language: ruby
5
+ cache: bundler
6
+ rvm:
7
+ - 2.6.3
8
+ before_install:
9
+ - gem install bundler -v 2.0.2
10
+ - bundle install
11
+ - git clone https://github.com/TravisToolbox/rubocop-travis.git
12
+ install:
13
+ - ./rubocop-travis/install.sh
14
+ script:
15
+ - ./rubocop-travis/scan.sh
16
+ - bundle exec rake spec
@@ -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 xanderriga@live.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,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'dry-struct'
6
+ gem 'dry-types'
7
+ gem 'httparty'
8
+ gem 'rake'
9
+ gem 'rubocop'
10
+ gem 'ruby-enum'
11
+
12
+ group :development do
13
+ gem 'pry'
14
+ gem 'vcr'
15
+ gem 'webmock'
16
+ end
17
+
18
+ # Specify your gem's dependencies in rubybrainz.gemspec
19
+ gemspec
@@ -0,0 +1,118 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubybrainz (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ ast (2.4.1)
12
+ coderay (1.1.3)
13
+ concurrent-ruby (1.1.7)
14
+ crack (0.4.4)
15
+ diff-lcs (1.4.4)
16
+ dry-configurable (0.11.6)
17
+ concurrent-ruby (~> 1.0)
18
+ dry-core (~> 0.4, >= 0.4.7)
19
+ dry-equalizer (~> 0.2)
20
+ dry-container (0.7.2)
21
+ concurrent-ruby (~> 1.0)
22
+ dry-configurable (~> 0.1, >= 0.1.3)
23
+ dry-core (0.4.10)
24
+ concurrent-ruby (~> 1.0)
25
+ dry-equalizer (0.3.0)
26
+ dry-inflector (0.2.0)
27
+ dry-logic (1.0.8)
28
+ concurrent-ruby (~> 1.0)
29
+ dry-core (~> 0.2)
30
+ dry-equalizer (~> 0.2)
31
+ dry-struct (1.3.0)
32
+ dry-core (~> 0.4, >= 0.4.4)
33
+ dry-equalizer (~> 0.3)
34
+ dry-types (~> 1.3)
35
+ ice_nine (~> 0.11)
36
+ dry-types (1.4.0)
37
+ concurrent-ruby (~> 1.0)
38
+ dry-container (~> 0.3)
39
+ dry-core (~> 0.4, >= 0.4.4)
40
+ dry-equalizer (~> 0.3)
41
+ dry-inflector (~> 0.1, >= 0.1.2)
42
+ dry-logic (~> 1.0, >= 1.0.2)
43
+ hashdiff (1.0.1)
44
+ httparty (0.18.1)
45
+ mime-types (~> 3.0)
46
+ multi_xml (>= 0.5.2)
47
+ i18n (1.8.5)
48
+ concurrent-ruby (~> 1.0)
49
+ ice_nine (0.11.2)
50
+ method_source (1.0.0)
51
+ mime-types (3.3.1)
52
+ mime-types-data (~> 3.2015)
53
+ mime-types-data (3.2020.1104)
54
+ multi_xml (0.6.0)
55
+ parallel (1.20.1)
56
+ parser (2.7.2.0)
57
+ ast (~> 2.4.1)
58
+ pry (0.13.1)
59
+ coderay (~> 1.1)
60
+ method_source (~> 1.0)
61
+ public_suffix (4.0.6)
62
+ rainbow (3.0.0)
63
+ rake (10.5.0)
64
+ regexp_parser (1.8.2)
65
+ rexml (3.2.4)
66
+ rspec (3.10.0)
67
+ rspec-core (~> 3.10.0)
68
+ rspec-expectations (~> 3.10.0)
69
+ rspec-mocks (~> 3.10.0)
70
+ rspec-core (3.10.0)
71
+ rspec-support (~> 3.10.0)
72
+ rspec-expectations (3.10.0)
73
+ diff-lcs (>= 1.2.0, < 2.0)
74
+ rspec-support (~> 3.10.0)
75
+ rspec-mocks (3.10.0)
76
+ diff-lcs (>= 1.2.0, < 2.0)
77
+ rspec-support (~> 3.10.0)
78
+ rspec-support (3.10.0)
79
+ rubocop (1.3.1)
80
+ parallel (~> 1.10)
81
+ parser (>= 2.7.1.5)
82
+ rainbow (>= 2.2.2, < 4.0)
83
+ regexp_parser (>= 1.8)
84
+ rexml
85
+ rubocop-ast (>= 1.1.1)
86
+ ruby-progressbar (~> 1.7)
87
+ unicode-display_width (>= 1.4.0, < 2.0)
88
+ rubocop-ast (1.1.1)
89
+ parser (>= 2.7.1.5)
90
+ ruby-enum (0.8.0)
91
+ i18n
92
+ ruby-progressbar (1.10.1)
93
+ unicode-display_width (1.7.0)
94
+ vcr (6.0.0)
95
+ webmock (3.10.0)
96
+ addressable (>= 2.3.6)
97
+ crack (>= 0.3.2)
98
+ hashdiff (>= 0.4.0, < 2.0.0)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ bundler (~> 2.0)
105
+ dry-struct
106
+ dry-types
107
+ httparty
108
+ pry
109
+ rake
110
+ rspec (~> 3.0)
111
+ rubocop
112
+ ruby-enum
113
+ rubybrainz!
114
+ vcr
115
+ webmock
116
+
117
+ BUNDLED WITH
118
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Xander
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,55 @@
1
+ # Rubybrainz
2
+
3
+ This is a wrapper for the [MusicBrainz API](https://musicbrainz.org/doc/MusicBrainz_API)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rubybrainz'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rubybrainz
20
+
21
+ ## Usage
22
+ ### Searching for an artist
23
+ Create an `ArtistParameter` object:
24
+
25
+ ```
26
+ artist_parameter = Rubybrainz::Entities::Request::ArtistParameter.new(artist: 'madeon')
27
+ ```
28
+
29
+ Call `Search.artist`
30
+
31
+ ```
32
+ response = Rubybrainz::Search.new.artist(artist_parameter: artist_parameter)
33
+ ```
34
+
35
+ Response will be an instance of `Rubybrainz::Entities::Response`. Since this was an artist query,
36
+ we can 0 or more artists in the `.artists` field on the response.
37
+
38
+
39
+ ## Development
40
+
41
+ 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.
42
+
43
+ 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).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/XanderRiga/rubybrainz. 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.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
52
+
53
+ ## Code of Conduct
54
+
55
+ Everyone interacting in the Rubybrainz project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rubybrainz/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 'rubybrainz'
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,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubybrainz/version'
4
+ require 'rubybrainz/entities/request/artist_parameter'
5
+
6
+ # This is the base module to use all of the rubybrainz module.
7
+ module Rubybrainz
8
+ autoload :Search, 'rubybrainz/search'
9
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby-enum'
4
+
5
+ module Rubybrainz
6
+ module Constants
7
+ # These are the possible types
8
+ class Type
9
+ include Ruby::Enum
10
+
11
+ define :artist, 'artist'
12
+ define :release, 'release'
13
+ define :release_group, 'release-group'
14
+ define :recording, 'recording'
15
+ define :work, 'work'
16
+ define :label, 'label'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubybrainz
4
+ # Where all the constants are gonna go
5
+ module Constants
6
+ module Urls
7
+ ROOT_URL = 'https://musicbrainz.org/ws/2/'
8
+ ARTIST_URL = "#{ROOT_URL}artist/"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubybrainz/entities/base'
4
+
5
+ module Rubybrainz
6
+ module Entities
7
+ # This is what MusicBrainz refers to as a an area
8
+ class Area < Base
9
+ attribute :id, Types::String
10
+ attribute :type, Types::String # Country, City, etc
11
+ attribute :type_id, Types::String
12
+ attribute :name, Types::String
13
+ attribute :sort_name, Types::String.optional.default(nil)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubybrainz/entities/base'
4
+ require 'rubybrainz/entities/area'
5
+
6
+ module Rubybrainz
7
+ module Entities
8
+ # This represents an artist in musicbrainz
9
+ class Artist < Base
10
+ attribute :id, Types::String
11
+ attribute :name, Types::String
12
+ attribute :sort_name, Types::String.optional.default(nil)
13
+ attribute :type, Types::String.optional.default(nil)
14
+ attribute :type_id, Types::String.optional.default(nil)
15
+ attribute :gender, Types::String.optional.default(nil)
16
+ attribute :country, Types::String.optional.default(nil)
17
+ attribute :area, Rubybrainz::Entities::Area.optional.default(nil)
18
+ attribute :begin_area, Rubybrainz::Entities::Area.optional.default(nil)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+ require 'rubybrainz/entities/types'
5
+
6
+ module Rubybrainz
7
+ module Entities
8
+ class Base < Dry::Struct
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubybrainz/entities/base'
4
+
5
+ module Rubybrainz
6
+ module Entities
7
+ module Request
8
+ # This defines a request to search for an artist
9
+ class ArtistParameter < Base
10
+ attribute :alias, Types::String.optional.default(nil)
11
+ attribute :area, Types::String.optional.default(nil)
12
+ attribute :arid, Types::String.optional.default(nil)
13
+ attribute :artist, Types::String.optional.default(nil)
14
+ attribute :artistaccent, Types::String.optional.default(nil)
15
+ attribute :begin, Types::String.optional.default(nil)
16
+ attribute :comment, Types::String.optional.default(nil)
17
+ attribute :country, Types::String.optional.default(nil)
18
+ attribute :end, Types::String.optional.default(nil)
19
+ attribute :endarea, Types::String.optional.default(nil)
20
+ attribute :ended, Types::String.optional.default(nil)
21
+ attribute :gender, Types::String.optional.default(nil)
22
+ attribute :ipi, Types::String.optional.default(nil)
23
+ attribute :sortname, Types::String.optional.default(nil)
24
+ attribute :tag, Types::String.optional.default(nil)
25
+ attribute :type, Types::String.optional.default(nil)
26
+
27
+ def query_string
28
+ existing_variables = []
29
+ to_h.each do |key, value|
30
+ existing_variables << ("#{key}:#{value}") if value
31
+ end
32
+
33
+ existing_variables.join(' AND ')
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubybrainz/entities/base'
4
+ require 'rubybrainz/entities/work'
5
+ require 'rubybrainz/entities/artist'
6
+
7
+ module Rubybrainz
8
+ module Entities
9
+ # This will be the object we return for all requests
10
+ class Response < Base
11
+ attribute :success, Types::Bool
12
+ attribute :message, Types::String
13
+ attribute :created, Types::String.optional.default(nil)
14
+ attribute :count, Types::Integer.optional.default(nil)
15
+ attribute :offset, Types::Integer.optional.default(nil)
16
+ attribute :works, Types::Array.of(Rubybrainz::Entities::Work).optional.default(nil)
17
+ attribute :artists, Types::Array.of(Rubybrainz::Entities::Artist).optional.default(nil)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-types'
4
+
5
+ module Rubybrainz
6
+ module Entities
7
+ # Our base types so we don't have to repeat this all over our data classes
8
+ module Types
9
+ include Dry.Types()
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubybrainz/entities/base'
4
+
5
+ module Rubybrainz
6
+ module Entities
7
+ # This is what MusicBrainz calls a "work" which is a track, song, etc
8
+ class Work < Base
9
+ attribute :id, Types::String
10
+ attribute :title, Types::String
11
+ attribute :type, Types::String.optional.default(nil)
12
+ attribute :score, Types::Integer.optional.default(nil)
13
+ attribute :language, Types::String.optional.default(nil)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require 'rubybrainz/interactors/build_response'
5
+
6
+ module Rubybrainz
7
+ # This is the class that will handle our request/response directly.
8
+ class Http
9
+ def get(url:, query:, limit: 25)
10
+ response = HTTParty.get(
11
+ url,
12
+ headers: {
13
+ 'Accept' => 'application/json',
14
+ 'User-Agent' => 'rubybrainz (xanderriga@live.com)'
15
+ },
16
+ query: { query: query, limit: limit }
17
+ )
18
+
19
+ response_builder.call(httparty_response: response)
20
+ end
21
+
22
+ private
23
+
24
+ def response_builder
25
+ @response_builder ||= Rubybrainz::Interactors::BuildResponse.new
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubybrainz/entities/response'
4
+ require 'rubybrainz/transforms/json_to_artist'
5
+
6
+ module Rubybrainz
7
+ module Interactors
8
+ # This is how we will build a reasonable Rubybrainz response for each request
9
+ class BuildResponse
10
+ def call(httparty_response:)
11
+ if httparty_response.code == 200
12
+ body = JSON.parse(httparty_response.body)
13
+ Rubybrainz::Entities::Response.new(
14
+ success: true,
15
+ message: httparty_response.message,
16
+ created: body['created'],
17
+ count: body['count'],
18
+ offset: body['offset'],
19
+ artists: body['artists'].map { |artist| json_to_artist.call(json_artist: artist) }
20
+ )
21
+ else
22
+ Rubybrainz::Entities::Response.new(
23
+ success: false,
24
+ message: httparty_response.message,
25
+ created: body['created'],
26
+ count: body['count'],
27
+ offset: body['offset']
28
+ )
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def json_to_artist
35
+ @json_to_artist ||= Rubybrainz::Transforms::JsonToArtist.new
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubybrainz/http'
4
+ require 'rubybrainz/constants/urls'
5
+
6
+ module Rubybrainz
7
+ # The thing that should be called to actually hit MusicBrainz search API
8
+ class Search
9
+ def artist(artist_parameter:)
10
+ client.get(
11
+ url: Rubybrainz::Constants::Urls::ARTIST_URL,
12
+ query: artist_parameter.query_string
13
+ )
14
+ end
15
+
16
+ private
17
+
18
+ def client
19
+ @client ||= Rubybrainz::Http.new
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubybrainz/entities/area'
4
+
5
+ module Rubybrainz
6
+ module Transforms
7
+ # Convert response json to an area
8
+ class JsonToArea
9
+ def call(json_area:)
10
+ Rubybrainz::Entities::Area.new(
11
+ id: json_area['id'],
12
+ type: json_area['type'],
13
+ type_id: json_area['type-id'],
14
+ name: json_area['name'],
15
+ sort_name: json_area['sort-name']
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubybrainz/entities/artist'
4
+ require 'rubybrainz/transforms/json_to_area'
5
+
6
+ module Rubybrainz
7
+ module Transforms
8
+ # Convert response json to an artist
9
+ class JsonToArtist
10
+ def call(json_artist:)
11
+ Rubybrainz::Entities::Artist.new(
12
+ id: json_artist['id'],
13
+ name: json_artist['name'],
14
+ sort_name: json_artist['sort-name'],
15
+ type: json_artist['type'],
16
+ type_id: json_artist['type-id'],
17
+ gender: json_artist['gender'],
18
+ country: json_artist['country'],
19
+ area: json_to_area.call(json_area: json_artist['area']),
20
+ begin_area: json_to_area.call(json_area: json_artist['begin-area'])
21
+ )
22
+ end
23
+
24
+ private
25
+
26
+ def json_to_area
27
+ @json_to_area ||= Rubybrainz::Transforms::JsonToArea.new
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubybrainz
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rubybrainz/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.required_ruby_version = '>= 2.6.0'
9
+ spec.name = 'rubybrainz'
10
+ spec.version = Rubybrainz::VERSION
11
+ spec.authors = ['Xander Riga']
12
+ spec.email = ['xanderriga@live.com']
13
+
14
+ spec.summary = 'Wrapper for the MusicBrainz API'
15
+ spec.description = 'Wrapper for the MusicBrainz API'
16
+ spec.homepage = 'https://github.com/XanderRiga/rubybrainz'
17
+ spec.license = 'MIT'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/XanderRiga/rubybrainz'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/XanderRiga/rubybrainz'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_development_dependency 'bundler', '~> 2.0'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.0'
35
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubybrainz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Xander Riga
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-26 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Wrapper for the MusicBrainz API
56
+ email:
57
+ - xanderriga@live.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - lib/rubybrainz.rb
75
+ - lib/rubybrainz/constants/type.rb
76
+ - lib/rubybrainz/constants/urls.rb
77
+ - lib/rubybrainz/entities/area.rb
78
+ - lib/rubybrainz/entities/artist.rb
79
+ - lib/rubybrainz/entities/base.rb
80
+ - lib/rubybrainz/entities/request/artist_parameter.rb
81
+ - lib/rubybrainz/entities/response.rb
82
+ - lib/rubybrainz/entities/types.rb
83
+ - lib/rubybrainz/entities/work.rb
84
+ - lib/rubybrainz/http.rb
85
+ - lib/rubybrainz/interactors/build_response.rb
86
+ - lib/rubybrainz/search.rb
87
+ - lib/rubybrainz/transforms/json_to_area.rb
88
+ - lib/rubybrainz/transforms/json_to_artist.rb
89
+ - lib/rubybrainz/version.rb
90
+ - rubybrainz.gemspec
91
+ homepage: https://github.com/XanderRiga/rubybrainz
92
+ licenses:
93
+ - MIT
94
+ metadata:
95
+ homepage_uri: https://github.com/XanderRiga/rubybrainz
96
+ source_code_uri: https://github.com/XanderRiga/rubybrainz
97
+ changelog_uri: https://github.com/XanderRiga/rubybrainz
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 2.6.0
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Wrapper for the MusicBrainz API
117
+ test_files: []