mangadex 5.3.3 → 5.3.3.1

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: 166fb230b0125992e5168515129718a28f7d545c3c1cb07f9bc81e837ad8c2c7
4
- data.tar.gz: cf310df080bb7fdce3df2fd885aa478de4ae050272e58d97ce6fdbe0b60459af
3
+ metadata.gz: cdf99fecbef4c256aa1f0b739a7051d68f7f79a864f2525d7a56d5ee6a2cca79
4
+ data.tar.gz: 7250ded43bef9892e3d13323a1cea91c8f45378df330534f1a4f229575a1ebee
5
5
  SHA512:
6
- metadata.gz: 4babccf80e64908e70f612d5afb152b00fef108c827cbfc75a273478ee2f1230b6b2366318bab5a3fadb3b2025e0e7a64bed88746c04484d18a9c1a62a241e2a
7
- data.tar.gz: aebcdeed93c99b1beb9e4723e8371875c21da6629311270cbf2b6ca5c58c55b0dca39e8a222bcd886180ee7b1059e40853948f90a25553da4dea8f1d261b4f44
6
+ metadata.gz: ef23c65119a28a69e2c060b69361be24e3558cdce80b6bed93e1a0fc7463e7f87bca81b59c770c4fb378d68368c0da1713723523f4fee445d829ac9d4e0a973b
7
+ data.tar.gz: 58b0f5ee9763465a0801ebfbaf825c0009b12138bd20996ac34d5183c68a16ed6d515c8555e02b669c29cdbcb5e12916bb7adfec4d0769edbc7e793597d97334
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mangadex (5.3.2)
4
+ mangadex (5.3.3.1)
5
5
  activesupport (~> 6.1)
6
6
  psych (~> 4.0.1)
7
7
  rest-client (~> 2.1)
@@ -4,15 +4,23 @@ module Mangadex
4
4
  class Context
5
5
  extend T::Sig
6
6
 
7
+ DEFAULT_MANGADEX_CONTENT_RATING_VALUES = [
8
+ ContentRating::SAFE,
9
+ ContentRating::SUGGESTIVE,
10
+ ContentRating::EROTICA,
11
+ ].freeze
12
+
7
13
  @@user = nil
8
14
  @@version = nil
9
15
  @@force_raw_requests = nil
16
+ @@tags = nil
17
+ @@allowed_content_ratings = DEFAULT_MANGADEX_CONTENT_RATING_VALUES
10
18
 
11
19
  sig { returns(T.nilable(String)) }
12
20
  def self.version
13
21
  return @@version unless @@version.nil?
14
22
 
15
- @@version = Mangadex::Api::Version.check_mangadex_version
23
+ @@version = Mangadex::Api::VersionChecker.check_mangadex_version
16
24
  end
17
25
 
18
26
  sig { returns(T.nilable(Mangadex::Api::User)) }
@@ -20,6 +28,18 @@ module Mangadex
20
28
  @@user&.with_valid_session
21
29
  end
22
30
 
31
+ sig { returns(T::Array[Mangadex::Tag]) }
32
+ def self.tags
33
+ return @@tags if @@tags
34
+
35
+ @@tags = Mangadex::Tag.list.data
36
+ end
37
+
38
+ sig { returns(T::Array[Mangadex::ContentRating]) }
39
+ def self.allowed_content_ratings
40
+ @@allowed_content_ratings.map { |value| ContentRating.new(value) }
41
+ end
42
+
23
43
  sig { params(user: T.nilable(T.any(Hash, Mangadex::Api::User, Mangadex::User))).void }
24
44
  def self.user=(user)
25
45
  if user.is_a?(Mangadex::Api::User)
@@ -30,7 +50,11 @@ module Mangadex
30
50
  data: user,
31
51
  )
32
52
  elsif user.is_a?(Hash)
33
- user = user.with_indifferent_access
53
+ user = Mangadex::Internal::Definition.validate(user, {
54
+ mangadex_user_id: { accepts: String, required: true },
55
+ session: { accepts: String },
56
+ refresh: { accepts: String },
57
+ })
34
58
 
