mangadex 5.8.0 → 5.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5a9dfc94c6c5866bc5c5cc6655c2a3a3f6553dd5fc3adeb1cbd0ca854b3b194
4
- data.tar.gz: 46b48717c4943ab88d2e6f12d64cb6dc9bab74a41c407c88e206d63f4e99d83b
3
+ metadata.gz: 18087cc00534cd6237918795bf9a788ce418f09a9e6853507979a6152b3ed573
4
+ data.tar.gz: 9ba7ab45bd94fa41e13a4a7dc263bcf090ccc6b529a8bc7107ce8842cb46e4a4
5
5
  SHA512:
6
- metadata.gz: adf076fba8b23de5486b741f9d4e3bf27ad8636059d16c991cd5538f9daea0211f223131349ab7e5b87d81f861ea04ef5580eff022b6c13e480b37886cd6fccd
7
- data.tar.gz: 1632d1a344b5afd3bad0db012d835c736df4ab4eef830e387015b9187c3c4cd0b53bbbcb0e679f5725bb01add4f69ba7b04692cf1dc76abf689424c17669e0c6
6
+ metadata.gz: fa61b0946bfb0e13205500cabfb7083bd0585cf9f8eb5bf522c5bd96b786f58f57aca9d6660210e153beb735a979d208baa5c3f6210af47e146664c31adf493a
7
+ data.tar.gz: 8fffed4ae99b25713edb3b53031051663d86205d5b0794dd8f51282aca54f8469d34b16f27ad0b21455bfd8ccb3a81d1d0de15376dfdc3109897b010ad69e8b5
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mangadex (5.8.0)
5
- psych (~> 4.0.1)
4
+ mangadex (5.10.0)
5
+ psych (>= 4.0.1, < 5.2.0)
6
6
  rest-client (~> 2.1)
7
7
  sorbet-runtime
8
8
 
@@ -19,12 +19,12 @@ GEM
19
19
  method_source (1.0.0)
20
20
  mime-types (3.4.1)
21
21
  mime-types-data (~> 3.2015)
22
- mime-types-data (3.2022.0105)
22
+ mime-types-data (3.2023.0218.1)
23
23
  netrc (0.11.0)
24
- pry (0.14.1)
24
+ pry (0.14.2)
25
25
  coderay (~> 1.1)
26
26
  method_source (~> 1.0)
27
- psych (4.0.6)
27
+ psych (5.1.0)
28
28
  stringio
29
29
  rake (13.0.6)
30
30
  rest-client (2.1.0)
@@ -45,11 +45,11 @@ GEM
45
45
  diff-lcs (>= 1.2.0, < 2.0)
46
46
  rspec-support (~> 3.12.0)
47
47
  rspec-support (3.12.0)
48
- sorbet (0.5.10539)
49
- sorbet-static (= 0.5.10539)
50
- sorbet-runtime (0.5.10597)
51
- sorbet-static (0.5.10539-x86_64-linux)
52
- stringio (3.0.4)
48
+ sorbet (0.5.10864)
49
+ sorbet-static (= 0.5.10864)
50
+ sorbet-runtime (0.5.10863)
51
+ sorbet-static (0.5.10864-x86_64-linux)
52
+ stringio (3.0.7)
53
53
  unf (0.1.4)
54
54
  unf_ext
55
55
  unf_ext (0.0.8.2)
data/docker-compose.yml CHANGED
@@ -2,7 +2,7 @@ version: "3"
2
2
  services:
3
3
  gem:
4
4
  build: .
5
- command: bash
5
+ command: bin/console
6
6
  stdin_open: true
7
7
  tty: true
8
8
  volumes:
@@ -36,6 +36,8 @@ module Mangadex
36
36
  coerce_entity(data)
37
37
  elsif data['response'] == 'collection'
38
38
  coerce_collection(data)
39
+ elsif data.keys.include?('statistics')
40
+ coerce_statistics(data)
39
41
  else
40
42
  data
41
43
  end
@@ -109,7 +111,10 @@ module Mangadex
109
111
 
110
112
  # Derive the class name from the type. "Convention over configuration"
