mangadex 5.3.1.3 → 5.3.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
 
@@ -66,6 +67,8 @@ module Mangadex
66
67
 
67
68
  sig { params(id: String, args: T::Api::Arguments).returns(T::Api::MangaResponse) }
68
69
  def self.view(id, **args)
70
+ Mangadex::Internal::Definition.must(id)
71
+
69
72
  Mangadex::Internal::Request.get(
70
73
  '/manga/%{id}' % {id: id},
71
74
  Mangadex::Internal::Definition.validate(args, {
@@ -76,6 +79,8 @@ module Mangadex
76
79
 
77
80
  sig { params(id: String).returns(T.any(Hash, Mangadex::Api::Response)) }
78
81
  def self.unfollow(id)
82
+ Mangadex::Internal::Definition.must(id)
83
+
79
84
  Mangadex::Internal::Request.delete(
80
85
  '/manga/%{id}/follow' % {id: id},
81
86
  )
@@ -83,6 +88,8 @@ module Mangadex
83
88
 
84
89
  sig { params(id: String).returns(T.any(Hash, Mangadex::Api::Response)) }
85
90
  def self.follow(id)
91
+ Mangadex::Internal::Definition.must(id)
92
+
86
93
  Mangadex::Internal::Request.post(
87
94
  '/manga/%{id}/follow' % {id: id},
88
95
  )
@@ -90,9 +97,12 @@ module Mangadex
90
97
 
91
98
  sig { params(id: String, args: T::Api::Arguments).returns(T::Api::ChapterResponse) }
92
99
  def self.feed(id, **args)
100
+ Mangadex::Internal::Definition.must(id)
101
+
93
102
  Mangadex::Internal::Request.get(
94
103
  '/manga/%{id}/feed' % {id: id},
95
104
  Mangadex::Internal::Definition.chapter_list(args),
105
+ content_rating: true,
96
106
  )
97
107
  end
98
108
 
@@ -113,14 +123,16 @@ module Mangadex
113
123
  )
114
124
  end
115
125
 
116
- sig { params(args: T::Api::Arguments).returns(T::Api::GenericResponse) }
117
- def self.all_reading_status(**args)
126
+ sig { params(status: String).returns(T::Api::GenericResponse) }
127
+ def self.all_reading_status(status)
128
+ args = { status: status }
129
+
118
130
  Mangadex::Internal::Request.get(
119
131
  '/manga/status',
120
132
  Mangadex::Internal::Definition.validate(args, {
121
133
  status: {
122
134
  accepts: %w(reading on_hold dropped plan_to_read re_reading completed),
123
- converts: Mangadex::Internal::Definition.converts(:to_a),
135
+ converts: :to_s,
124
136
  },
125
137
  })
126
138
  )
@@ -128,6 +140,8 @@ module Mangadex
128
140
 
129
141
  sig { params(id: String).returns(T::Api::GenericResponse) }
130
142
  def self.reading_status(id)
143
+ Mangadex::Internal::Definition.must(id)
144
+
131
145
  Mangadex::Internal::Request.get(
132
146
  '/manga/%{id}/status' % {id: id},
133
147
  )
@@ -135,6 +149,8 @@ module Mangadex
135
149
 
136
150
  sig { params(id: String, status: String).returns(T::Api::GenericResponse) }
137
151
  def self.update_reading_status(id, status)
152
+ Mangadex::Internal::Definition.must(id)
153
+
138
154
  Mangadex::Internal::Request.post(
139
155
  '/manga/%{id}/status' % {id: id},
140
156
  payload: Mangadex::Internal::Definition.validate({status: status}, {
@@ -149,11 +165,15 @@ module Mangadex
149
165
  # Untested API endpoints
150
166
  sig { params(id: String, args: T::Api::Arguments).returns(T::Api::MangaResponse) }
151
167
  def self.update(id, **args)
168
+ Mangadex::Internal::Definition.must(id)
169
+
152
170
  Mangadex::Internal::Request.put('/manga/%{id}' % {id: id}, payload: args)
153
171
  end
154
172
 
155
173
  sig { params(id: String).returns(Hash) }
156
174
  def self.delete(id)
175
+ Mangadex::Internal::Definition.must(id)
176
+
157
177
  Mangadex::Internal::Request.delete(
158
178
  '/manga/%{id}' % {id: id},
159
179
  )
@@ -169,6 +189,8 @@ module Mangadex
169
189
 
170
190
  class << self
171
191
  alias_method :aggregate, :volumes_and_chapters
192
+ alias_method :get, :view
193
+ alias_method :edit, :update
172
194
  end
173
195
 
174
196
  sig { returns(T.nilable(ContentRating)) }
@@ -1,33 +1,45 @@
1
1
  # typed: false
2
2
  module Mangadex
3
3
  class Relationship < MangadexObject
4
- attr_accessor :id, :type, :attributes
4
+ attr_accessor :id, :type, :related, :attributes
5
+
6
+ RELATED_VALUES = %w(
7
+ monochrome
8
+ main_story
9
+ adapted_from
10
+ based_on
11
+ prequel
12
+ side_story
13
+ doujinshi
14
+ same_franchise
15
+ shared_universe
16
+ sequel
17
+ spin_off
18
+ alternate_story
19
+ preserialization
20
+ colored
21
+ serialization
22
+ ).freeze
5
23
 
6
24
  class << self
7
25
  def from_data(data)
8
26
  data = data.with_indifferent_access
9
27
  klass = class_for_relationship_type(data['type'])
10
28
 
11
- return klass.from_data(data) if klass && data['attributes']&.any?
29
+ if klass && data['attributes']&.any?
30
+ return klass.from_data(data, related_type: data['related'])
31
+ end
12
32
 
13
33
  new(
14
34
  id: data['id'],
15
35
  type: data['type'],
16
36
  attributes: OpenStruct.new(data['attributes']),
37
+ related: data['related'],
17
38
  )
18
39
  end
19
40
 
20
41
  private
21
42
 
22
- def build_attributes(data)
23
- klass = class_for_relationship_type(data['type'])
24
- if klass.present?
25
- klass.from_data(data)
26
- else
27
- OpenStruct.new(data['attributes'])
28
- end
29
- end
30
-
31
43
  def class_for_relationship_type(type)
32
44
  module_parts = self.name.split('::')
33
45
  module_name = module_parts.take(module_parts.size - 1).join('::')
@@ -39,8 +51,18 @@ module Mangadex
39
51
  end
40
52
  end
41
53
 
42
- def inspect
43
- "#<#{self.class} id=#{id.inspect} type=#{type.inspect}>"
54
+ def self.attributes_to_inspect
55
+ [:id, :type, :related]
56
+ end
57
+
58
+
59
+ def method_missing(value)
60
+ return super unless value.end_with?("?")
61
+
62
+ looking_for_related = value.to_s.split("?").first
63
+ return super unless RELATED_VALUES.include?(looking_for_related)
64
+
65
+ !related.nil? && related == looking_for_related
44
66
  end
45
67
  end
46
68
  end
@@ -3,6 +3,7 @@ module Mangadex
3
3
  class ScanlationGroup < MangadexObject
4
4
  has_attributes \
5
5
  :name,
6
+ :alt_names,
6
7
  :website,
7
8
  :irc_channel,
8
9
  :irc_server,
@@ -47,6 +48,8 @@ module Mangadex
47
48
  end
48
49
 
49
50
  def view(id)
51
+ Mangadex::Internal::Definition.must(id)
52
+
50
53
  Mangadex::Internal::Request.get(
51
54
  '/group/%{id}' % {id: id},
52
55
  Mangadex::Internal::Definition.validate(args, {
@@ -91,6 +94,11 @@ module Mangadex
91
94
  end
92
95
  end
93
96
 
97
+ class << self
98
+ alias_method :get, :view
99
+ alias_method :edit, :update
100
+ end
101
+
94
102
  def self.inspect_attributes
95
103
  self.attributes - [:version, :created_at, :updated_at]
96
104
  end
@@ -17,7 +17,7 @@ module T
17
17
  MangaResponse = T.type_alias do
18
18
  T.any(
19
19
  Mangadex::Api::Response[Mangadex::Manga],
20
- Mangadex::Api::Response[T::Array[Mangadex::Manga]]
20
+ Mangadex::Api::Response[T::Array[Mangadex::Manga]],
21
21
  )
22
22
  end
23
23
  ChapterResponse = T.type_alias do
@@ -0,0 +1,18 @@
1
+ module Mangadex
2
+ module Storage
3
+ class Basic
4
+ def get(_scope, _key)
5
+ raise NotImplementedError
6
+ end
7
+
8
+ def set(_scope, _key, _value)
9
+ raise NotImplementedError
10
+ end
11
+
12
+ def clear(_scope)
13
+ warn("Don't know how to clear #{self.class} storage strategy! Skipping...")
14
+ nil
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module Mangadex
2
+ module Storage
3
+ class Memory < BasicObject
4
+ def initialize
5
+ @storage = {}
6
+ end
7
+
8
+ def get(scope, key)
9
+ @storage.dig(scope.to_s, key.to_s)
10
+ end
11
+
12
+ def set(scope, key, value)
13
+ key = key.to_s
14
+ @storage[scope] = {} unless @storage.has_key?(scope)
15
+ @storage[scope][key] = value
16
+ end
17
+
18
+ def clear(scope)
19
+ @storage.delete(scope)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ module Mangadex
2
+ module Storage
3
+ class None < Basic
4
+ def get(_scope, _key); end
5
+ def set(_scope, _key, _value); end
6
+ def clear(_scope); end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ require_relative "storage/basic"
2
+ require_relative "storage/none"
3
+ require_relative "storage/memory"
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
@@ -28,6 +28,8 @@ module Mangadex
28
28
  alias_method :begin, :start
29
29
 
30
30
  def upload_images(upload_session_id)
31
+ Mangadex::Internal::Definition.must(upload_session_id)
32
+
31
33
  Mangadex::Internal::Request.post(
32
34
  '/upload/%{upload_session_id}' % {upload_session_id: upload_session_id},
33
35
  payload: Mangadex::Internal::Definition.validate(args, {
@@ -37,6 +39,8 @@ module Mangadex
37
39
  end
38
40
 
39
41
  def abandon(upload_session_id)
42
+ Mangadex::Internal::Definition.must(upload_session_id)
43
+
40
44
  Mangadex::Internal::Request.delete(
41
45
  '/upload/%{upload_session_id}' % {upload_session_id: upload_session_id},
42
46
  )
@@ -44,6 +48,8 @@ module Mangadex
44
48
  alias_method :stop, :abandon
45
49
 
46
50
  def commit(upload_session_id, **args)
51
+ Mangadex::Internal::Definition.must(upload_session_id)
52
+
47
53
  Mangadex::Internal::Request.post(
48
54
  '/upload/%{upload_session_id}/commit' % {upload_session_id: upload_session_id},
49
55
  payload: Mangadex::Internal::Definition.validate(args, {
@@ -54,6 +60,8 @@ module Mangadex
54
60
  end
55
61
 
56
62
  def delete_uploaded_image(upload_session_id, upload_session_file_id)
63
+ Mangadex::Internal::Definition.must(upload_session_id)
64
+
57
65
  Mangadex::Internal::Request.delete(
58
66
  '/upload/%{upload_session_id}/%{upload_session_file_id}' % {
59
67
  upload_session_id: upload_session_id,
@@ -63,6 +71,8 @@ module Mangadex
63
71
  end
64
72
 
65
73
  def delete_uploaded_images(upload_session_id, upload_session_file_ids)
74
+ Mangadex::Internal::Definition.must(upload_session_id)
75
+
66
76
  Mangadex::Internal::Request.delete(
67
77
  '/upload/%{upload_session_id}' % {upload_session_id: upload_session_id},
68
78
  payload: Array(upload_session_file_id),
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
@@ -30,6 +31,8 @@ module Mangadex
30
31
 
31
32
  sig { params(id: String).returns(T::Boolean) }
32
33
  def self.follows_group(id)
34
+ Mangadex::Internal::Definition.must(id)
35
+
33
36
  data = Mangadex::Internal::Request.get(
34
37
  '/user/follows/group/%{id}' % {id: id},
35
38
  raw: true,
@@ -55,7 +58,9 @@ module Mangadex
55
58
 
56
59
  sig { params(id: String).returns(T::Boolean) }
57
60
  def self.follows_user(id)
58
- return if Mangadex::Api::Context.user.nil?
61
+ Mangadex::Internal::Definition.must(id)
62
+
63
+ return if Mangadex.context.user.nil?
59
64
 
60
65
  data = Mangadex::Internal::Request.get(
61
66
  '/user/follows/user/%{id}' % {id: id},
@@ -83,7 +88,9 @@ module Mangadex
83
88
 
84
89
  sig { params(id: String).returns(T::Boolean) }
85
90
  def self.follows_manga(id)
86
- return if Mangadex::Api::Context.user.nil?
91
+ Mangadex::Internal::Definition.must(id)
92
+
93
+ return if Mangadex.context.user.nil?
87
94
 
88
95
  data = Mangadex::Internal::Request.get(
89
96
  '/user/follows/manga/%{id}' % {id: id},
@@ -3,8 +3,8 @@ module Mangadex
3
3
  module Version
4
4
  MAJOR = "5"
5
5
  MINOR = "3"
6
- TINY = "1"
7
- PATCH = "3"
6
+ TINY = "3"
7
+ PATCH = "2"
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
10
10
  FULL = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
data/lib/mangadex.rb CHANGED
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: true
2
2
  require 'sorbet-runtime'
3
3
 
4
4
  require 'active_support'
@@ -14,22 +14,35 @@ require "mangadex/types"
14
14
  # API, to interact with Mangadex
15
15
  require "mangadex/api"
16
16
 
17
+ # Persist strategies
18
+ require "mangadex/storage"
19
+
20
+ require_relative "config"
21
+ require_relative "errors"
22
+
17
23
  # Namespace for classes and modules for this gem.
18
24
  # @since 5.3.0
19
25
 
20
26
  module Mangadex
21
- # Standard error class for this gem.
22
- #
23
- # @author thedrummeraki
24
- # @since 0.6.0
25
- class Error < StandardError
26
- extend T::Sig
27
- end
27
+ class << self
28
+ def configuration
29
+ @configuration ||= Config.new
30
+ end
31
+
32
+ def context
33
+ @context ||= Internal::Context.new
34
+ end
35
+
36
+ def configure(&block)
37
+ yield(configuration)
38
+ end
39
+
40
+ def storage
41
+ configuration.storage
42
+ end
28
43
 
29
- class UserNotLoggedIn < Error
30
- sig { returns(String) }
31
- def message
32
- "You are not logged in. Use [Mangadex::Auth.login] to log in."
44
+ def api_version
45
+ context.version
33
46
  end
34
47
  end
35
48
  end
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.3.1.3
4
+ version: 5.3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akinyele Cafe-Febrissy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-25 00:00:00.000000000 Z
11
+ date: 2021-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych
@@ -150,7 +150,7 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- description:
153
+ description:
154
154
  email:
155
155
  - me@akinyele.ca
156
156
  executables: []
@@ -170,11 +170,14 @@ files:
170
170
  - Rakefile
171
171
  - bin/console
172
172
  - bin/setup
173
+ - docs/authentication.md
174
+ - docs/context.md
175
+ - lib/config.rb
176
+ - lib/errors.rb
173
177
  - lib/extensions.rb
174
178
  - lib/mangadex.rb
175
179
  - lib/mangadex/README.md
176
180
  - lib/mangadex/api.rb
177
- - lib/mangadex/api/context.rb
178
181
  - lib/mangadex/api/response.rb
179
182
  - lib/mangadex/api/user.rb
180
183
  - lib/mangadex/api/version_checker.rb
@@ -186,6 +189,7 @@ files:
186
189
  - lib/mangadex/cover_art.rb
187
190
  - lib/mangadex/custom_list.rb
188
191
  - lib/mangadex/internal.rb
192
+ - lib/mangadex/internal/context.rb
189
193
  - lib/mangadex/internal/definition.rb
190
194
  - lib/mangadex/internal/request.rb
191
195
  - lib/mangadex/internal/with_attributes.rb
@@ -195,6 +199,10 @@ files:
195
199
  - lib/mangadex/report_reason.rb
196
200
  - lib/mangadex/scanlation_group.rb
197
201
  - lib/mangadex/sorbet.rb
202
+ - lib/mangadex/storage.rb
203
+ - lib/mangadex/storage/basic.rb
204
+ - lib/mangadex/storage/memory.rb
205
+ - lib/mangadex/storage/none.rb
198
206
  - lib/mangadex/tag.rb
199
207
  - lib/mangadex/types.rb
200
208
  - lib/mangadex/upload.rb
@@ -236,7 +244,7 @@ homepage: https://github.com/thedrummeraki/mangadex
236
244
  licenses:
237
245
  - MIT
238
246
  metadata: {}
239
- post_install_message:
247
+ post_install_message:
240
248
  rdoc_options: []
241
249
  require_paths:
242
250
  - lib
@@ -252,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
260
  version: '0'
253
261
  requirements: []
254
262
  rubygems_version: 3.2.15
255
- signing_key:
263
+ signing_key:
256
264
  specification_version: 4
257
265
  summary: Your next favourite Ruby gem for interacting with Mangadex.org
258
266
  test_files: []
@@ -1,63 +0,0 @@
1
- # typed: true
2
- module Mangadex
3
- module Api
4
- class Context
5
- extend T::Sig
6
-
7
- @@user = nil
8
- @@version = nil
9
-
10
- sig { returns(T.nilable(String)) }
11
- def self.version
12
- return @@version unless @@version.nil?
13
-
14
- @@version = Mangadex::Api::Version.check_mangadex_version
15
- end
16
-
17
- sig { returns(T.nilable(Mangadex::Api::User)) }
18
- def self.user
19
- @@user&.with_valid_session
20
- end
21
-
22
- sig { params(user: T.nilable(T.any(Hash, Mangadex::Api::User, Mangadex::User))).void }
23
- def self.user=(user)
24
- if user.is_a?(Mangadex::Api::User)
25
- @@user = user
26
- elsif user.is_a?(Mangadex::User)
27
- @@user = Mangadex::Api::User.new(
28
- user.id,
29
- data: user,
30
- )
31
- elsif user.is_a?(Hash)
32
- user = user.with_indifferent_access
33
-
34
- @@user = Mangadex::Api::User.new(
35
- user[:mangadex_user_id],
36
- session: user[:session],
37
- refresh: user[:refresh],
38
- )
39
- elsif user.nil?
40
- @@user = nil
41
- end
42
- end
43
-
44
- sig { params(user: T.nilable(T.any(Hash, Mangadex::Api::User, Mangadex::User)), block: T.proc.returns(T.untyped)).returns(T.untyped) }
45
- def self.with_user(user, &block)
46
- current_user = @@user
47
- @@user = user
48
- response = yield
49
- @@user = current_user
50
- response
51
- ensure
52
- @@user = current_user
53
- end
54
-
55
- sig { params(block: T.proc.returns(T.untyped)).returns(T.untyped) }
56
- def self.without_user(&block)
57
- with_user(nil) do
58
- yield
59
- end
60
- end
61
- end
62
- end
63
- end