35
59
  @@user = Mangadex::Api::User.new(
36
60
  user[:mangadex_user_id],
@@ -44,13 +68,9 @@ module Mangadex
44
68
 
45
69
  sig { params(user: T.nilable(T.any(Hash, Mangadex::Api::User, Mangadex::User)), block: T.proc.returns(T.untyped)).returns(T.untyped) }
46
70
  def self.with_user(user, &block)
47
- current_user = @@user
48
- @@user = user
49
- response = yield
50
- @@user = current_user
51
- response
52
- ensure
53
- @@user = current_user
71
+ temp_set_value("user", user) do
72
+ yield
73
+ end
54
74
  end
55
75
 
56
76
  sig { params(block: T.proc.returns(T.untyped)).returns(T.untyped) }
@@ -62,7 +82,7 @@ module Mangadex
62
82
 
63
83
  def self.force_raw_requests(&block)
64
84
  if block_given?
65
- temp_force_raw_requests do
85
+ temp_set_value("force_raw_requests", true) do
66
86
  yield
67
87
  end
68
88
  else
@@ -74,16 +94,43 @@ module Mangadex
74
94
  @@force_raw_requests = value
75
95
  end
76
96
 
97
+ def self.allow_content_ratings(*content_ratings, &block)
98
+ content_ratings = if content_ratings.empty?
99
+ allowed_content_ratings
100
+ else
101
+ Mangadex::ContentRating.parse(content_ratings)
102
+ end
103
+ if block_given?
104
+ # set temporarily
105
+ temp_set_value("allowed_content_ratings", content_ratings) do
106
+ yield
107
+ end
108
+ elsif content_ratings.any?
109
+ # set "permanently"
110
+ @@allowed_content_ratings = content_ratings
111
+ else
112
+ # This is to throw an exception prompting to pass a block if there no params.
113
+ yield
114
+ end
115
+ end
116
+
117
+ def self.with_allowed_content_ratings(*other_content_ratings, &block)
118
+ T.unsafe(self).allow_content_ratings(*(allowed_content_ratings + other_content_ratings)) do
119
+ yield
120
+ end
121
+ end
122
+
77
123
  private
78
124
 
79
- def self.temp_force_raw_requests(&block)
80
- current_force_raw_requests = @@force_raw_requests
81
- @@force_raw_requests = true
125
+ def self.temp_set_value(name, value, &block)
126
+ var_name = "@@#{name}"
127
+ current_value = class_variable_get(var_name)
128
+ class_variable_set(var_name, value)
82
129
  response = yield
83
- @@force_raw_requests = current_force_raw_requests
130
+ class_variable_set(var_name, current_value)
84
131
  response
85
132
  ensure
86
- @@force_raw_requests = current_force_raw_requests
133
+ class_variable_set(var_name, current_value) if current_value
87
134
  end
88
135
  end
89
136
  end
@@ -3,7 +3,7 @@ require "psych"
3
3
 
4
4
  module Mangadex
5
5
  module Api
6
- class Version
6
+ class VersionChecker
7
7
  extend T::Sig
8
8
 
9
9
  sig { returns(T.nilable(String)) }
@@ -13,7 +13,7 @@ module Mangadex
13
13
  :melon_book,
14
14
  :fan_box,
15
15
  :booth,
16
- :nicovideo,
16
+ :nico_video,
17
17
  :skeb,
18
18
  :fantia,
19
19
  :tumblr,
@@ -26,6 +26,7 @@ module Mangadex
26
26
  Mangadex::Internal::Request.get(
27
27
  '/chapter',
28
28
  Mangadex::Internal::Definition.chapter_list(args),
29
+ content_rating: true,
29
30
  )
30
31
  end
31
32
 
@@ -28,6 +28,11 @@ module Mangadex
28
28
  SCORES.keys.map { |key| ContentRating.new(key) }.select { |record| record <= content_rating }.sort
29
29
  end
30
30
 
31
+ sig { params(content_ratings: T::Array[T.any(T::Api::Text, T::Api::ContentRating)]).returns(T::Array[ContentRating]) }
32
+ def self.parse(content_ratings)
33
+ content_ratings.map { |content_rating| ContentRating.new(content_rating) }.uniq
34
+ end
35
+
31
36
  sig { params(value: T.any(T::Api::Text, T::Api::ContentRating)).void }
32
37
  def initialize(value)
33
38
  @value = ensure_value!(value.to_s)
@@ -62,6 +62,7 @@ module Mangadex
62
62
  Mangadex::Internal::Request.get(
63
63
  '/list/%{id}/feed' % {id: id},
64
64
  Mangadex::Internal::Definition.chapter_list(args),
65
+ content_rating: true,
65
66
  )
66
67
  end
67
68
 
@@ -157,7 +157,7 @@ module Mangadex
157
157
  if errors.any?
158
158
  error_message = errors.map do |error|
159
159
  if error[:extra]
160
- "paalidate_required!rams[:#{error[:extra]}] does not exist and cannot be passed to this request"
160
+ "params[:#{error[:extra]}] does not exist and cannot be passed to this request"
161
161
  elsif error[:message]
162
162
  error[:message]
163
163
  else
@@ -13,9 +13,9 @@ module Mangadex
13
13
  attr_accessor :path, :headers, :payload, :method, :raw
14
14
  attr_reader :response
15
15
 
16
- def self.get(path, params={}, auth: false, headers: nil, raw: false)
16
+ def self.get(path, params={}, auth: false, headers: nil, raw: false, content_rating: false)
17
17
  new(
18
- path_with_params(path, params),
18
+ path_with_params(path, params, content_rating),
19
19
  method: :get,
20
20
  headers: headers,
21
21
  payload: nil,
@@ -78,7 +78,8 @@ module Mangadex
78
78
 
79
79
  private
80
80
 
81
- def self.path_with_params(path, params)
81
+ def self.path_with_params(path, params, content_rating)
82
+ params = content_rating ? self.with_content_rating(params) : params
82
83
  return path if params.blank?
83
84
 
84
85
  params = params.deep_transform_keys do |key|
@@ -87,6 +88,14 @@ module Mangadex
87
88
  "#{path}?#{params.to_query}"
88
89
  end
89
90
 
91
+ def self.with_content_rating(data)
92
+ content_rating = data.has_key?(:content_rating) ? data[:content_rating] : []
93
+ Mangadex::Api::Context.allow_content_ratings(*content_rating) do
94
+ data[:content_rating] = Mangadex::Api::Context.allowed_content_ratings
95
+ end
96
+ data
97
+ end
98
+
90
99
  def request_url
91
100
  request_path = path.start_with?('/') ? path : "/#{path}"
92
101
  "#{BASE_URI}#{request_path}"
@@ -50,6 +50,7 @@ module Mangadex
50
50
  order: { accepts: Hash },
51
51
  includes: { accepts: Array, converts: to_a },
52
52
  }),