111
113
  class_from_data = "Mangadex::#{object_type.split('_').collect(&:capitalize).join}"
112
- return unless Object.const_defined?(class_from_data)
114
+ unless Object.const_defined?(class_from_data)
115
+ warn("Expected class #{class_from_data} to be defined")
116
+ return
117
+ end
113
118
 
114
119
  klass = Object.const_get(class_from_data)
115
120
  new(
@@ -142,6 +147,13 @@ module Mangadex
142
147
  raw_data: data,
143
148
  )
144
149
  end
150
+
151
+ def self.coerce_statistics(data)
152
+ new(
153
+ result: data['result'],
154
+ data: Mangadex::Statistic.from_data(data['statistics']),
155
+ )
156
+ end
145
157
  end
146
158
  end
147
159
  end
@@ -4,6 +4,7 @@ require_relative "definitions/accepts"
4
4
 
5
5
  require_relative "definitions/base"
6
6
  require_relative "definitions/content_rating"
7
+ require_relative "definitions/year"
7
8
 
8
9
  module Mangadex
9
10
  module Internal
@@ -0,0 +1,28 @@
1
+ # typed: false
2
+
3
+ module Mangadex
4
+ module Internal
5
+ module Definitions
6
+ class Year < Base
7
+ def initialize(value)
8
+ super(
9
+ value,
10
+ key: :year,
11
+ accepts: Accepts.new(
12
+ array: ["none"],
13
+ class: Integer,
14
+ condition: :or,
15
+ ),
16
+ required: false,
17
+ )
18
+ end
19
+
20
+ def validate_accepts
21
+ @accepts.validate!(converted_value)
22
+ rescue ArgumentError => error
23
+ add_error(error.message)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -29,11 +29,13 @@ module Mangadex
29
29
  Mangadex::Utils.underscore(self.name.split('::').last)
30
30
  end
31
31
 
32
- def from_data(data, related_type: nil, source_obj: nil)
32
+ def from_data(data, related_type: nil, source_obj: nil, direct: false)
33
33
  base_class_name = self.name.gsub('::', '_')
34
34
  klass_name = self.name
35
35
  target_attributes_class_name = "#{base_class_name}_Attributes"
36
36
 
37
+ return if data.nil? || data.empty?
38
+
37
39
  data = data.transform_keys(&:to_s)
38
40
 
39
41
  klass = if const_defined?(target_attributes_class_name)
@@ -58,22 +60,38 @@ module Mangadex
58
60
  Relationship.from_data(relationship_data, MangadexObject.new(**data))
59
61
  end
60
62
 
61
- found_attributes = data['attributes'] || {}
62
- attributes = klass.new(**Hash(found_attributes.symbolize_keys))
63
+ if direct
64
+ symbolized_data = data.symbolize_keys
65
+ symbolized_data.transform_keys! do |key|
66
+ Mangadex::Utils.underscore(key)
67
+ end
68
+ keys = symbolized_data.keys
69
+ keys.each do |key|
70
+ attr_accessor key
71
+ end
63
72
 
64
- initialize_hash = {
65
- id: data['id'],
66
- type: data['type'] || self.type,
67
- attributes: attributes,
68
- related_type: related_type,
69
- }
73
+ instance = new
74
+ keys.each do |key|
75
+ instance.send("#{key}=", symbolized_data[key])
76
+ end
70
77
 
71
- relationships = [source_obj].compact unless relationships.present?
72
- initialize_hash.merge!({relationships: relationships}) if relationships.present?
78
+ instance
79
+ else
80
+ found_attributes = data['attributes'] || {}
81
+ attributes = klass.new(**Hash(found_attributes.symbolize_keys))
82
+
83
+ initialize_hash = {
84
+ id: data['id'],
85
+ type: data['type'] || self.type,
86
+ attributes: attributes,
87
+ related_type: related_type,
88
+ }
73
89
 
74
- # binding.pry
90
+ relationships = [source_obj].compact unless relationships.present?
91
+ initialize_hash.merge!({relationships: relationships}) if relationships.present?
75
92
 
