crawlora-modrinth 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: 38d51c7236e6e877ee828a915542fa9a0f9340e94310897c7f0f64103657f06e
4
+ data.tar.gz: f0e25f50e408f9b5827e8d501a59ffe21916706101281e4f6c2df382b8dfb22c
5
+ SHA512:
6
+ metadata.gz: 4efc381b31049ec192dabcbe752d9c8ccd29b22bf48b9f2fb4c948c1a3a645caa2856156ad2a25a31bf26547eb3ed86d744e63898f048ca48a25bd1b4f0d37c9
7
+ data.tar.gz: f1ff56019aee9a1ff03868e478930d41fff0e075d0b535d2f6596b8753204bd0a45735e1d6a71381ca31425c82a634686e54900798103fd7a5c1317bd14035f2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Initial focused Modrinth Ruby client for Crawlora's hosted API.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Crawlora
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Crawlora Modrinth API client for Ruby (`crawlora-modrinth`)
2
+
3
+ This Ruby gem calls Crawlora's hosted Modrinth API at `https://api.crawlora.net/api/v1`. It exposes 34 endpoints covering project search and metadata, versions, dependencies, collections, organizations, and file compatibility; it does not call or scrape Modrinth directly. Requests require your Crawlora API key and use your account's service plan.
4
+
5
+ ## Install
6
+
7
+ ```ruby
8
+ gem "crawlora-modrinth"
9
+ ```
10
+
11
+ Create an account at [crawlora.net](https://crawlora.net/signup?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=modrinth-ruby-signup), open the [Crawlora console](https://crawlora.net/app?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=modrinth-ruby-console) to get an API key, and set `CRAWLORA_API_KEY` before running the client:
12
+
13
+ ```ruby
14
+ require "json"
15
+ require "crawlora/modrinth"
16
+
17
+ client = Crawlora::Modrinth::Client.new
18
+ result = client.request("modrinth-search", JSON.parse("{\"query\": \"sample\"}"))
19
+ puts result
20
+ client.close
21
+ ```
22
+
23
+ Use an operation-specific method for normal calls. `request(operation_id, params = {}, response_type: :auto)` is available for every operation. `response_type: :text` returns raw response text. This gem includes 34 API operations.
24
+
25
+ ```ruby
26
+ client = Crawlora::Modrinth::Client.new(api_key: ENV.fetch("CRAWLORA_API_KEY"), timeout: 30)
27
+ # client.<operation_method>(<endpoint parameters>)
28
+ client.close
29
+ ```
30
+
31
+ Client options include `api_key`, `base_url`, and `timeout`. Ruby stdlib provides the HTTP and JSON support.
32
+
33
+ ## Supported Modrinth API endpoints
34
+
35
+ Browse every route included in this gem. The [endpoint reference](https://github.com/Crawlora-org/crawlora-modrinth/blob/main/docs/usage.md) includes parameter and response details.
36
+
37
+ | Method | Endpoint | API operation | Description |
38
+ | --- | --- | --- | --- |
39
+ | `GET` | `/modrinth/collection/{id}` | `modrinth-collection` | Read a public Modrinth collection |
40
+ | `GET` | `/modrinth/collections` | `modrinth-collections` | Resolve public Modrinth collections |
41
+ | `GET` | `/modrinth/metadata/link-platforms` | `modrinth-metadata-link-platforms` | Get Modrinth link platforms |
42
+ | `GET` | `/modrinth/metadata/loader-fields` | `modrinth-metadata-loader-fields` | Discover Modrinth loader fields |
43
+ | `GET` | `/modrinth/metadata/loader-fields/{field}` | `modrinth-metadata-loader-field-values` | Get Modrinth loader-field values |
44
+ | `GET` | `/modrinth/metadata/loaders` | `modrinth-metadata-loaders` | Get Modrinth loader capabilities |
45
+ | `GET` | `/modrinth/organization/{id}` | `modrinth-organization` | Read a public Modrinth organization |
46
+ | `GET` | `/modrinth/organization/{id}/projects` | `modrinth-organization-projects` | Read a public organization's Modrinth projects |
47
+ | `GET` | `/modrinth/organizations` | `modrinth-organizations` | Resolve public Modrinth organizations |
48
+ | `GET` | `/modrinth/project/{id}` | `modrinth-project` | Get a Modrinth project |
49
+ | `GET` | `/modrinth/project/{id}/check` | `modrinth-check-project` | Resolve a project ID or slug |
50
+ | `GET` | `/modrinth/project/{id}/dependencies` | `modrinth-dependencies` | Get project dependency metadata |
51
+ | `GET` | `/modrinth/project/{id}/disclosures` | `modrinth-project-disclosures` | Get Modrinth public project disclosures |
52
+ | `GET` | `/modrinth/project/{id}/version` | `modrinth-project-versions` | List project versions |
53
+ | `GET` | `/modrinth/project/{id}/version/{number}` | `modrinth-project-version` | Get a project version by number or ID |
54
+ | `GET` | `/modrinth/projects` | `modrinth-projects` | Get native multiple-project metadata |
55
+ | `GET` | `/modrinth/projects_random` | `modrinth-random-projects` | Get native random projects |
56
+ | `GET` | `/modrinth/search` | `modrinth-search` | Search Modrinth projects |
57
+ | `GET` | `/modrinth/statistics` | `modrinth-statistics` | Get Modrinth instance statistics |
58
+ | `GET` | `/modrinth/tag/license/{id}` | `modrinth-license` | Get source license title and text |
59
+ | `GET` | `/modrinth/tag/{type}` | `modrinth-tags` | Discover Modrinth catalog values |
60
+ | `GET` | `/modrinth/updates/{id}/forge_updates.json` | `modrinth-forge-updates` | Get native Forge update metadata |
61
+ | `GET` | `/modrinth/v3/search` | `modrinth-search-v3` | Search current Modrinth projects and servers |
62
+ | `POST` | `/modrinth/v3/search` | `modrinth-search-v3-body` | Search Modrinth using the native v3 JSON body |
63
+ | `GET` | `/modrinth/v3/search/options` | `modrinth-search-v3-options` | Discover Modrinth v3 search options |
64
+ | `GET` | `/modrinth/version/{id}` | `modrinth-version` | Get a version by ID |
65
+ | `POST` | `/modrinth/version_file/project` | `modrinth-file-projects` | Resolve file hashes to projects |
66
+ | `GET` | `/modrinth/version_file/{hash}` | `modrinth-file-version` | Resolve a version by file hash |
67
+ | `POST` | `/modrinth/version_file/{hash}/update` | `modrinth-file-update` | Resolve a compatible update for a file |
68
+ | `POST` | `/modrinth/version_files` | `modrinth-file-versions` | Resolve file hashes to versions |
69
+ | `POST` | `/modrinth/version_files/update` | `modrinth-files-update` | Resolve compatible updates for files |
70
+ | `POST` | `/modrinth/version_files/update_individual` | `modrinth-files-update-individual` | Resolve updates with per-file filters |
71
+ | `POST` | `/modrinth/version_files/update_many` | `modrinth-files-update-many` | List compatible update versions for files |
72
+ | `GET` | `/modrinth/versions` | `modrinth-versions` | Get native multiple-version metadata |
73
+
74
+ See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=modrinth-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=modrinth-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-modrinth) for account setup, the API operation reference, and release history.
@@ -0,0 +1,332 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ module Crawlora
6
+ module Modrinth
7
+ module Errors
8
+ class Error < StandardError
9
+ attr_reader :status, :operation_id, :body
10
+
11
+ def initialize(message, status: nil, operation_id: nil, body: nil)
12
+ super(message)
13
+ @status, @operation_id, @body = status, operation_id, body
14
+ end
15
+ end
16
+ class ClientError < Error; end
17
+ class ServerError < Error; end
18
+ class NetworkError < Error; end
19
+ end
20
+
21
+ OPERATIONS = JSON.parse(<<~'JSON').freeze
22
+ {"modrinth-check-project": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-check-project", "method": "GET", "params": [{"description": "Native id", "in": "path", "name": "id", "required": true, "type": "string"}], "path": "/modrinth/project/{id}/check", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-collection": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-collection", "method": "GET", "params": [{"description": "Base62 collection ID from a public collection URL", "in": "path", "name": "id", "required": true, "type": "string"}], "path": "/modrinth/collection/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-collections": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-collections", "method": "GET", "params": [{"description": "Native JSON array of base62 collection IDs; [] is valid", "in": "query", "name": "ids", "required": true, "type": "string"}], "path": "/modrinth/collections", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "ids", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "modrinth-dependencies": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-dependencies", "method": "GET", "params": [{"description": "Native id", "in": "path", "name": "id", "required": true, "type": "string"}], "path": "/modrinth/project/{id}/dependencies", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-file-projects": {"bodyParam": "body", "bodyRequired": true, "id": "modrinth-file-projects", "method": "POST", "params": [{"description": "Native metadata lookup body", "in": "body", "name": "body", "required": true, "schema": {"$ref": "#/definitions/modrinth.HashesRequest"}}], "path": "/modrinth/version_file/project", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-file-update": {"bodyParam": "body", "bodyRequired": true, "id": "modrinth-file-update", "method": "POST", "params": [{"description": "Native hash", "in": "path", "name": "hash", "required": true, "type": "string"}, {"description": "File-hash algorithm; omitted uses native auto-detection", "enum": ["sha1", "sha512"], "in": "query", "name": "algorithm", "type": "string"}, {"description": "Native metadata lookup body", "in": "body", "name": "body", "required": true, "schema": {"$ref": "#/definitions/modrinth.FiltersRequest"}}], "path": "/modrinth/version_file/{hash}/update", "pathParams": ["hash"], "produces": ["application/json"], "queryParams": [{"enum": ["sha1", "sha512"], "in": "query", "name": "algorithm", "type": "string"}], "security": ["ApiKeyAuth"]}, "modrinth-file-version": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-file-version", "method": "GET", "params": [{"description": "Native hash", "in": "path", "name": "hash", "required": true, "type": "string"}, {"description": "File-hash algorithm; omitted uses native auto-detection", "enum": ["sha1", "sha512"], "in": "query", "name": "algorithm", "type": "string"}], "path": "/modrinth/version_file/{hash}", "pathParams": ["hash"], "produces": ["application/json"], "queryParams": [{"enum": ["sha1", "sha512"], "in": "query", "name": "algorithm", "type": "string"}], "security": ["ApiKeyAuth"]}, "modrinth-file-versions": {"bodyParam": "body", "bodyRequired": true, "id": "modrinth-file-versions", "method": "POST", "params": [{"description": "Native metadata lookup body", "in": "body", "name": "body", "required": true, "schema": {"$ref": "#/definitions/modrinth.HashesRequest"}}], "path": "/modrinth/version_files", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-files-update": {"bodyParam": "body", "bodyRequired": true, "id": "modrinth-files-update", "method": "POST", "params": [{"description": "Native metadata lookup body", "in": "body", "name": "body", "required": true, "schema": {"$ref": "#/definitions/modrinth.HashUpdatesRequest"}}], "path": "/modrinth/version_files/update", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-files-update-individual": {"bodyParam": "body", "bodyRequired": true, "id": "modrinth-files-update-individual", "method": "POST", "params": [{"description": "Native metadata lookup body", "in": "body", "name": "body", "required": true, "schema": {"$ref": "#/definitions/modrinth.IndividualUpdatesRequest"}}], "path": "/modrinth/version_files/update_individual", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-files-update-many": {"bodyParam": "body", "bodyRequired": true, "id": "modrinth-files-update-many", "method": "POST", "params": [{"description": "Native metadata lookup body", "in": "body", "name": "body", "required": true, "schema": {"$ref": "#/definitions/modrinth.HashUpdatesRequest"}}], "path": "/modrinth/version_files/update_many", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-forge-updates": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-forge-updates", "method": "GET", "params": [{"description": "Native id", "in": "path", "name": "id", "required": true, "type": "string"}, {"description": "Native NeoForge selection; omitted retains Forge default", "enum": ["include", "only"], "in": "query", "name": "neoforge", "type": "string"}], "path": "/modrinth/updates/{id}/forge_updates.json", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"enum": ["include", "only"], "in": "query", "name": "neoforge", "type": "string"}], "security": ["ApiKeyAuth"]}, "modrinth-license": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-license", "method": "GET", "params": [{"description": "Native id", "in": "path", "name": "id", "required": true, "type": "string"}], "path": "/modrinth/tag/license/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-metadata-link-platforms": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-metadata-link-platforms", "method": "GET", "params": [], "path": "/modrinth/metadata/link-platforms", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-metadata-loader-field-values": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-metadata-loader-field-values", "method": "GET", "params": [{"description": "Source field name from loader-field discovery", "in": "path", "name": "field", "required": true, "type": "string"}], "path": "/modrinth/metadata/loader-fields/{field}", "pathParams": ["field"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-metadata-loader-fields": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-metadata-loader-fields", "method": "GET", "params": [], "path": "/modrinth/metadata/loader-fields", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-metadata-loaders": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-metadata-loaders", "method": "GET", "params": [], "path": "/modrinth/metadata/loaders", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-organization": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-organization", "method": "GET", "params": [{"description": "Organization ID or slug from a public organization URL or project metadata", "in": "path", "name": "id", "required": true, "type": "string"}], "path": "/modrinth/organization/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-organization-projects": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-organization-projects", "method": "GET", "params": [{"description": "Organization ID or slug from a public organization URL or project metadata", "in": "path", "name": "id", "required": true, "type": "string"}], "path": "/modrinth/organization/{id}/projects", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-organizations": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-organizations", "method": "GET", "params": [{"description": "Native JSON array of organization IDs or slugs; [] is valid", "in": "query", "name": "ids", "required": true, "type": "string"}], "path": "/modrinth/organizations", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "ids", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "modrinth-project": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-project", "method": "GET", "params": [{"description": "Native id", "in": "path", "name": "id", "required": true, "type": "string"}], "path": "/modrinth/project/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-project-disclosures": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-project-disclosures", "method": "GET", "params": [{"description": "Native project ID or canonical slug", "in": "path", "name": "id", "required": true, "type": "string"}], "path": "/modrinth/project/{id}/disclosures", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-project-version": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-project-version", "method": "GET", "params": [{"description": "Native id", "in": "path", "name": "id", "required": true, "type": "string"}, {"description": "Native number", "in": "path", "name": "number", "required": true, "type": "string"}], "path": "/modrinth/project/{id}/version/{number}", "pathParams": ["id", "number"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-project-versions": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-project-versions", "method": "GET", "params": [{"description": "Native id", "in": "path", "name": "id", "required": true, "type": "string"}, {"description": "JSON array of loader names from the loader tag catalog", "in": "query", "name": "loaders", "type": "string"}, {"description": "JSON array of game versions from the game_version tag catalog", "in": "query", "name": "game_versions", "type": "string"}, {"description": "Native featured selector; false is distinct from omission", "in": "query", "name": "featured", "type": "boolean"}, {"default": true, "description": "Include changelog fields", "in": "query", "name": "include_changelog", "type": "boolean"}], "path": "/modrinth/project/{id}/version", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "loaders", "type": "string"}, {"in": "query", "name": "game_versions", "type": "string"}, {"in": "query", "name": "featured", "type": "boolean"}, {"in": "query", "name": "include_changelog", "type": "boolean"}], "security": ["ApiKeyAuth"]}, "modrinth-projects": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-projects", "method": "GET", "params": [{"description": "JSON-encoded array of native identifiers; absent members are omitted", "in": "query", "name": "ids", "required": true, "type": "string"}], "path": "/modrinth/projects", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "ids", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "modrinth-random-projects": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-random-projects", "method": "GET", "params": [{"description": "Number of random projects, 1 to 100", "in": "query", "name": "count", "required": true, "type": "integer"}], "path": "/modrinth/projects_random", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "count", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "modrinth-search": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-search", "method": "GET", "params": [{"description": "Search text", "in": "query", "name": "query", "type": "string"}, {"description": "Native JSON array of OR groups joined by AND; see the full facet reference", "in": "query", "name": "facets", "type": "string"}, {"description": "Native search order", "enum": ["relevance", "downloads", "follows", "newest", "updated"], "in": "query", "name": "index", "type": "string"}, {"default": 0, "description": "Native result offset, at least zero", "in": "query", "name": "offset", "type": "integer"}, {"default": 10, "description": "Native result limit, zero to 100", "in": "query", "name": "limit", "type": "integer"}], "path": "/modrinth/search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "query", "type": "string"}, {"in": "query", "name": "facets", "type": "string"}, {"enum": ["relevance", "downloads", "follows", "newest", "updated"], "in": "query", "name": "index", "type": "string"}, {"in": "query", "name": "offset", "type": "integer"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "modrinth-search-v3": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-search-v3", "method": "GET", "params": [{"description": "Native search text", "in": "query", "name": "query", "type": "string"}, {"description": "Native v3 order", "enum": ["relevance", "downloads", "follows", "newest", "updated", "date_created", "date_modified", "minecraft_java_server.verified_plays_2w", "minecraft_java_server.ping.data.players_online"], "in": "query", "name": "index", "type": "string"}, {"description": "Native nonnegative offset; default0", "in": "query", "name": "offset", "type": "integer"}, {"description": "Native nonnegative limit; default10; source normalizes to1–100", "in": "query", "name": "limit", "type": "integer"}, {"description": "Native current filter expression, forwarded unchanged", "in": "query", "name": "new_filters", "type": "string"}, {"description": "Legacy JSON array of string arrays using v3 field names", "in": "query", "name": "facets", "type": "string"}, {"description": "Legacy filter-expression clause", "in": "query", "name": "filters", "type": "string"}, {"description": "Legacy secondary filter-expression clause", "in": "query", "name": "version", "type": "string"}], "path": "/modrinth/v3/search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "query", "type": "string"}, {"enum": ["relevance", "downloads", "follows", "newest", "updated", "date_created", "date_modified", "minecraft_java_server.verified_plays_2w", "minecraft_java_server.ping.data.players_online"], "in": "query", "name": "index", "type": "string"}, {"in": "query", "name": "offset", "type": "integer"}, {"in": "query", "name": "limit", "type": "integer"}, {"in": "query", "name": "new_filters", "type": "string"}, {"in": "query", "name": "facets", "type": "string"}, {"in": "query", "name": "filters", "type": "string"}, {"in": "query", "name": "version", "type": "string"}], "security": ["ApiKeyAuth"]}, "modrinth-search-v3-body": {"bodyParam": "body", "bodyRequired": true, "id": "modrinth-search-v3-body", "method": "POST", "params": [{"description": "Native search body; offset/limit are strings", "in": "body", "name": "body", "required": true, "schema": {"$ref": "#/definitions/modrinth.SearchV3BodyRequest"}}], "path": "/modrinth/v3/search", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-search-v3-options": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-search-v3-options", "method": "GET", "params": [], "path": "/modrinth/v3/search/options", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-statistics": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-statistics", "method": "GET", "params": [], "path": "/modrinth/statistics", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-tags": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-tags", "method": "GET", "params": [{"description": "Native type", "enum": ["category", "loader", "game_version", "license", "donation_platform", "report_type", "project_type", "side_type"], "in": "path", "name": "type", "required": true, "type": "string"}], "path": "/modrinth/tag/{type}", "pathParams": ["type"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-version": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-version", "method": "GET", "params": [{"description": "Native id", "in": "path", "name": "id", "required": true, "type": "string"}], "path": "/modrinth/version/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "modrinth-versions": {"bodyParam": null, "bodyRequired": false, "id": "modrinth-versions", "method": "GET", "params": [{"description": "JSON-encoded array of native identifiers; absent members are omitted", "in": "query", "name": "ids", "required": true, "type": "string"}], "path": "/modrinth/versions", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "ids", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}}
23
+ JSON
24
+ OPERATION_IDS = JSON.parse(<<~'JSON').freeze
25
+ ["modrinth-check-project", "modrinth-collection", "modrinth-collections", "modrinth-dependencies", "modrinth-file-projects", "modrinth-file-update", "modrinth-file-version", "modrinth-file-versions", "modrinth-files-update", "modrinth-files-update-individual", "modrinth-files-update-many", "modrinth-forge-updates", "modrinth-license", "modrinth-metadata-link-platforms", "modrinth-metadata-loader-field-values", "modrinth-metadata-loader-fields", "modrinth-metadata-loaders", "modrinth-organization", "modrinth-organization-projects", "modrinth-organizations", "modrinth-project", "modrinth-project-disclosures", "modrinth-project-version", "modrinth-project-versions", "modrinth-projects", "modrinth-random-projects", "modrinth-search", "modrinth-search-v3", "modrinth-search-v3-body", "modrinth-search-v3-options", "modrinth-statistics", "modrinth-tags", "modrinth-version", "modrinth-versions"]
26
+ JSON
27
+ OPERATION_COUNT = OPERATION_IDS.length
28
+
29
+ class Client
30
+ attr_reader :base_url
31
+
32
+ def initialize(api_key: ENV["CRAWLORA_API_KEY"], base_url: "https://api.crawlora.net/api/v1", timeout: 30, user_agent: "crawlora-modrinth-ruby/0.1.0", transport: nil)
33
+ @api_key = api_key
34
+ @base_url = base_url.to_s.sub(%r{/+$}, "")
35
+ @timeout = Float(timeout)
36
+ @user_agent = user_agent
37
+ @transport = transport
38
+ @closed = false
39
+ end
40
+
41
+ def request(operation_id, params = {}, response_type: :auto)
42
+ raise Errors::ClientError, "client is closed" if @closed
43
+ operation_id = operation_id.to_s
44
+ operation = OPERATIONS[operation_id]
45
+ raise Errors::ClientError.new("unknown operation: #{operation_id}", operation_id: operation_id) unless operation
46
+ raise Errors::ClientError.new("Crawlora API key is required", operation_id: operation_id) if @api_key.nil? || @api_key.to_s.empty?
47
+ normalized = params.each_with_object({}) { |(key, value), out| out[key.to_s] = value }
48
+ payload = request_body(operation, normalized)
49
+ url = build_url(operation, normalized)
50
+ uri = URI.parse(url)
51
+ request = operation["method"] == "POST" ? Net::HTTP::Post.new(uri) : Net::HTTP::Get.new(uri)
52
+ unless payload.nil?
53
+ request.body = payload
54
+ request["Content-Type"] = "application/json"
55
+ end
56
+ request["x-api-key"] = @api_key
57
+ request["User-Agent"] = @user_agent
58
+ request["Accept"] = operation["produces"].include?("text/plain") ? "application/json, text/plain" : "application/json"
59
+ begin
60
+ if @transport
61
+ response = if operation["method"] == "POST"
62
+ @transport.call(url, request.to_hash, @timeout, "POST", payload)
63
+ else
64
+ @transport.call(url, request.to_hash, @timeout)
65
+ end
66
+ status = Integer(response.fetch(:status) { response.fetch("status") })
67
+ body = response.fetch(:body) { response.fetch("body", "") }
68
+ headers = response.fetch(:headers) { response.fetch("headers", {}) }
69
+ content_type = headers["content-type"] || headers["Content-Type"]
70
+ else
71
+ http = Net::HTTP.new(uri.host, uri.port)
72
+ http.use_ssl = uri.scheme == "https"
73
+ http.open_timeout = @timeout
74
+ http.read_timeout = @timeout
75
+ response = http.start { |connection| connection.request(request) }
76
+ status = response.code.to_i
77
+ body = response.body
78
+ content_type = response["content-type"]
79
+ end
80
+ rescue Timeout::Error, SocketError, SystemCallError, IOError, EOFError, Net::HTTPBadResponse, Net::ProtocolError, OpenSSL::SSL::SSLError => error
81
+ raise Errors::NetworkError.new("Crawlora request failed: #{error.message}", operation_id: operation_id)
82
+ end
83
+ unless status >= 200 && status < 300
84
+ klass = status >= 500 ? Errors::ServerError : Errors::ClientError
85
+ raise klass.new("Crawlora returned HTTP #{status}", status: status, operation_id: operation_id, body: body)
86
+ end
87
+ parse_response(body, content_type, operation, normalized, response_type)
88
+ end
89
+
90
+ def close
91
+ @closed = true
92
+ end
93
+
94
+ def closed?
95
+ @closed
96
+ end
97
+
98
+ def with
99
+ return self unless block_given?
100
+ yield self
101
+ ensure
102
+ close if block_given?
103
+ end
104
+
105
+ def self.operation_count
106
+ OPERATION_COUNT
107
+ end
108
+
109
+ def self.operation_ids
110
+ OPERATION_IDS
111
+ end
112
+
113
+ def self.operations
114
+ OPERATIONS
115
+ end
116
+
117
+ define_method('collection') do |**params|
118
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
119
+ request('modrinth-collection', params, response_type: response_type)
120
+ end
121
+ define_method('collections') do |**params|
122
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
123
+ request('modrinth-collections', params, response_type: response_type)
124
+ end
125
+ define_method('metadata_link_platforms') do |**params|
126
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
127
+ request('modrinth-metadata-link-platforms', params, response_type: response_type)
128
+ end
129
+ define_method('metadata_loader_fields') do |**params|
130
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
131
+ request('modrinth-metadata-loader-fields', params, response_type: response_type)
132
+ end
133
+ define_method('metadata_loader_field_values') do |**params|
134
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
135
+ request('modrinth-metadata-loader-field-values', params, response_type: response_type)
136
+ end
137
+ define_method('metadata_loaders') do |**params|
138
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
139
+ request('modrinth-metadata-loaders', params, response_type: response_type)
140
+ end
141
+ define_method('organization') do |**params|
142
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
143
+ request('modrinth-organization', params, response_type: response_type)
144
+ end
145
+ define_method('organization_projects') do |**params|
146
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
147
+ request('modrinth-organization-projects', params, response_type: response_type)
148
+ end
149
+ define_method('organizations') do |**params|
150
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
151
+ request('modrinth-organizations', params, response_type: response_type)
152
+ end
153
+ define_method('project') do |**params|
154
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
155
+ request('modrinth-project', params, response_type: response_type)
156
+ end
157
+ define_method('check_project') do |**params|
158
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
159
+ request('modrinth-check-project', params, response_type: response_type)
160
+ end
161
+ define_method('dependencies') do |**params|
162
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
163
+ request('modrinth-dependencies', params, response_type: response_type)
164
+ end
165
+ define_method('project_disclosures') do |**params|
166
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
167
+ request('modrinth-project-disclosures', params, response_type: response_type)
168
+ end
169
+ define_method('project_versions') do |**params|
170
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
171
+ request('modrinth-project-versions', params, response_type: response_type)
172
+ end
173
+ define_method('project_version') do |**params|
174
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
175
+ request('modrinth-project-version', params, response_type: response_type)
176
+ end
177
+ define_method('projects') do |**params|
178
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
179
+ request('modrinth-projects', params, response_type: response_type)
180
+ end
181
+ define_method('random_projects') do |**params|
182
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
183
+ request('modrinth-random-projects', params, response_type: response_type)
184
+ end
185
+ define_method('search') do |**params|
186
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
187
+ request('modrinth-search', params, response_type: response_type)
188
+ end
189
+ define_method('statistics') do |**params|
190
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
191
+ request('modrinth-statistics', params, response_type: response_type)
192
+ end
193
+ define_method('license') do |**params|
194
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
195
+ request('modrinth-license', params, response_type: response_type)
196
+ end
197
+ define_method('tags') do |**params|
198
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
199
+ request('modrinth-tags', params, response_type: response_type)
200
+ end
201
+ define_method('forge_updates') do |**params|
202
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
203
+ request('modrinth-forge-updates', params, response_type: response_type)
204
+ end
205
+ define_method('search_v3') do |**params|
206
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
207
+ request('modrinth-search-v3', params, response_type: response_type)
208
+ end
209
+ define_method('search_v3_body') do |**params|
210
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
211
+ request('modrinth-search-v3-body', params, response_type: response_type)
212
+ end
213
+ define_method('search_v3_options') do |**params|
214
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
215
+ request('modrinth-search-v3-options', params, response_type: response_type)
216
+ end
217
+ define_method('version') do |**params|
218
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
219
+ request('modrinth-version', params, response_type: response_type)
220
+ end
221
+ define_method('file_projects') do |**params|
222
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
223
+ request('modrinth-file-projects', params, response_type: response_type)
224
+ end
225
+ define_method('file_version') do |**params|
226
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
227
+ request('modrinth-file-version', params, response_type: response_type)
228
+ end
229
+ define_method('file_update') do |**params|
230
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
231
+ request('modrinth-file-update', params, response_type: response_type)
232
+ end
233
+ define_method('file_versions') do |**params|
234
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
235
+ request('modrinth-file-versions', params, response_type: response_type)
236
+ end
237
+ define_method('files_update') do |**params|
238
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
239
+ request('modrinth-files-update', params, response_type: response_type)
240
+ end
241
+ define_method('files_update_individual') do |**params|
242
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
243
+ request('modrinth-files-update-individual', params, response_type: response_type)
244
+ end
245
+ define_method('files_update_many') do |**params|
246
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
247
+ request('modrinth-files-update-many', params, response_type: response_type)
248
+ end
249
+ define_method('versions') do |**params|
250
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
251
+ request('modrinth-versions', params, response_type: response_type)
252
+ end
253
+
254
+ private
255
+
256
+ # POST operations take their JSON body under the body parameter name or "body".
257
+ def request_body(operation, params)
258
+ name = operation["bodyParam"]
259
+ return nil if name.nil?
260
+ value = params.key?(name) ? params[name] : params["body"]
261
+ if value.nil?
262
+ raise Errors::ClientError.new("missing request body: #{name}", operation_id: operation["id"]) if operation["bodyRequired"]
263
+ return nil
264
+ end
265
+ value.is_a?(String) ? value : JSON.generate(value)
266
+ end
267
+
268
+ def build_url(operation, params)
269
+ known = operation["params"].map { |param| param["name"] }
270
+ known << "body" if operation["bodyParam"]
271
+ unknown = params.keys - known
272
+ raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
273
+ path = operation["path"].dup
274
+ operation["params"].select { |param| param["in"] == "path" }.each do |param|
275
+ value = params[param["name"]]
276
+ raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
277
+ path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
278
+ end
279
+ pairs = []
280
+ operation["queryParams"].each do |param|
281
+ name = param["name"]
282
+ value = params.key?(name) ? params[name] : param["default"]
283
+ if value.nil?
284
+ raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
285
+ next
286
+ end
287
+ enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
288
+ if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
289
+ raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
290
+ end
291
+ if value.is_a?(Array)
292
+ format = param["collectionFormat"] || "csv"
293
+ if format == "multi"
294
+ value.each { |item| pairs << [name, scalar(item)] }
295
+ else
296
+ separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
297
+ pairs << [name, value.map { |item| scalar(item) }.join(separator)]
298
+ end
299
+ else
300
+ pairs << [name, scalar(value)]
301
+ end
302
+ end
303
+ query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
304
+ @base_url + path + (query.empty? ? "" : "?" + query)
305
+ end
306
+
307
+ def scalar(value)
308
+ value == true ? "true" : (value == false ? "false" : value.to_s)
309
+ end
310
+
311
+ def percent_encode(value)
312
+ URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
313
+ end
314
+
315
+ def parse_response(body, content_type, operation, params, response_type)
316
+ type = response_type.to_s
317
+ raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
318
+ format = operation["params"].find { |param| param["name"] == "format" }
319
+ text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
320
+ raw_format = params["format"] && text_formats.include?(params["format"].to_s)
321
+ json_format = format && format["enum"] && format["enum"].any? { |value| %w[json application/json].include?(value.to_s.downcase) } && %w[json application/json].include?(params["format"].to_s.downcase)
322
+ is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
323
+ return body if type == "text" || raw_format || (type == "auto" && !is_json)
324
+ JSON.parse(body)
325
+ rescue JSON::ParserError => error
326
+ raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
327
+ end
328
+
329
+ public
330
+ end
331
+ end
332
+ end
@@ -0,0 +1,5 @@
1
+ module Crawlora
2
+ module Modrinth
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require_relative "modrinth/version"
2
+ require_relative "modrinth/client"
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crawlora-modrinth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Crawlora
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-11-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby client for Crawlora's hosted Modrinth API. Covers project search
14
+ and metadata, versions, dependencies, collections, organizations, and file compatibility
15
+ across 34 endpoints.
16
+ email:
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.md
22
+ - LICENSE
23
+ - README.md
24
+ - lib/crawlora/modrinth.rb
25
+ - lib/crawlora/modrinth/client.rb
26
+ - lib/crawlora/modrinth/version.rb
27
+ homepage: https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=modrinth-ruby-homepage
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ source_code_uri: https://github.com/Crawlora-org/crawlora-modrinth
32
+ documentation_uri: https://github.com/Crawlora-org/crawlora-modrinth/blob/main/ruby/README.md
33
+ rubygems_mfa_required: 'true'
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '2.6'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.4.19
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Modrinth API client for Crawlora (34 endpoints)
53
+ test_files: []