53
+ content_rating: true,
53
54
  )
54
55
  end
55
56
 
@@ -101,6 +102,7 @@ module Mangadex
101
102
  Mangadex::Internal::Request.get(
102
103
  '/manga/%{id}/feed' % {id: id},
103
104
  Mangadex::Internal::Definition.chapter_list(args),
105
+ content_rating: true,
104
106
  )
105
107
  end
106
108
 
@@ -18,7 +18,6 @@ module T
18
18
  T.any(
19
19
  Mangadex::Api::Response[Mangadex::Manga],
20
20
  Mangadex::Api::Response[T::Array[Mangadex::Manga]],
21
- Hash,
22
21
  )
23
22
  end
24
23
  ChapterResponse = T.type_alias do
data/lib/mangadex/tag.rb CHANGED
@@ -3,6 +3,11 @@ module Mangadex
3
3
  class Tag < MangadexObject
4
4
  has_attributes :name, :description, :group, :version
5
5
 
6
+ sig { returns(Mangadex::Api::Response[Mangadex::Tag]) }
7
+ def self.list
8
+ Mangadex::Manga.tag_list
9
+ end
10
+
6
11
  def self.attributes_to_inspect
7
12
  %i(name)
8
13
  end
data/lib/mangadex/user.rb CHANGED
@@ -11,6 +11,7 @@ module Mangadex
11
11
  Mangadex::Internal::Request.get(
12
12
  '/user/follows/manga/feed',
13
13
  Mangadex::Internal::Definition.chapter_list(args),
14
+ content_rating: true,
14
15
  auth: true,
15
16
  )
16
17
  end
@@ -4,7 +4,7 @@ module Mangadex
4
4
  MAJOR = "5"
5
5
  MINOR = "3"
6
6
  TINY = "3"
7
- PATCH = nil
7
+ PATCH = "1"
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
10
10
  FULL = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mangadex
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.3
4
+ version: 5.3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akinyele Cafe-Febrissy