mangadex 5.8.0 → 5.9.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: 3962f11d163fbee424561f0f46f10e6311b8a15ad66fb4bc326ae36587b5d285
4
+ data.tar.gz: 693c63aa836bf40b635ed76736160ffcf3de502152f0d2b41401be5b061b3e12
5
5
  SHA512:
6
- metadata.gz: adf076fba8b23de5486b741f9d4e3bf27ad8636059d16c991cd5538f9daea0211f223131349ab7e5b87d81f861ea04ef5580eff022b6c13e480b37886cd6fccd
7
- data.tar.gz: 1632d1a344b5afd3bad0db012d835c736df4ab4eef830e387015b9187c3c4cd0b53bbbcb0e679f5725bb01add4f69ba7b04692cf1dc76abf689424c17669e0c6
6
+ metadata.gz: e9e62bae145e06c736ff43c80132e995a90d922e901b18b2cb1d506ffa01fae45a1abb4edc8fe4e020df37acf4f390e697095303652449b5af7f33e485634994
7
+ data.tar.gz: ad84f862fa9842f7135ffd2e7b58b68f9c2418bceda63dfcd8a190a8a90dae89bacace3a63d2f7b10ff2b1b8a16e694d79534937a06cb75ce170154653262b80
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mangadex (5.8.0)
4
+ mangadex (5.9.0)
5
5
  psych (~> 4.0.1)
6
6
  rest-client (~> 2.1)
7
7
  sorbet-runtime
@@ -47,7 +47,7 @@ GEM
47
47
  rspec-support (3.12.0)
48
48
  sorbet (0.5.10539)
49
49
  sorbet-static (= 0.5.10539)
50
- sorbet-runtime (0.5.10597)
50
+ sorbet-runtime (0.5.10626)
51
51
  sorbet-static (0.5.10539-x86_64-linux)
52
52
  stringio (3.0.4)
53
53
  unf (0.1.4)
@@ -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
@@ -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
 
@@ -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
@@ -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 = "9"
6
6
  TINY = "0"
7
7
  PATCH = nil
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
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.9.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-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych
@@ -190,6 +190,7 @@ files:
190
190
  - lib/mangadex/storage/memory.rb
191
191
  - lib/mangadex/storage/none.rb
192
192
  - lib/mangadex/tag.rb
193
+ - lib/mangadex/thread.rb
193
194
  - lib/mangadex/types.rb
194
195
  - lib/mangadex/upload.rb
195
196
  - lib/mangadex/user.rb
@@ -246,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
247
  - !ruby/object:Gem::Version
247
248
  version: '0'
248
249
  requirements: []
249
- rubygems_version: 3.3.26
250
+ rubygems_version: 3.4.1
250
251
  signing_key:
251
252
  specification_version: 4
252
253
  summary: Your next favourite Ruby gem for interacting with Mangadex.org