omi-clients 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 707c10caf0cbc1fbde84af118e236e4a9790f3b9666dd93e3b8bd26408da7df5
4
+ data.tar.gz: 63b8ccd1e43589f4a90d80362e59dfdf9bc4c9cb97c8c1726862bebf0a4981e5
5
+ SHA512:
6
+ metadata.gz: 519c17d04677cb962e43a2c2f1f7f2bb0d25a3107fab52df7dd7cb6e17e65c34c7fd0bdaab620d9e502db90eb1c200bd10b0802ed397205080afb251847edfd8
7
+ data.tar.gz: e6a0e09f0bd03e0840f39c58483d9d9a703e0a3047d91d00fb6065755f48ccfb93b0e6c6ab55c270c97d7b97ec882618d25d9c0f31244036938ded0b7d65d9d6
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 4.0.1
data/AGENTS.md ADDED
@@ -0,0 +1,33 @@
1
+ # Omi Clients - Agent Guide
2
+
3
+ Welcome to the `omi-clients` codebase! This document outlines what you need to know to work effectively in this repository.
4
+
5
+ ## Project Type
6
+ This is a Ruby gem project that provides various client implementations (like `HttpClient`, `IfpiClient`, `MlcClient`, etc.) under the `Omi::Clients` module.
7
+
8
+ ## Essential Commands
9
+
10
+ The project uses `rake` to orchestrate common tasks.
11
+
12
+ * **Run all tests and linting (Default):** `bundle exec rake`
13
+ * **Run tests only:** `bundle exec rake spec` or `bundle exec rspec`
14
+ * **Run linting only:** `bundle exec rake rubocop` or `bundle exec rubocop`
15
+
16
+ ## Code Organization & Structure
17
+
18
+ * **`lib/omi/clients.rb`**: The main entry point for the gem, defining the `Omi::Clients` module.
19
+ * **`lib/omi/clients/`**: Contains the core logic and various client implementations (e.g., `http_client.rb`, `ifpi_client.rb`).
20
+ * **`spec/`**: Contains all the RSpec tests. Follows the structure of the `lib/` directory.
21
+ * **`HttpClient`**: The `HttpClient` module (`lib/omi/clients/http_client.rb`) provides a standardized way to make HTTP requests (`request(method:, base:, path:, ...)`).
22
+
23
+ ## Coding Conventions & Style
24
+
25
+ * **String Literals**: Use **double quotes** for strings and string interpolation. This is strictly enforced by RuboCop in `.rubocop.yml`.
26
+ * **Frozen String Literal**: All Ruby files should begin with `# frozen_string_literal: true`.
27
+ * **Linting**: The project uses RuboCop. Always ensure your code passes `bundle exec rubocop` after making changes.
28
+
29
+ ## Testing Approach
30
+
31
+ * The project uses **RSpec** for testing.
32
+ * Tests should be placed in the `spec/` directory, mirroring the structure of the `lib/` directory.
33
+ * Run tests frequently using `bundle exec rake spec` to verify your changes. Note that the default generated tests may contain an intentionally failing test (`expect(false).to eq(true)`), be mindful when running tests on a fresh codebase.
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-03-23
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Chris Garrett
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.
data/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # Omi::Clients
2
+
3
+ Welcome to the `omi-clients` gem! This library provides easy-to-use API clients for communicating with various music rights and data organizations:
4
+ - **MLC Client**: Connects to The Mechanical Licensing Collective (MLC) API to search for works and matched recordings.
5
+ - **USCO Client**: Connects to the US Copyright Office API to search public records.
6
+ - **IFPI Client**: Connects to the IFPI ISRC API (via SoundExchange) to search for recordings and ISRCs.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'omi-clients'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```bash
19
+ bundle install
20
+ ```
21
+
22
+ Or install it yourself as:
23
+
24
+ ```bash
25
+ gem install omi-clients
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ Below are examples of how to initialize and use each of the available clients.
31
+
32
+ ### MLC Client
33
+
34
+ The `MlcClient` allows you to search for works and recordings in The Mechanical Licensing Collective database.
35
+
36
+ ```ruby
37
+ require 'omi/clients'
38
+
39
+ client = MlcClient.new
40
+
41
+ # Search for a work by title
42
+ works = client.search_works('yesterday', size: 1)
43
+ ```
44
+
45
+ **Example Response:**
46
+ ```json
47
+ {
48
+ "content": [
49
+ {
50
+ "id": 992933336,
51
+ "title": "YESTERDAY",
52
+ "songCode": "YP8CWO",
53
+ "writers": [
54
+ {
55
+ "fullName": "JESSE J SANDERS",
56
+ "ipiNumber": "00819749198",
57
+ "roleCode": 11
58
+ }
59
+ ]
60
+ }
61
+ ],
62
+ "number": 1,
63
+ "size": 1,
64
+ "totalElements": 10835
65
+ }
66
+ ```
67
+
68
+ ### USCO Client
69
+
70
+ The `UscoClient` interacts with the US Copyright Office API to query registered copyright records.
71
+
72
+ ```ruby
73
+ require 'omi/clients'
74
+
75
+ client = UscoClient.new
76
+
77
+ # Search the USCO public records
78
+ records = client.search('yesterday', size: 1)
79
+ ```
80
+
81
+ **Example Response:**
82
+ ```json
83
+ {
84
+ "metadata": {
85
+ "took_ms": 43,
86
+ "hit_count": 31849,
87
+ "max_score": 54.251675
88
+ },
89
+ "data": [
90
+ {
91
+ "score": 54.251675,
92
+ "hit": {
93
+ "author": ["MARVIN F. MOODY"],
94
+ "title_of_work": ["Today and Yesterday"],
95
+ "registration_number": ["AA 448496"],
96
+ "registration_status": "published",
97
+ "first_published_date": ["1944-02-10"]
98
+ }
99
+ }
100
+ ]
101
+ }
102
+ ```
103
+
104
+ ### IFPI Client
105
+
106
+ The `IfpiClient` searches the IFPI ISRC database to find recording information and ISRCs. *Note: You must call `login!` before performing any searches to fetch the required authentication token.*
107
+
108
+ ```ruby
109
+ require 'omi/clients'
110
+
111
+ client = IfpiClient.new
112
+
113
+ # Fetch authentication token
114
+ client.login!
115
+
116
+ # Search for recordings (number must be between 10 and 100)
117
+ recordings = client.search_recordings(recording_title: 'yesterday', number: 10)
118
+ ```
119
+
120
+ **Example Response:**
121
+ ```json
122
+ {
123
+ "numberOfRecordings": 10000,
124
+ "show_releases": true,
125
+ "recordings": [
126
+ {
127
+ "duration": "5:23",
128
+ "recordingType": "Audio",
129
+ "recordingYear": "2017",
130
+ "recordingArtistName": "Eric Reed",
131
+ "isrc": "USL4Q1776253",
132
+ "recordingTitle": "Yesterday - Yesterdays",
133
+ "id": "USL4Q1776253"
134
+ }
135
+ ]
136
+ }
137
+ ```
138
+
139
+ ## Development
140
+
141
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the tests and linter. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
142
+
143
+ ## License
144
+
145
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
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
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+
7
+ # A module to make HTTP requests
8
+ module HttpClient
9
+ def request(method:, base:, path:, **options)
10
+ uri = build_uri(base, path, options[:query])
11
+ req = prepare_request(method, uri, options)
12
+ res = execute_request(req, uri)
13
+ handle_response(res)
14
+ end
15
+
16
+ private
17
+
18
+ def prepare_request(method, uri, options)
19
+ req = build_request(method, uri)
20
+ headers = options[:headers] || {}
21
+ default_headers.merge(headers).each { |k, v| req[k] = v }
22
+ req.body = options[:body] if options[:body]
23
+ req
24
+ end
25
+
26
+ def execute_request(req, uri)
27
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
28
+ http.request(req)
29
+ end
30
+ end
31
+
32
+ def handle_response(res)
33
+ raise "#{self.class} API error: #{res.code} – #{res.body}" unless res.is_a?(Net::HTTPSuccess)
34
+
35
+ JSON.parse(res.body)
36
+ end
37
+
38
+ def build_uri(base, path, query)
39
+ uri = URI.join(base.end_with?('/') ? base : "#{base}/", path)
40
+ uri.query = URI.encode_www_form(query) if query&.any?
41
+ uri
42
+ end
43
+
44
+ def build_request(method, uri)
45
+ case method
46
+ when :get then Net::HTTP::Get.new(uri)
47
+ when :post then Net::HTTP::Post.new(uri)
48
+ else
49
+ raise ArgumentError, "Unsupported HTTP method: #{method}"
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'literal'
4
+ require_relative './http_client'
5
+
6
+ # Client for IFPI ISRC API
7
+ class IfpiClient < Literal::Object
8
+ include HttpClient
9
+
10
+ API_BASE = 'https://isrc-api.soundexchange.com/api/ext'
11
+ USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) ' \
12
+ 'AppleWebKit/537.36 (KHTML, like Gecko) ' \
13
+ 'Chrome/138.0.0.0 Safari/537.36'
14
+ TOKEN_TTL = 3600
15
+
16
+ prop :token, _String?
17
+ prop :token_fetched_at, _String?
18
+
19
+ def login!
20
+ resp = request(
21
+ method: :get,
22
+ base: API_BASE,
23
+ path: 'login',
24
+ headers: login_headers
25
+ )
26
+
27
+ @token = resp.fetch('token')
28
+ @token_fetched_at = Time.now
29
+ self
30
+ end
31
+
32
+ def search_recordings(**args)
33
+ raise 'Call login! first' unless valid_token?
34
+
35
+ request(
36
+ method: :post,
37
+ base: API_BASE,
38
+ path: 'recordings',
39
+ body: build_search_payload(**args).to_json,
40
+ headers: default_headers.merge('Authorization' => "Token #{@token}")
41
+ )
42
+ end
43
+
44
+ private
45
+
46
+ def build_search_payload(**kwargs)
47
+ {
48
+ searchFields: {
49
+ recordingArtistName: { value: kwargs[:recording_artist_name].to_s },
50
+ recordingTitle: { value: kwargs[:recording_title].to_s },
51
+ releaseName: { value: kwargs[:release_name].to_s }
52
+ },
53
+ start: kwargs.fetch(:start, 0),
54
+ number: kwargs.fetch(:number, 100),
55
+ showReleases: kwargs.fetch(:show_releases, true)
56
+ }
57
+ end
58
+
59
+ def valid_token?
60
+ @token &&
61
+ @token_fetched_at &&
62
+ (Time.now - @token_fetched_at) < TOKEN_TTL
63
+ end
64
+
65
+ def default_headers
66
+ {
67
+ 'Accept' => 'application/json',
68
+ 'Content-Type' => 'application/json',
69
+ 'User-Agent' => USER_AGENT
70
+ }
71
+ end
72
+
73
+ def login_headers
74
+ {
75
+ 'Accept' => 'application/json',
76
+ 'Authorization' => 'Token undefined',
77
+ 'Content-Type' => 'application/json',
78
+ 'User-Agent' => USER_AGENT
79
+ }
80
+ end
81
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './http_client'
4
+
5
+ # Client for MLC API
6
+ class MlcClient
7
+ include HttpClient
8
+
9
+ API_BASE = 'https://api.ptl.themlc.com/api'
10
+ API_2_BASE = 'https://api.ptl.themlc.com/api2v/public'
11
+ DSP_BASE = 'https://api.ptl.themlc.com/api/dsp-recording'
12
+ USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) ' \
13
+ 'AppleWebKit/537.36 (KHTML, like Gecko) ' \
14
+ 'Chrome/138.0.0.0 Safari/537.36'
15
+
16
+ def search_works(title, writer_names: nil, page: 1, size: 100)
17
+ request(
18
+ method: :post,
19
+ base: API_2_BASE,
20
+ path: 'search/works',
21
+ query: { page:, size: },
22
+ body: { title:, writerFullNames: writer_names }.compact.to_json
23
+ )
24
+ end
25
+
26
+ def matched_recordings(song_code, limit: 100, page: 1, order: 'matchedAmount', direction: 'desc')
27
+ request(
28
+ method: :get,
29
+ base: DSP_BASE,
30
+ path: "matched/#{song_code}",
31
+ query: { limit:, page:, order:, direction: }
32
+ )
33
+ end
34
+
35
+ def get_work(work_id)
36
+ request(
37
+ method: :get,
38
+ base: API_BASE,
39
+ path: "catalog/work/#{work_id}"
40
+ )
41
+ end
42
+
43
+ private
44
+
45
+ def default_headers
46
+ {
47
+ 'Accept' => 'application/json',
48
+ 'User-Agent' => USER_AGENT,
49
+ 'Content-Type' => 'application/json'
50
+ }
51
+ end
52
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './http_client'
4
+
5
+ # Client for US Copyright Office API
6
+ class UscoClient
7
+ include HttpClient
8
+
9
+ API_BASE = 'https://api.publicrecords.copyright.gov'
10
+
11
+ USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) ' \
12
+ 'AppleWebKit/537.36 (KHTML, like Gecko) ' \
13
+ 'Chrome/138.0.0.0 Safari/537.36'
14
+
15
+ def search(query, **options)
16
+ request(
17
+ method: :get,
18
+ base: API_BASE,
19
+ path: 'search_service_external/simple_search_dsl',
20
+ query: build_search_query(query, **options)
21
+ )
22
+ end
23
+
24
+ private
25
+
26
+ def build_search_query(query, **options)
27
+ {
28
+ query:,
29
+ page_number: options.fetch(:page, 1),
30
+ records_per_page: options.fetch(:size, 100),
31
+ field_type: options.fetch(:field_type, 'keyword'),
32
+ sort_order: options.fetch(:sort, 'asc'),
33
+ model: options.fetch(:model, '')
34
+ }
35
+ end
36
+
37
+ def default_headers
38
+ {
39
+ 'Accept' => 'application/json',
40
+ 'User-Agent' => USER_AGENT,
41
+ 'Content-Type' => 'application/json'
42
+ }
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omi
4
+ module Clients
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'clients/version'
4
+ require 'literal'
5
+ require_relative 'clients/http_client'
6
+ require_relative 'clients/ifpi_client'
7
+ require_relative 'clients/mlc_client'
8
+ require_relative 'clients/usco_client'
9
+
10
+ module Omi
11
+ module Clients
12
+ class Error < StandardError; end
13
+ # Your code goes here...
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module Omi
2
+ module Clients
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omi-clients
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Open Music Initiative
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: literal
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.9'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.9'
26
+ description: Access datasets like the MLC, IFPI and USCO to access data critical to
27
+ songwriters and artists.
28
+ email:
29
+ - chris@chrsgrrtt.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".ruby-version"
35
+ - AGENTS.md
36
+ - CHANGELOG.md
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - lib/omi/clients.rb
41
+ - lib/omi/clients/http_client.rb
42
+ - lib/omi/clients/ifpi_client.rb
43
+ - lib/omi/clients/mlc_client.rb
44
+ - lib/omi/clients/usco_client.rb
45
+ - lib/omi/clients/version.rb
46
+ - sig/omi/clients.rbs
47
+ homepage: https://github.com/open-music-initiative/omi-clients
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/open-music-initiative/omi-clients
52
+ source_code_uri: https://github.com/open-music-initiative/omi-clients
53
+ changelog_uri: https://github.com/open-music-initiative/omi-clients
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 4.0.1
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 4.0.3
69
+ specification_version: 4
70
+ summary: A range of clients to access critical music data repositories.
71
+ test_files: []