comicinfo-metron 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 +7 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +13 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.md +21 -0
- data/README.md +55 -0
- data/Rakefile +10 -0
- data/lib/comicinfo/metron/client.rb +44 -0
- data/lib/comicinfo/metron/cover_date.rb +26 -0
- data/lib/comicinfo/metron/credits.rb +28 -0
- data/lib/comicinfo/metron/errors.rb +26 -0
- data/lib/comicinfo/metron/found_issue.rb +89 -0
- data/lib/comicinfo/metron/version.rb +5 -0
- data/lib/comicinfo/metron.rb +85 -0
- data/sig/comicinfo/metron.rbs +6 -0
- metadata +89 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 15da82a74413fd3cd1ebb86a0f8d23966534dad6ab6145111f46dd92e1722c99
|
|
4
|
+
data.tar.gz: 19a522e272f9d595da908026738d8c914b6e92cc8047491232b8720d087a9887
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 86389a04f058dc17da426a06e1377b684acb4610924bcecf9b4f19dc4314c940cccf962759e10b7e617329411cab3a3fef1fcd2b0425cab40a04b00b91adcb8c
|
|
7
|
+
data.tar.gz: '084ac02c09011fb04ee131759f866b5d5e2da2897c6eb2d72d230deda24c69c5185cb306cba86c386546ee68e522d3a9296499d13c88a8e5ac1918d210ecedf9'
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4.0.9
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- `ComicInfo::Metron`, a metadata source for [Metron](https://metron.cloud). `matches(issue)` finds the issue with the comic's number in every series whose name contains the comic's series, narrowed to its cover year when the comic has a year, ranked by series name then cover year. `issue(match)` reads the picked issue into a `ComicInfo::Issue`: series, volume, title, cover year and month, publisher, imprint, summary, genres, credits by role, characters, teams, story arcs, and its Metron page
|
|
12
|
+
- `ComicInfo::Metron::HTTPError` and `ComicInfo::Metron::InvalidIssueIDError`: an HTTP error status, such as 401 for a wrong token, or a match ID that isn't a Metron issue ID
|
|
13
|
+
- A live API spec, run against the real Metron API when `METRON_TOKEN` is set and skipped when it isn't
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
veganstraightedge@gmail.com.
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shane Becker
|
|
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,55 @@
|
|
|
1
|
+
# comicinfo-metron
|
|
2
|
+
|
|
3
|
+
Looks up comic details in [Metron](https://metron.cloud), for the [comicinfo](https://github.com/veganstraightedge/comicinfo) gem.
|
|
4
|
+
|
|
5
|
+
`ComicInfo::Metron` is a metadata source: it searches Metron for an issue, and returns what Metron knows about the one picked as a `ComicInfo::Issue`. See [Looking Up Details in Online Databases](https://github.com/veganstraightedge/comicinfo/blob/main/doc/metadata-sources.md).
|
|
6
|
+
|
|
7
|
+
It's the Ruby counterpart of [ComicInfoMetron.swift](https://github.com/veganstraightedge/ComicInfoMetron.swift), and a sibling of [comicinfo-comic_vine](https://github.com/veganstraightedge/comicinfo-comic_vine).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'comicinfo-metron'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
require 'comicinfo/metron'
|
|
19
|
+
|
|
20
|
+
metron = ComicInfo::Metron.new token: 'your API token', user_agent: 'MyApp/1.0'
|
|
21
|
+
|
|
22
|
+
issue = ComicInfo.load 'path/to/ComicInfo.xml'
|
|
23
|
+
matches = metron.matches issue # best first
|
|
24
|
+
found = metron.issue matches[0] # after a person picks one
|
|
25
|
+
updated = issue.with_blanks_filled_from found
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- `matches` needs a Series and a Number; `missing_details` says so when either is blank. A Year is optional: when there is one, only issues with a cover dated that year are found.
|
|
29
|
+
- It finds the issue with that number in every series whose name contains the issue's series, and ranks the matches by series name, then cover year.
|
|
30
|
+
- A match has no `site_url`: Metron's issue pages are addressed by a slug its search results don't include.
|
|
31
|
+
- `issue` reads the issue: series, volume, title (or else its first story's title), cover year and month, publisher, imprint, summary, genres, credits by role, characters, teams, story arcs, and the issue's Metron page as its web link.
|
|
32
|
+
- A request Metron refuses raises `ComicInfo::Metron::HTTPError` (with its `status`, such as 401 for a wrong token), and a match whose ID isn't a Metron issue ID raises `ComicInfo::Metron::InvalidIssueIDError` (with its `id`). Both are `ComicInfo::Metron::Error`s.
|
|
33
|
+
|
|
34
|
+
## Credit
|
|
35
|
+
|
|
36
|
+
Comic details from [Metron](https://metron.cloud). Whatever shows Metron's data must credit and link to Metron (`metron.name`, `metron.home_url`).
|
|
37
|
+
|
|
38
|
+
## Development
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
bin/setup # bundle install
|
|
42
|
+
bundle exec rake # specs and RuboCop
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The specs answer every request from a local server with a Metron response from `spec/fixtures/`, so they need no token or network. The fixtures follow the schemas of [Mokkari](https://github.com/Metron-Project/mokkari), Metron's Python client; they weren't recorded from the live API.
|
|
46
|
+
|
|
47
|
+
`spec/comic_info/metron_live_spec.rb` also calls the real API, when `METRON_TOKEN` holds an API token. Without it, it's skipped:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
METRON_TOKEN=your-token bundle exec rake
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
[MIT](LICENSE.md)
|
data/Rakefile
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'uri'
|
|
4
|
+
require_relative 'errors'
|
|
5
|
+
|
|
6
|
+
module ComicInfo
|
|
7
|
+
class Metron
|
|
8
|
+
# Calls the Metron API with one account's API token.
|
|
9
|
+
#
|
|
10
|
+
# Results are Metron's JSON, parsed with symbol keys. They follow Mokkari's schemas (Metron's
|
|
11
|
+
# own Python client).
|
|
12
|
+
class Client
|
|
13
|
+
def initialize base_url:, token:, user_agent:
|
|
14
|
+
@base_url = base_url
|
|
15
|
+
@token = token
|
|
16
|
+
@user_agent = user_agent
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# The issues numbered number in series whose names contain series, narrowed to a cover year when there is one
|
|
20
|
+
def find_issues number:, series:, cover_year: nil
|
|
21
|
+
parameters = { cover_year:, number:, series_name: series }.compact
|
|
22
|
+
|
|
23
|
+
get('issue/', parameters)[:results]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# One issue, credits and all
|
|
27
|
+
def issue(id) = get "issue/#{id}/"
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
# Calls one API resource and returns its parsed response
|
|
32
|
+
def get path, parameters = {}
|
|
33
|
+
uri = URI.join @base_url, path
|
|
34
|
+
uri.query = URI.encode_www_form parameters.sort unless parameters.empty?
|
|
35
|
+
|
|
36
|
+
headers = { 'Authorization' => "Bearer #{@token}", 'User-Agent' => @user_agent }
|
|
37
|
+
response = Net::HTTP.get_response uri, headers
|
|
38
|
+
raise HTTPError, response.code.to_i unless response.is_a? Net::HTTPOK
|
|
39
|
+
|
|
40
|
+
JSON.parse response.body, symbolize_names: true
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module ComicInfo
|
|
2
|
+
class Metron
|
|
3
|
+
# A cover date such as "2012-03-01", as a year and month.
|
|
4
|
+
#
|
|
5
|
+
# The day is left out: a cover date carries the 1st when only the month is known.
|
|
6
|
+
class CoverDate
|
|
7
|
+
def initialize text
|
|
8
|
+
@parts = text.to_s.split '-'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# The year, or nil when there isn't one
|
|
12
|
+
def year
|
|
13
|
+
year = Integer @parts[0], 10, exception: false if @parts.length >= 2
|
|
14
|
+
|
|
15
|
+
year if year&.between? 1000, 9999
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# The month, 1 to 12, or nil when there isn't one
|
|
19
|
+
def month
|
|
20
|
+
month = Integer @parts[1], 10, exception: false if @parts.length >= 2
|
|
21
|
+
|
|
22
|
+
month if month&.between? 1, 12
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module ComicInfo
|
|
2
|
+
class Metron
|
|
3
|
+
# The creators credited on an issue, and their roles.
|
|
4
|
+
#
|
|
5
|
+
# Metron gives each creator a list of roles, such as Artist and Cover.
|
|
6
|
+
class Credits
|
|
7
|
+
def initialize credits
|
|
8
|
+
@credits = credits
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Everyone credited with any of the roles (lowercase), each once, in credit order, joined with commas;
|
|
12
|
+
# nil when no one is
|
|
13
|
+
def names *roles
|
|
14
|
+
people = @credits.select { credited_with? it, roles }.map { it[:creator] }.uniq
|
|
15
|
+
|
|
16
|
+
people.join ', ' unless people.empty?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def credited_with? credit, roles
|
|
22
|
+
credit_roles = credit[:role].to_a.map { it[:name].to_s.downcase }
|
|
23
|
+
|
|
24
|
+
credit_roles.intersect? roles
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module ComicInfo
|
|
2
|
+
class Metron
|
|
3
|
+
# Why a Metron request failed
|
|
4
|
+
class Error < ComicInfo::Error; end
|
|
5
|
+
|
|
6
|
+
# Metron answered with an HTTP error status, such as 401 for a wrong token, or 429
|
|
7
|
+
class HTTPError < Error
|
|
8
|
+
attr_reader :status
|
|
9
|
+
|
|
10
|
+
def initialize status
|
|
11
|
+
@status = status
|
|
12
|
+
super("Metron answered with HTTP status #{status}.")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# A match's ID isn't a Metron issue ID, so it can't have come from Metron
|
|
17
|
+
class InvalidIssueIDError < Error
|
|
18
|
+
attr_reader :id
|
|
19
|
+
|
|
20
|
+
def initialize id
|
|
21
|
+
@id = id
|
|
22
|
+
super("“#{id}” isn't a Metron issue ID.")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require 'nokogiri'
|
|
2
|
+
require_relative 'cover_date'
|
|
3
|
+
require_relative 'credits'
|
|
4
|
+
|
|
5
|
+
module ComicInfo
|
|
6
|
+
class Metron
|
|
7
|
+
# A Metron issue as a ComicInfo::Issue.
|
|
8
|
+
#
|
|
9
|
+
# The issue is built from ComicInfo XML with only the fields Metron knows, so
|
|
10
|
+
# ComicInfo::Issue#with_blanks_filled_from keeps what a comic already has.
|
|
11
|
+
class FoundIssue
|
|
12
|
+
# - issue: Metron's issue detail
|
|
13
|
+
def initialize issue:
|
|
14
|
+
@issue = issue
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def to_issue
|
|
18
|
+
ComicInfo.load(xml)
|
|
19
|
+
.with_characters(names(@issue[:characters]))
|
|
20
|
+
.with_genres(names(@issue.dig(:series, :genres)))
|
|
21
|
+
.with_teams(names(@issue[:teams]))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# ComicInfo XML with every field Metron knows, by element name
|
|
27
|
+
def xml
|
|
28
|
+
document = Nokogiri::XML::Document.new
|
|
29
|
+
root = document.create_element 'ComicInfo'
|
|
30
|
+
|
|
31
|
+
fields.each { |element, value| root.add_child document.create_element(element, value.to_s) }
|
|
32
|
+
document.root = root
|
|
33
|
+
|
|
34
|
+
document.to_xml
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def fields
|
|
38
|
+
credits = Credits.new @issue[:credits].to_a
|
|
39
|
+
cover_date = CoverDate.new @issue[:cover_date]
|
|
40
|
+
|
|
41
|
+
{
|
|
42
|
+
'Colorist' => credits.names('colorist'),
|
|
43
|
+
'CoverArtist' => credits.names('cover'),
|
|
44
|
+
'Editor' => credits.names('editor'),
|
|
45
|
+
'Imprint' => present(@issue.dig(:imprint, :name)),
|
|
46
|
+
'Inker' => credits.names('inker', 'artist'),
|
|
47
|
+
'Letterer' => credits.names('letterer'),
|
|
48
|
+
'Month' => cover_date.month,
|
|
49
|
+
'Number' => present(@issue[:number]),
|
|
50
|
+
'Penciller' => credits.names('penciller', 'artist'),
|
|
51
|
+
'Publisher' => present(@issue.dig(:publisher, :name)),
|
|
52
|
+
'Series' => present(@issue.dig(:series, :name)),
|
|
53
|
+
'StoryArc' => present(names(@issue[:arcs]).join(', ')),
|
|
54
|
+
'Summary' => present(@issue[:desc]),
|
|
55
|
+
'Title' => title,
|
|
56
|
+
'Translator' => credits.names('translator'),
|
|
57
|
+
'Volume' => volume,
|
|
58
|
+
'Web' => present(@issue[:resource_url]),
|
|
59
|
+
'Writer' => credits.names('writer', 'script', 'story', 'plot'),
|
|
60
|
+
'Year' => cover_date.year
|
|
61
|
+
}.compact
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# The collection's title, or else its first story's
|
|
65
|
+
def title
|
|
66
|
+
story_titles = @issue[:name].to_a.filter_map { present it }
|
|
67
|
+
|
|
68
|
+
present(@issue[:title]) || story_titles.first
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# The series' volume, or nil when Metron doesn't know it
|
|
72
|
+
def volume
|
|
73
|
+
volume = @issue.dig(:series, :volume)
|
|
74
|
+
|
|
75
|
+
volume if volume.to_i.positive?
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# The names of the characters, teams, genres, or story arcs Metron lists
|
|
79
|
+
def names(items) = items.to_a.filter_map { it[:name] }
|
|
80
|
+
|
|
81
|
+
# The text, trimmed, or nil when it's blank
|
|
82
|
+
def present text
|
|
83
|
+
trimmed = text.to_s.strip
|
|
84
|
+
|
|
85
|
+
trimmed unless trimmed.empty?
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'comicinfo'
|
|
2
|
+
require_relative 'metron/client'
|
|
3
|
+
require_relative 'metron/errors'
|
|
4
|
+
require_relative 'metron/found_issue'
|
|
5
|
+
require_relative 'metron/version'
|
|
6
|
+
|
|
7
|
+
module ComicInfo
|
|
8
|
+
# Looks up comic details in Metron, https://metron.cloud
|
|
9
|
+
#
|
|
10
|
+
# metron = ComicInfo::Metron.new token: token, user_agent: 'MyApp/1.0'
|
|
11
|
+
# matches = metron.matches issue
|
|
12
|
+
# found = metron.issue matches.first
|
|
13
|
+
# updated = issue.with_blanks_filled_from found
|
|
14
|
+
#
|
|
15
|
+
# Whatever shows Metron's data credits and links back to it. Requests are made with a Metron
|
|
16
|
+
# account's API token.
|
|
17
|
+
class Metron
|
|
18
|
+
BASE_URL = 'https://metron.cloud/api/'.freeze
|
|
19
|
+
|
|
20
|
+
# - token: the account's Metron API token
|
|
21
|
+
# - user_agent: names the app, such as "MyApp/1.0"
|
|
22
|
+
# - base_url: where the API is, for testing against a server of your own
|
|
23
|
+
def initialize token:, user_agent:, base_url: BASE_URL
|
|
24
|
+
@client = Client.new(base_url:, token:, user_agent:)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def name = 'Metron'
|
|
28
|
+
def home_url = 'https://metron.cloud/'
|
|
29
|
+
|
|
30
|
+
# What the issue still needs before it can be searched for, or nil
|
|
31
|
+
def missing_details issue
|
|
32
|
+
return if present(issue.series) && present(issue.number)
|
|
33
|
+
|
|
34
|
+
'Metron needs a Series and a Number to search for.'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The issues with the issue's number in every series whose name contains its series, best first.
|
|
38
|
+
#
|
|
39
|
+
# When the issue has a year, only issues with a cover dated that year are asked for.
|
|
40
|
+
def matches issue
|
|
41
|
+
cover_year = issue.year if issue.year.to_i.positive?
|
|
42
|
+
found = client.find_issues cover_year:, number: present(issue.number), series: present(issue.series)
|
|
43
|
+
matches = found.map { match_for it }
|
|
44
|
+
|
|
45
|
+
issue.rank matches
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Everything Metron knows about the match's issue, as a ComicInfo::Issue
|
|
49
|
+
def issue match
|
|
50
|
+
id = Integer match.id, 10, exception: false
|
|
51
|
+
raise InvalidIssueIDError, match.id unless id
|
|
52
|
+
|
|
53
|
+
found = client.issue id
|
|
54
|
+
|
|
55
|
+
FoundIssue.new(issue: found).to_issue
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
attr_reader :client
|
|
61
|
+
|
|
62
|
+
# One issue from the issue list as a match.
|
|
63
|
+
#
|
|
64
|
+
# Metron's issue pages are addressed by a slug, which the list doesn't have, so it has no site URL.
|
|
65
|
+
def match_for found
|
|
66
|
+
series = found.dig(:series, :name) || ''
|
|
67
|
+
heading = present(found[:issue]) || "#{series} ##{found[:number]}"
|
|
68
|
+
cover_date = "Cover date #{present(found[:cover_date]) || 'unknown'}"
|
|
69
|
+
|
|
70
|
+
Match.new cover_date: found[:cover_date],
|
|
71
|
+
details: cover_date,
|
|
72
|
+
heading:,
|
|
73
|
+
id: found[:id].to_s,
|
|
74
|
+
number: found[:number],
|
|
75
|
+
series:
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# The text, trimmed, or nil when it's blank
|
|
79
|
+
def present text
|
|
80
|
+
trimmed = text.to_s.strip
|
|
81
|
+
|
|
82
|
+
trimmed unless trimmed.empty?
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: comicinfo-metron
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Shane Becker
|
|
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: comicinfo
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.3'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.3'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: nokogiri
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 1.19.7
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 1.19.7
|
|
40
|
+
description: |
|
|
41
|
+
A metadata source for the comicinfo gem: searches Metron for an issue,
|
|
42
|
+
and returns what Metron knows about the one picked as a ComicInfo::Issue
|
|
43
|
+
email:
|
|
44
|
+
- veganstraightedge@gmail.com
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- ".ruby-version"
|
|
50
|
+
- CHANGELOG.md
|
|
51
|
+
- CODE_OF_CONDUCT.md
|
|
52
|
+
- LICENSE.md
|
|
53
|
+
- README.md
|
|
54
|
+
- Rakefile
|
|
55
|
+
- lib/comicinfo/metron.rb
|
|
56
|
+
- lib/comicinfo/metron/client.rb
|
|
57
|
+
- lib/comicinfo/metron/cover_date.rb
|
|
58
|
+
- lib/comicinfo/metron/credits.rb
|
|
59
|
+
- lib/comicinfo/metron/errors.rb
|
|
60
|
+
- lib/comicinfo/metron/found_issue.rb
|
|
61
|
+
- lib/comicinfo/metron/version.rb
|
|
62
|
+
- sig/comicinfo/metron.rbs
|
|
63
|
+
homepage: https://github.com/veganstraightedge/comicinfo-metron
|
|
64
|
+
licenses:
|
|
65
|
+
- MIT
|
|
66
|
+
metadata:
|
|
67
|
+
allowed_push_host: https://rubygems.org
|
|
68
|
+
homepage_uri: https://github.com/veganstraightedge/comicinfo-metron
|
|
69
|
+
source_code_uri: https://github.com/veganstraightedge/comicinfo-metron
|
|
70
|
+
changelog_uri: https://github.com/veganstraightedge/comicinfo-metron/blob/main/CHANGELOG.md
|
|
71
|
+
rubygems_mfa_required: 'true'
|
|
72
|
+
rdoc_options: []
|
|
73
|
+
require_paths:
|
|
74
|
+
- lib
|
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: 4.0.9
|
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
requirements: []
|
|
86
|
+
rubygems_version: 4.0.20
|
|
87
|
+
specification_version: 4
|
|
88
|
+
summary: Looks up comic details in Metron, for the comicinfo gem
|
|
89
|
+
test_files: []
|