76
- new(**initialize_hash)
93
+ new(**initialize_hash)
94
+ end
77
95
  end
78
96
  end
79
97
 
@@ -36,7 +36,7 @@ module Mangadex
36
36
  author_or_artist: { accepts: String },
37
37
  authors: { accepts: [String], converts: :to_a },
38
38
  artists: { accepts: [String], converts: :to_a },
39
- year: { accepts: Integer },
39
+ year: Mangadex::Internal::Definitions::Year,
40
40
  included_tags: { accepts: [String], converts: :to_a },
41
41
  included_tags_mode: { accepts: %w(OR AND) },
42
42
  excluded_tags: { accepts: [String], converts: :to_a },
@@ -224,5 +224,20 @@ module Mangadex
224
224
  chapter_args = args.merge({manga: id})
225
225
  Chapter.list(**chapter_args)
226
226
  end
227
+
228
+ sig { returns(T::Boolean) }
229
+ def has_comments?
230
+ !comments_info.nil? && comments_info.repliesCount > 0
231
+ end
232
+
233
+ def statistics
234
+ @statistics ||= Mangadex::Statistic.get(id).data
235
+ end
236
+ alias :stats :statistics
237
+
238
+ def comments_info
239
+ statistics.comments
240
+ end
241
+ alias :comments :comments_info
227
242
  end
228
243
  end
@@ -17,6 +17,7 @@ module Mangadex
17
17
  :focused_languages,
18
18
  :publish_delay,
19
19
  :inactive,
20
+ :ex_licensed,
20
21
  :manga_updates,
21
22
  :version,
22
23
  :created_at,
@@ -2,30 +2,77 @@
2
2
 
3
3
  module Mangadex
4
4
  class Statistic < MangadexObject
5
- has_attributes \
5
+ class Rating < MangadexObject
6
+ has_attributes \
7
+ :average,
8
+ :bayesian,
9
+ :distribution
10
+
11
+ def self.attributes_to_inspect
12
+ [:average, :bayesian]
13
+ end
14
+ end
15
+
16
+ class Comments < MangadexObject
17
+ has_attributes \
18
+ :thread_id,
19
+ :replies_count
20
+
21
+ def self.attributes_to_inspect
22
+ [:replies_count]
23
+ end
24
+ end
25
+
26
+ attr_accessor \
6
27
  :rating,
7
- :average,
8
- :bayesian,
9
- :distribution,
10
- :follows
28
+ :follows,
29
+ :comments
11
30
 
12
- sig { params(uuid: String).returns(T::Api::GenericResponse) }
13
- def self.get(uuid)
31
+ class << self
32
+ def from_data(data)
33
+ results = if data.is_a?(Array)
34
+ data.map do |item|
35
+ from_data(item)
36
+ end
37
+ else
38
+ data.keys.map do |manga_id|
39
+ statistics = data[manga_id]
40
+ new(
41
+ rating: Mangadex::Statistic::Rating.from_data(statistics['rating'], direct: true),
42
+ comments: Mangadex::Statistic::Comments.from_data(statistics['comments'], direct: true),
43
+ follows: statistics['follows'],
44
+ )
45
+ end
46
+ end
47
+
48
+ return results.first if results.length == 1
49
+ Mangadex::Api::Response::Collection.new(results)
50
+ end
51
+ end
52
+
53
+ sig { params(uuid: String, raw: T::Boolean).returns(T::Api::GenericResponse) }
54
+ def self.get(uuid, raw: false)
14
55
  Mangadex::Internal::Definition.must(uuid)
15
56
 
16
57
  Mangadex::Internal::Request.get(
17
58
  '/statistics/manga/%{uuid}' % {uuid: uuid},
59
+ raw: raw,
18
60
  )
19
61
  end
20
62
 
21
- sig { params(args: T::Api::Arguments).returns(T::Api::GenericResponse) }
22
- def self.list(**args)
63
+ sig { params(raw: T::Boolean, args: T::Api::Arguments).returns(T::Api::GenericResponse) }
64
+ def self.list(raw: false, **args)
23
65
  Mangadex::Internal::Request.get(
24
66
  '/statistics/manga',
25
67
  Mangadex::Internal::Definition.validate(args, {
26
68
  manga: { accepts: [String], converts: :to_a },
27
- })
69
+ }),
70
+ raw: raw,
28
71
  )
