crawlora-boardgamegeek 0.2.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +58 -0
- data/lib/crawlora/boardgamegeek/client.rb +268 -0
- data/lib/crawlora/boardgamegeek/version.rb +5 -0
- data/lib/crawlora/boardgamegeek.rb +2 -0
- metadata +52 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9c9f0e639e1b95d52a5cce02bf72020e871c4f9a0571ec3516e037b4205b7b5f
|
|
4
|
+
data.tar.gz: 35897d402a321f14f58a5a950b9c78e66bbf7663afa8944e3c60cf1b0ecca3af
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a09330a02f849b34f1e04227b23d82d14d30bb669abe2a5256a05cc762cb23093e3aa5a4b6d2d9c8bf555a6437d50d8a1bbb0ed63c8d82b78d12b11a90d682d6
|
|
7
|
+
data.tar.gz: 12bc5b94f351603e024bb926ec061aef4967fb0d690faea6a78a8351aade81f45c4b46f7186a892bab6c3c0cc88d3629ecdfd4339cb402e77acd61a7c388745f
|
data/CHANGELOG.md
ADDED
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,58 @@
|
|
|
1
|
+
# Crawlora BoardGameGeek API client for Ruby (`crawlora-boardgamegeek`)
|
|
2
|
+
|
|
3
|
+
This Ruby gem calls Crawlora's hosted BoardGameGeek API at `https://api.crawlora.net/api/v1`. It exposes 18 endpoints covering public game, geeklist, review, thread, and taxonomy data; it does not call or scrape BoardGameGeek directly. Requests require your Crawlora API key and use your account's service plan.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "crawlora-boardgamegeek"
|
|
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=boardgamegeek-ruby-signup), open the [Crawlora console](https://crawlora.net/app?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=boardgamegeek-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/boardgamegeek"
|
|
16
|
+
|
|
17
|
+
client = Crawlora::Boardgamegeek::Client.new
|
|
18
|
+
result = client.request("boardgamegeek-blog", JSON.parse("{\"id\": \"sample-id\"}"))
|
|
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 18 API operations.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
client = Crawlora::Boardgamegeek::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 BoardGameGeek API endpoints
|
|
34
|
+
|
|
35
|
+
Browse every route included in this gem. The [endpoint reference](https://github.com/Crawlora-org/crawlora-boardgamegeek/blob/main/docs/usage.md) includes parameter and response details.
|
|
36
|
+
|
|
37
|
+
| Method | Endpoint | API operation | Description |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| `GET` | `/boardgamegeek/blog/{id}` | `boardgamegeek-blog` | Get a BoardGameGeek blog's detail |
|
|
40
|
+
| `GET` | `/boardgamegeek/blogpost/{id}` | `boardgamegeek-blogpost` | Get a BoardGameGeek blog post |
|
|
41
|
+
| `GET` | `/boardgamegeek/blogposts` | `boardgamegeek-blogposts` | List recent BoardGameGeek blog posts |
|
|
42
|
+
| `GET` | `/boardgamegeek/blogs` | `boardgamegeek-blogs` | List BoardGameGeek blogs |
|
|
43
|
+
| `GET` | `/boardgamegeek/cardsets/{id}` | `boardgamegeek-cardsets` | List a BoardGameGeek game's card sets |
|
|
44
|
+
| `GET` | `/boardgamegeek/entity/{type}/{id}` | `boardgamegeek-entity` | Get a BoardGameGeek family, person, company, property or version |
|
|
45
|
+
| `GET` | `/boardgamegeek/game/{id}` | `boardgamegeek-game` | Get a BoardGameGeek game's detail, ratings and links |
|
|
46
|
+
| `GET` | `/boardgamegeek/geeklist/{id}` | `boardgamegeek-geeklist` | Get a BoardGameGeek geeklist's detail |
|
|
47
|
+
| `GET` | `/boardgamegeek/geeklist/{id}/items` | `boardgamegeek-geeklist-items` | List a BoardGameGeek geeklist's entries |
|
|
48
|
+
| `GET` | `/boardgamegeek/geeklists` | `boardgamegeek-geeklists` | List geeklists that link a BoardGameGeek object |
|
|
49
|
+
| `GET` | `/boardgamegeek/hotness` | `boardgamegeek-hotness` | Get BoardGameGeek's current hotness list |
|
|
50
|
+
| `GET` | `/boardgamegeek/links` | `boardgamegeek-links` | List a BoardGameGeek object's typed links |
|
|
51
|
+
| `GET` | `/boardgamegeek/media/{id}` | `boardgamegeek-media` | List a BoardGameGeek item's images, videos or files |
|
|
52
|
+
| `GET` | `/boardgamegeek/recommendations/{id}` | `boardgamegeek-recommendations` | Get BoardGameGeek recommendations for a game |
|
|
53
|
+
| `GET` | `/boardgamegeek/reviews/{type}/{id}` | `boardgamegeek-reviews` | List a BoardGameGeek object's reviews |
|
|
54
|
+
| `GET` | `/boardgamegeek/taxonomy` | `boardgamegeek-taxonomy` | List BoardGameGeek's object-type, subtype and link-type enums |
|
|
55
|
+
| `GET` | `/boardgamegeek/thread/{id}` | `boardgamegeek-thread` | Get a BoardGameGeek thread and one page of its articles |
|
|
56
|
+
| `GET` | `/boardgamegeek/threads` | `boardgamegeek-threads` | List a BoardGameGeek object's forum threads |
|
|
57
|
+
|
|
58
|
+
See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=boardgamegeek-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=boardgamegeek-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-boardgamegeek) for account setup, the API operation reference, and release history.
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Crawlora
|
|
6
|
+
module Boardgamegeek
|
|
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
|
+
{"boardgamegeek-blog": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-blog", "method": "GET", "params": [{"description": "BoardGameGeek blog id, positive integer; the BoardGameGeek Blog is 1", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "1"}], "path": "/boardgamegeek/blog/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "boardgamegeek-blogpost": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-blogpost", "method": "GET", "params": [{"description": "BoardGameGeek blog post id, positive integer from boardgamegeek_blogposts", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "194175"}], "path": "/boardgamegeek/blogpost/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "boardgamegeek-blogposts": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-blogposts", "method": "GET", "params": [{"description": "Post sort: recent (default) or hot", "enum": ["recent", "hot"], "in": "query", "name": "sort", "type": "string"}, {"description": "Optional blogger id (a post creator id), positive integer; lists only that blogger's recent posts", "in": "query", "name": "bloggerid", "type": "integer", "x-example": 20607}], "path": "/boardgamegeek/blogposts", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["recent", "hot"], "in": "query", "name": "sort", "type": "string"}, {"in": "query", "name": "bloggerid", "type": "integer"}], "security": ["ApiKeyAuth"]}, "boardgamegeek-blogs": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-blogs", "method": "GET", "params": [{"description": "Directory sort: active (recently updated, default) or recent (newly created)", "enum": ["active", "recent"], "in": "query", "name": "sort", "type": "string"}, {"description": "Page number, 1-1000; the source pages 25 blogs at a time and has about 248 pages", "in": "query", "name": "pageid", "type": "integer", "x-example": 1}], "path": "/boardgamegeek/blogs", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["active", "recent"], "in": "query", "name": "sort", "type": "string"}, {"in": "query", "name": "pageid", "type": "integer"}], "security": ["ApiKeyAuth"]}, "boardgamegeek-cardsets": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-cardsets", "method": "GET", "params": [{"description": "BoardGameGeek game id, positive integer; Catan is 13", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "13"}], "path": "/boardgamegeek/cardsets/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "boardgamegeek-entity": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-entity", "method": "GET", "params": [{"description": "Entity object type", "enum": ["family", "person", "company", "property", "version"], "in": "path", "name": "type", "required": true, "type": "string"}, {"description": "BoardGameGeek entity id, positive integer; the Catan family is 3", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "3"}], "path": "/boardgamegeek/entity/{type}/{id}", "pathParams": ["type", "id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "boardgamegeek-game": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-game", "method": "GET", "params": [{"description": "BoardGameGeek game (thing) id, positive integer; Catan is 13", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "13"}], "path": "/boardgamegeek/game/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "boardgamegeek-geeklist": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-geeklist", "method": "GET", "params": [{"description": "BoardGameGeek geeklist id, positive integer", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "387123"}], "path": "/boardgamegeek/geeklist/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "boardgamegeek-geeklist-items": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-geeklist-items", "method": "GET", "params": [{"description": "BoardGameGeek geeklist id, positive integer", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "387123"}, {"description": "Entry page number, 1-1000; the source pages entries 25 at a time", "in": "query", "name": "page", "type": "integer", "x-example": 1}], "path": "/boardgamegeek/geeklist/{id}/items", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "boardgamegeek-geeklists": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-geeklists", "method": "GET", "params": [{"description": "Object type: thing, family, person, company, property or version. Defaults to thing.", "enum": ["thing", "family", "person", "company", "property", "version"], "in": "query", "name": "objecttype", "type": "string", "x-example": "thing"}, {"description": "Object identifier, positive integer; Catan is 13", "in": "query", "name": "objectid", "required": true, "type": "integer", "x-example": 13}, {"description": "Category filter: all, trade or general. Defaults to general.", "enum": ["all", "trade", "general"], "in": "query", "name": "category", "type": "string", "x-example": "general"}, {"description": "Sort: hot or recent. Defaults to hot.", "enum": ["hot", "recent"], "in": "query", "name": "sort", "type": "string", "x-example": "hot"}, {"description": "Page size, 1-50", "in": "query", "name": "showcount", "type": "integer", "x-example": 25}, {"description": "Page number, 1-1000", "in": "query", "name": "pageid", "type": "integer", "x-example": 1}], "path": "/boardgamegeek/geeklists", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["thing", "family", "person", "company", "property", "version"], "in": "query", "name": "objecttype", "type": "string"}, {"in": "query", "name": "objectid", "required": true, "type": "integer"}, {"enum": ["all", "trade", "general"], "in": "query", "name": "category", "type": "string"}, {"enum": ["hot", "recent"], "in": "query", "name": "sort", "type": "string"}, {"in": "query", "name": "showcount", "type": "integer"}, {"in": "query", "name": "pageid", "type": "integer"}], "security": ["ApiKeyAuth"]}, "boardgamegeek-hotness": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-hotness", "method": "GET", "params": [{"description": "Object type; one of thing (games), person or company", "enum": ["thing", "person", "company"], "in": "query", "name": "objecttype", "type": "string", "x-example": "thing"}, {"description": "Requested list length, 1-50; the source caps the list at 50", "in": "query", "name": "showcount", "type": "integer", "x-example": 50}], "path": "/boardgamegeek/hotness", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["thing", "person", "company"], "in": "query", "name": "objecttype", "type": "string"}, {"in": "query", "name": "showcount", "type": "integer"}], "security": ["ApiKeyAuth"]}, "boardgamegeek-links": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-links", "method": "GET", "params": [{"description": "Canonical object type that owns the links", "enum": ["thing", "family", "person", "company", "property", "version"], "in": "query", "name": "objecttype", "required": true, "type": "string", "x-example": "thing"}, {"description": "Object identifier, positive integer; Catan is 13", "in": "query", "name": "objectid", "required": true, "type": "integer", "x-example": 13}, {"description": "Link type; must be one of the values verified for the object type (see boardgamegeek-taxonomy)", "enum": ["boardgame", "boardgameaccessory", "boardgameaccessoryartist", "boardgameaccessorydesigner", "boardgameartist", "boardgamecategory", "boardgamedesigner", "boardgamedeveloper", "boardgameeditor", "boardgameexpansion", "boardgamefamily", "boardgamegraphicdesigner", "boardgamehonor", "boardgameinsertdesigner", "boardgameintegration", "boardgameissue", "boardgameissueartist", "boardgameissueauthor", "boardgamemechanic", "boardgamepublisher", "boardgamesculptor", "boardgamesolodesigner", "boardgamesubdomain", "boardgameversion", "boardgameversionartist", "boardgamewriter", "cardset", "containedin", "contains", "expandsboardgame", "expandsvideogame", "languages", "reimplementation", "reimplements", "rpgartist", "rpgdesigner", "rpghonor", "rpgissuearticleauthor", "rpgissueartist", "rpgissuedesigner", "rpgissueproducer", "rpgproducer", "videogamebg", "videogamedeveloper", "videogameexpansion", "videogamefranchise", "videogamegenre", "videogamemode", "videogameplatform", "videogamepublisher", "videogameseries", "videogametheme"], "in": "query", "name": "linktype", "required": true, "type": "string", "x-example": "boardgamemechanic"}, {"description": "Page size, 1-50", "in": "query", "name": "showcount", "type": "integer", "x-example": 25}, {"description": "Page number, 1-1000", "in": "query", "name": "pageid", "type": "integer", "x-example": 1}], "path": "/boardgamegeek/links", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["thing", "family", "person", "company", "property", "version"], "in": "query", "name": "objecttype", "required": true, "type": "string"}, {"in": "query", "name": "objectid", "required": true, "type": "integer"}, {"enum": ["boardgame", "boardgameaccessory", "boardgameaccessoryartist", "boardgameaccessorydesigner", "boardgameartist", "boardgamecategory", "boardgamedesigner", "boardgamedeveloper", "boardgameeditor", "boardgameexpansion", "boardgamefamily", "boardgamegraphicdesigner", "boardgamehonor", "boardgameinsertdesigner", "boardgameintegration", "boardgameissue", "boardgameissueartist", "boardgameissueauthor", "boardgamemechanic", "boardgamepublisher", "boardgamesculptor", "boardgamesolodesigner", "boardgamesubdomain", "boardgameversion", "boardgameversionartist", "boardgamewriter", "cardset", "containedin", "contains", "expandsboardgame", "expandsvideogame", "languages", "reimplementation", "reimplements", "rpgartist", "rpgdesigner", "rpghonor", "rpgissuearticleauthor", "rpgissueartist", "rpgissuedesigner", "rpgissueproducer", "rpgproducer", "videogamebg", "videogamedeveloper", "videogameexpansion", "videogamefranchise", "videogamegenre", "videogamemode", "videogameplatform", "videogamepublisher", "videogameseries", "videogametheme"], "in": "query", "name": "linktype", "required": true, "type": "string"}, {"in": "query", "name": "showcount", "type": "integer"}, {"in": "query", "name": "pageid", "type": "integer"}], "security": ["ApiKeyAuth"]}, "boardgamegeek-media": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-media", "method": "GET", "params": [{"description": "BoardGameGeek item (thing) id, positive integer; Catan is 13", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "13"}, {"description": "Media kind; defaults to image", "enum": ["image", "video", "file"], "in": "query", "name": "type", "type": "string", "x-example": "image"}, {"description": "Page size, 1-50", "in": "query", "name": "showcount", "type": "integer", "x-example": 25}, {"description": "Page number, 1-1000", "in": "query", "name": "pageid", "type": "integer", "x-example": 1}, {"description": "Sort order; applies to images, videos and files", "enum": ["hot", "recent"], "in": "query", "name": "sort", "type": "string", "x-example": "hot"}, {"description": "Image date interval; image only", "enum": ["alltime", "today", "twodays", "last7", "last30", "year"], "in": "query", "name": "interval", "type": "string", "x-example": "alltime"}, {"description": "Gallery filter. Images: all, game, person, creative. Videos: all, review, session, instructional, interview, unboxing, humor, other. Not valid for files.", "enum": ["all", "game", "person", "creative", "review", "session", "instructional", "interview", "unboxing", "humor", "other"], "in": "query", "name": "gallery", "type": "string", "x-example": "all"}, {"description": "Image category; image only", "enum": ["BoxFront", "BoxBack", "Components", "Customized", "Play", "Miscellaneous", "uncat"], "in": "query", "name": "tag", "type": "string"}, {"description": "Image license filter; image only", "enum": ["reuse", "commercial", "modify"], "in": "query", "name": "license", "type": "string", "x-example": "commercial"}, {"description": "Media language id from boardgamegeek_taxonomy media_video_languages/media_file_languages; video and file only", "in": "query", "name": "languageid", "type": "string", "x-example": "2184"}], "path": "/boardgamegeek/media/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"enum": ["image", "video", "file"], "in": "query", "name": "type", "type": "string"}, {"in": "query", "name": "showcount", "type": "integer"}, {"in": "query", "name": "pageid", "type": "integer"}, {"enum": ["hot", "recent"], "in": "query", "name": "sort", "type": "string"}, {"enum": ["alltime", "today", "twodays", "last7", "last30", "year"], "in": "query", "name": "interval", "type": "string"}, {"enum": ["all", "game", "person", "creative", "review", "session", "instructional", "interview", "unboxing", "humor", "other"], "in": "query", "name": "gallery", "type": "string"}, {"enum": ["BoxFront", "BoxBack", "Components", "Customized", "Play", "Miscellaneous", "uncat"], "in": "query", "name": "tag", "type": "string"}, {"enum": ["reuse", "commercial", "modify"], "in": "query", "name": "license", "type": "string"}, {"in": "query", "name": "languageid", "type": "string"}], "security": ["ApiKeyAuth"]}, "boardgamegeek-recommendations": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-recommendations", "method": "GET", "params": [{"description": "BoardGameGeek game id, positive integer; Catan is 13", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "13"}, {"description": "Maximum number of recommendations, 1-50", "in": "query", "name": "showcount", "type": "integer", "x-example": 25}], "path": "/boardgamegeek/recommendations/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "showcount", "type": "integer"}], "security": ["ApiKeyAuth"]}, "boardgamegeek-reviews": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-reviews", "method": "GET", "params": [{"description": "Object type", "enum": ["thing", "family", "person", "company", "property", "version"], "in": "path", "name": "type", "required": true, "type": "string"}, {"description": "Object identifier, positive integer; Catan is 13", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "13"}], "path": "/boardgamegeek/reviews/{type}/{id}", "pathParams": ["type", "id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "boardgamegeek-taxonomy": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-taxonomy", "method": "GET", "params": [], "path": "/boardgamegeek/taxonomy", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "boardgamegeek-thread": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-thread", "method": "GET", "params": [{"description": "BoardGameGeek thread id, positive integer", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "3782789"}, {"description": "Article page number, 1-1000; the source pages articles 25 at a time", "in": "query", "name": "pageid", "type": "integer", "x-example": 1}], "path": "/boardgamegeek/thread/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "pageid", "type": "integer"}], "security": ["ApiKeyAuth"]}, "boardgamegeek-threads": {"bodyParam": null, "bodyRequired": false, "id": "boardgamegeek-threads", "method": "GET", "params": [{"description": "Object type: thing, family, person, company, property or version. Defaults to thing.", "enum": ["thing", "family", "person", "company", "property", "version"], "in": "query", "name": "objecttype", "type": "string", "x-example": "thing"}, {"description": "Object identifier, positive integer; Catan is 13", "in": "query", "name": "objectid", "required": true, "type": "integer", "x-example": 13}, {"description": "Forum id from this route's forums list; unknown ids are ignored upstream, so use a listed id", "in": "query", "name": "forumid", "type": "integer", "x-example": 65}, {"description": "Thread sort: hot, recent or active. Defaults to recent.", "enum": ["hot", "recent", "active"], "in": "query", "name": "sort", "type": "string", "x-example": "recent"}, {"description": "Page size, 1-100; the source caps it at 100", "in": "query", "name": "showcount", "type": "integer", "x-example": 25}, {"description": "Page number, 1-1000", "in": "query", "name": "pageid", "type": "integer", "x-example": 1}], "path": "/boardgamegeek/threads", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["thing", "family", "person", "company", "property", "version"], "in": "query", "name": "objecttype", "type": "string"}, {"in": "query", "name": "objectid", "required": true, "type": "integer"}, {"in": "query", "name": "forumid", "type": "integer"}, {"enum": ["hot", "recent", "active"], "in": "query", "name": "sort", "type": "string"}, {"in": "query", "name": "showcount", "type": "integer"}, {"in": "query", "name": "pageid", "type": "integer"}], "security": ["ApiKeyAuth"]}}
|
|
23
|
+
JSON
|
|
24
|
+
OPERATION_IDS = JSON.parse(<<~'JSON').freeze
|
|
25
|
+
["boardgamegeek-blog", "boardgamegeek-blogpost", "boardgamegeek-blogposts", "boardgamegeek-blogs", "boardgamegeek-cardsets", "boardgamegeek-entity", "boardgamegeek-game", "boardgamegeek-geeklist", "boardgamegeek-geeklist-items", "boardgamegeek-geeklists", "boardgamegeek-hotness", "boardgamegeek-links", "boardgamegeek-media", "boardgamegeek-recommendations", "boardgamegeek-reviews", "boardgamegeek-taxonomy", "boardgamegeek-thread", "boardgamegeek-threads"]
|
|
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-boardgamegeek-ruby/0.2.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('blog') do |**params|
|
|
118
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
119
|
+
request('boardgamegeek-blog', params, response_type: response_type)
|
|
120
|
+
end
|
|
121
|
+
define_method('blogpost') do |**params|
|
|
122
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
123
|
+
request('boardgamegeek-blogpost', params, response_type: response_type)
|
|
124
|
+
end
|
|
125
|
+
define_method('blogposts') do |**params|
|
|
126
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
127
|
+
request('boardgamegeek-blogposts', params, response_type: response_type)
|
|
128
|
+
end
|
|
129
|
+
define_method('blogs') do |**params|
|
|
130
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
131
|
+
request('boardgamegeek-blogs', params, response_type: response_type)
|
|
132
|
+
end
|
|
133
|
+
define_method('cardsets') do |**params|
|
|
134
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
135
|
+
request('boardgamegeek-cardsets', params, response_type: response_type)
|
|
136
|
+
end
|
|
137
|
+
define_method('entity') do |**params|
|
|
138
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
139
|
+
request('boardgamegeek-entity', params, response_type: response_type)
|
|
140
|
+
end
|
|
141
|
+
define_method('game') do |**params|
|
|
142
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
143
|
+
request('boardgamegeek-game', params, response_type: response_type)
|
|
144
|
+
end
|
|
145
|
+
define_method('geeklist') do |**params|
|
|
146
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
147
|
+
request('boardgamegeek-geeklist', params, response_type: response_type)
|
|
148
|
+
end
|
|
149
|
+
define_method('geeklist_items') do |**params|
|
|
150
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
151
|
+
request('boardgamegeek-geeklist-items', params, response_type: response_type)
|
|
152
|
+
end
|
|
153
|
+
define_method('geeklists') do |**params|
|
|
154
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
155
|
+
request('boardgamegeek-geeklists', params, response_type: response_type)
|
|
156
|
+
end
|
|
157
|
+
define_method('hotness') do |**params|
|
|
158
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
159
|
+
request('boardgamegeek-hotness', params, response_type: response_type)
|
|
160
|
+
end
|
|
161
|
+
define_method('links') do |**params|
|
|
162
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
163
|
+
request('boardgamegeek-links', params, response_type: response_type)
|
|
164
|
+
end
|
|
165
|
+
define_method('media') do |**params|
|
|
166
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
167
|
+
request('boardgamegeek-media', params, response_type: response_type)
|
|
168
|
+
end
|
|
169
|
+
define_method('recommendations') do |**params|
|
|
170
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
171
|
+
request('boardgamegeek-recommendations', params, response_type: response_type)
|
|
172
|
+
end
|
|
173
|
+
define_method('reviews') do |**params|
|
|
174
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
175
|
+
request('boardgamegeek-reviews', params, response_type: response_type)
|
|
176
|
+
end
|
|
177
|
+
define_method('taxonomy') do |**params|
|
|
178
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
179
|
+
request('boardgamegeek-taxonomy', params, response_type: response_type)
|
|
180
|
+
end
|
|
181
|
+
define_method('thread') do |**params|
|
|
182
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
183
|
+
request('boardgamegeek-thread', params, response_type: response_type)
|
|
184
|
+
end
|
|
185
|
+
define_method('threads') do |**params|
|
|
186
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
187
|
+
request('boardgamegeek-threads', params, response_type: response_type)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
private
|
|
191
|
+
|
|
192
|
+
# POST operations take their JSON body under the body parameter name or "body".
|
|
193
|
+
def request_body(operation, params)
|
|
194
|
+
name = operation["bodyParam"]
|
|
195
|
+
return nil if name.nil?
|
|
196
|
+
value = params.key?(name) ? params[name] : params["body"]
|
|
197
|
+
if value.nil?
|
|
198
|
+
raise Errors::ClientError.new("missing request body: #{name}", operation_id: operation["id"]) if operation["bodyRequired"]
|
|
199
|
+
return nil
|
|
200
|
+
end
|
|
201
|
+
value.is_a?(String) ? value : JSON.generate(value)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def build_url(operation, params)
|
|
205
|
+
known = operation["params"].map { |param| param["name"] }
|
|
206
|
+
known << "body" if operation["bodyParam"]
|
|
207
|
+
unknown = params.keys - known
|
|
208
|
+
raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
|
|
209
|
+
path = operation["path"].dup
|
|
210
|
+
operation["params"].select { |param| param["in"] == "path" }.each do |param|
|
|
211
|
+
value = params[param["name"]]
|
|
212
|
+
raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
|
|
213
|
+
path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
|
|
214
|
+
end
|
|
215
|
+
pairs = []
|
|
216
|
+
operation["queryParams"].each do |param|
|
|
217
|
+
name = param["name"]
|
|
218
|
+
value = params.key?(name) ? params[name] : param["default"]
|
|
219
|
+
if value.nil?
|
|
220
|
+
raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
|
|
221
|
+
next
|
|
222
|
+
end
|
|
223
|
+
enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
|
|
224
|
+
if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
|
|
225
|
+
raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
|
|
226
|
+
end
|
|
227
|
+
if value.is_a?(Array)
|
|
228
|
+
format = param["collectionFormat"] || "csv"
|
|
229
|
+
if format == "multi"
|
|
230
|
+
value.each { |item| pairs << [name, scalar(item)] }
|
|
231
|
+
else
|
|
232
|
+
separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
|
|
233
|
+
pairs << [name, value.map { |item| scalar(item) }.join(separator)]
|
|
234
|
+
end
|
|
235
|
+
else
|
|
236
|
+
pairs << [name, scalar(value)]
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
|
|
240
|
+
@base_url + path + (query.empty? ? "" : "?" + query)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def scalar(value)
|
|
244
|
+
value == true ? "true" : (value == false ? "false" : value.to_s)
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def percent_encode(value)
|
|
248
|
+
URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def parse_response(body, content_type, operation, params, response_type)
|
|
252
|
+
type = response_type.to_s
|
|
253
|
+
raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
|
|
254
|
+
format = operation["params"].find { |param| param["name"] == "format" }
|
|
255
|
+
text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
|
|
256
|
+
raw_format = params["format"] && text_formats.include?(params["format"].to_s)
|
|
257
|
+
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)
|
|
258
|
+
is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
|
|
259
|
+
return body if type == "text" || raw_format || (type == "auto" && !is_json)
|
|
260
|
+
JSON.parse(body)
|
|
261
|
+
rescue JSON::ParserError => error
|
|
262
|
+
raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
public
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crawlora-boardgamegeek
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Crawlora
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-11-29 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Ruby client for Crawlora's hosted BoardGameGeek API. Covers public game,
|
|
14
|
+
geeklist, review, thread, and taxonomy data across 18 endpoints.
|
|
15
|
+
email:
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- CHANGELOG.md
|
|
21
|
+
- LICENSE
|
|
22
|
+
- README.md
|
|
23
|
+
- lib/crawlora/boardgamegeek.rb
|
|
24
|
+
- lib/crawlora/boardgamegeek/client.rb
|
|
25
|
+
- lib/crawlora/boardgamegeek/version.rb
|
|
26
|
+
homepage: https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=boardgamegeek-ruby-homepage
|
|
27
|
+
licenses:
|
|
28
|
+
- MIT
|
|
29
|
+
metadata:
|
|
30
|
+
source_code_uri: https://github.com/Crawlora-org/crawlora-boardgamegeek
|
|
31
|
+
documentation_uri: https://github.com/Crawlora-org/crawlora-boardgamegeek/blob/main/ruby/README.md
|
|
32
|
+
rubygems_mfa_required: 'true'
|
|
33
|
+
post_install_message:
|
|
34
|
+
rdoc_options: []
|
|
35
|
+
require_paths:
|
|
36
|
+
- lib
|
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '2.6'
|
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
requirements: []
|
|
48
|
+
rubygems_version: 3.4.19
|
|
49
|
+
signing_key:
|
|
50
|
+
specification_version: 4
|
|
51
|
+
summary: BoardGameGeek API client for Crawlora (18 endpoints)
|
|
52
|
+
test_files: []
|