29
72
  end
73
+
74
+ def self.attributes_to_inspect
75
+ [:follows, :rating, :comments]
76
+ end
30
77
  end
31
78
  end
@@ -0,0 +1,24 @@
1
+ module Mangadex
2
+ class Thread < MangadexObject
3
+ has_attributes \
4
+ :replies_count
5
+
6
+ class << self
7
+ def create(type:, id:)
8
+ payload = {type: type, id: id}
9
+ Mangadex::Internal::Request.post(
10
+ '/forums/thread',
11
+ payload: Mangadex::Internal::Definition.validate(payload, {
12
+ type: { accepts: %w(manga group chapter), converts: :to_s, required: true },
13
+ id: { accepts: String, required: true },
14
+ }),
15
+ auth: true,
16
+ )
17
+ end
18
+ end
19
+
20
+ def self.attributes_to_inspect
21
+ [:id, :type, :replies_count]
22
+ end
23
+ end
24
+ end
@@ -22,6 +22,7 @@ require_relative "report_reason"
22
22
  require_relative "report"
23
23
  require_relative "rating"
24
24
  require_relative "statistic"
25
+ require_relative "thread"
25
26
 
26
27
  # Relationship
27
28
  require_relative "relationship"
@@ -10,9 +10,13 @@ module Mangadex
10
10
  end
11
11
 
12
12
  def underscore(string)
13
- string.gsub(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do
13
+ is_symbol = string.kind_of?(Symbol)
14
+ data = string.to_s
15
+ result = data.gsub(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do
14
16
  ($1 || $2) << "_"
15
17
  end.tr('-', '_').downcase
18
+
19
+ is_symbol ? result.to_sym : result
16
20
  end
17
21
  end
18
22
  end
@@ -2,7 +2,7 @@
2
2
  module Mangadex
3
3
  module Version
4
4
  MAJOR = "5"
5
- MINOR = "8"
5
+ MINOR = "10"
6
6
  TINY = "0"
7
7
  PATCH = nil
8
8
 
data/mangadex.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency "psych", "~> 4.0.1"
25
+ spec.add_dependency "psych", ">= 4.0.1", "< 5.2.0"
26
26
  spec.add_dependency "rest-client", "~> 2.1"
27
27
  spec.add_dependency "sorbet-runtime"
28
28
 
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mangadex
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.8.0
4
+ version: 5.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akinyele Cafe-Febrissy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-20 00:00:00.000000000 Z
11
+ date: 2023-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.0.1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 5.2.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 4.0.1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 5.2.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rest-client
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -174,6 +180,7 @@ files:
174
180
  - lib/mangadex/internal/definitions/accepts.rb
175
181
  - lib/mangadex/internal/definitions/base.rb
176
182
  - lib/mangadex/internal/definitions/content_rating.rb
183
+ - lib/mangadex/internal/definitions/year.rb
177
184
  - lib/mangadex/internal/request.rb
178
185
  - lib/mangadex/internal/with_attributes.rb
179
186
  - lib/mangadex/manga.rb
@@ -190,6 +197,7 @@ files:
190
197
  - lib/mangadex/storage/memory.rb
191
198
  - lib/mangadex/storage/none.rb
192
199
  - lib/mangadex/tag.rb
200
+ - lib/mangadex/thread.rb
193
201
  - lib/mangadex/types.rb
194
202
  - lib/mangadex/upload.rb
195
203
  - lib/mangadex/user.rb
@@ -246,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
254
  - !ruby/object:Gem::Version
247
255
  version: '0'
248
256
  requirements: []
249
- rubygems_version: 3.3.26
257
+ rubygems_version: 3.4.10
250
258
  signing_key:
251
259
  specification_version: 4
252
260
  summary: Your next favourite Ruby gem for interacting with Mangadex.org