mangadex 5.3.1.1 → 5.3.1.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/mangadex/api/context.rb +47 -37
- data/lib/mangadex/api/user.rb +6 -1
- data/lib/mangadex/api/version_checker.rb +31 -0
- data/lib/mangadex/api.rb +1 -1
- data/lib/mangadex/auth.rb +48 -44
- data/lib/mangadex/version.rb +10 -2
- data/mangadex.gemspec +1 -1
- metadata +7 -7
- data/lib/mangadex/api/version.rb +0 -23
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7f849f066bfd4117f3a62b0712201ee6cafe769a7c2e6d6ef9d75789200accb9
|
|
4
|
+
data.tar.gz: 74deaae68ac7efe1b3634495689350a34b0b2479508518a11ae8162207c41b55
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: daae07877b80764aa77d3aa3ed5e4332f93c60cd72a70c5aaba48d5de4a12c5f6259b19fae0dcbf9f11a7cfc24f4d4d7fd9c761a2ecacd0172bc968bde69670c
|
|
7
|
+
data.tar.gz: 39515e57425a001d787a2bab769694e25c6da7aea8cbf7ffb1a3ee1d263cc7143576fbe916889180437d7c416ffaea392430d1a86080d135f40c2f4bd54d9df8
|
data/Gemfile.lock
CHANGED
data/lib/mangadex/api/context.rb
CHANGED
|
@@ -2,50 +2,60 @@
|
|
|
2
2
|
module Mangadex
|
|
3
3
|
module Api
|
|
4
4
|
class Context
|
|
5
|
+
extend T::Sig
|
|
6
|
+
|
|
5
7
|
@@user = nil
|
|
8
|
+
@@version = nil
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
end
|
|
10
|
+
sig { returns(T.nilable(String)) }
|
|
11
|
+
def self.version
|
|
12
|
+
return @@version unless @@version.nil?
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
)
|
|
20
|
-
elsif user.is_a?(Hash)
|
|
21
|
-
user = user.with_indifferent_access
|
|
22
|
-
|
|
23
|
-
@@user = Mangadex::Api::User.new(
|
|
24
|
-
user[:mangadex_user_id],
|
|
25
|
-
session: user[:session],
|
|
26
|
-
refresh: user[:refresh],
|
|
27
|
-
)
|
|
28
|
-
elsif user.nil?
|
|
29
|
-
@@user = nil
|
|
30
|
-
else
|
|
31
|
-
raise ArgumentError, "Must be an instance of #{Mangadex::Api::User}, #{Mangadex::User} or Hash"
|
|
32
|
-
end
|
|
33
|
-
end
|
|
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
|
|
34
21
|
|
|
35
|
-
|
|
36
|
-
|
|
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)
|
|
37
25
|
@@user = user
|
|
38
|
-
|
|
39
|
-
@@user =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
43
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
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
49
59
|
end
|
|
50
60
|
end
|
|
51
61
|
end
|
data/lib/mangadex/api/user.rb
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
module Mangadex
|
|
3
3
|
module Api
|
|
4
4
|
class User
|
|
5
|
+
extend T::Sig
|
|
6
|
+
|
|
5
7
|
attr_accessor :mangadex_user_id, :session, :refresh, :session_valid_until
|
|
6
8
|
attr_reader :data
|
|
7
9
|
|
|
10
|
+
sig { params(mangadex_user_id: String, session: T.nilable(String), refresh: T.nilable(String), data: T.untyped).void }
|
|
8
11
|
def initialize(mangadex_user_id, session: nil, refresh: nil, data: nil)
|
|
9
12
|
raise ArgumentError, 'Missing mangadex_user_id' if mangadex_user_id.to_s.empty?
|
|
10
13
|
|
|
@@ -15,9 +18,9 @@ module Mangadex
|
|
|
15
18
|
@data = data
|
|
16
19
|
end
|
|
17
20
|
|
|
18
|
-
# nil: Nothing happened, no need to refresh the token
|
|
19
21
|
# true: The tokens were successfully refreshed
|
|
20
22
|
# false: Error: refresh token empty or could not refresh the token on the server
|
|
23
|
+
sig { returns(T::Boolean) }
|
|
21
24
|
def refresh!
|
|
22
25
|
return false if refresh.nil?
|
|
23
26
|
|
|
@@ -33,6 +36,7 @@ module Mangadex
|
|
|
33
36
|
true
|
|
34
37
|
end
|
|
35
38
|
|
|
39
|
+
sig { returns(Mangadex::Api::User) }
|
|
36
40
|
def with_valid_session
|
|
37
41
|
session_expired? && refresh!
|
|
38
42
|
self
|
|
@@ -40,6 +44,7 @@ module Mangadex
|
|
|
40
44
|
self
|
|
41
45
|
end
|
|
42
46
|
|
|
47
|
+
sig { returns(T::Boolean) }
|
|
43
48
|
def session_expired?
|
|
44
49
|
@session_valid_until.nil? || @session_valid_until <= Time.now
|
|
45
50
|
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
require "psych"
|
|
3
|
+
|
|
4
|
+
module Mangadex
|
|
5
|
+
module Api
|
|
6
|
+
class Version
|
|
7
|
+
extend T::Sig
|
|
8
|
+
|
|
9
|
+
sig { returns(T.nilable(String)) }
|
|
10
|
+
def self.check_mangadex_version
|
|
11
|
+
puts("Checking Mangadex's latest API version...")
|
|
12
|
+
version = Psych.load(
|
|
13
|
+
RestClient.get(
|
|
14
|
+
'https://api.mangadex.org/api.yaml',
|
|
15
|
+
).body,
|
|
16
|
+
).dig('info', 'version')
|
|
17
|
+
|
|
18
|
+
if version != Mangadex::Version::STRING
|
|
19
|
+
warn(
|
|
20
|
+
"[Warning] This gem is compatible with #{Mangadex::Version::STRING} but it looks like Mangadex is at #{version}",
|
|
21
|
+
"[Warning] Check out #{Mangadex::Internal::Request::BASE_URI} for more information.",
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
version
|
|
26
|
+
rescue => error
|
|
27
|
+
nil
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
data/lib/mangadex/api.rb
CHANGED
data/lib/mangadex/auth.rb
CHANGED
|
@@ -1,56 +1,60 @@
|
|
|
1
1
|
# typed: false
|
|
2
2
|
module Mangadex
|
|
3
3
|
class Auth
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
extend T::Sig
|
|
5
|
+
|
|
6
|
+
sig { params(username: String, password: String).returns(T.any(T::Boolean, Mangadex::Api::Response)) }
|
|
7
|
+
def self.login(username, password)
|
|
8
|
+
response = Mangadex::Internal::Request.post(
|
|
9
|
+
'/auth/login',
|
|
10
|
+
payload: {
|
|
11
|
+
username: username,
|
|
12
|
+
password: password,
|
|
13
|
+
},
|
|
14
|
+
)
|
|
15
|
+
return response if response.is_a?(Mangadex::Api::Response) && response.errored?
|
|
16
|
+
|
|
17
|
+
session = response.dig('token', 'session')
|
|
18
|
+
refresh = response.dig('token', 'refresh')
|
|
19
|
+
|
|
20
|
+
mangadex_user = Mangadex::Internal::Request.get('/user/me', headers: { Authorization: session })
|
|
21
|
+
|
|
22
|
+
user = Mangadex::Api::User.new(
|
|
23
|
+
mangadex_user.data.id,
|
|
24
|
+
session: session,
|
|
25
|
+
refresh: refresh,
|
|
26
|
+
data: mangadex_user.data,
|
|
27
|
+
)
|
|
28
|
+
Mangadex::Api::Context.user = user
|
|
29
|
+
!user.session_expired?
|
|
30
|
+
end
|
|
19
31
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
sig { returns(Hash) }
|
|
33
|
+
def self.check_token
|
|
34
|
+
JSON.parse(
|
|
35
|
+
Mangadex::Internal::Request.get(
|
|
36
|
+
'/auth/check',
|
|
37
|
+
raw: true,
|
|
25
38
|
)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def check_token
|
|
31
|
-
JSON.parse(
|
|
32
|
-
Mangadex::Internal::Request.get(
|
|
33
|
-
'/auth/check',
|
|
34
|
-
raw: true,
|
|
35
|
-
)
|
|
36
|
-
)
|
|
37
|
-
end
|
|
39
|
+
)
|
|
40
|
+
end
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
sig { returns(T.any(T::Boolean, Mangadex::Api::Response)) }
|
|
43
|
+
def self.logout
|
|
44
|
+
return true if Mangadex::Api::Context.user.nil?
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
response = Mangadex::Internal::Request.post(
|
|
47
|
+
'/auth/logout',
|
|
48
|
+
)
|
|
49
|
+
return reponse if response.is_a?(Mangadex::Api::Response) && response.errored?
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
Mangadex::Api::Context.user = nil
|
|
52
|
+
true
|
|
53
|
+
end
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
sig { returns(T::Boolean) }
|
|
56
|
+
def self.refresh_token
|
|
57
|
+
!(Mangadex::Api::Context.user&.refresh!).nil?
|
|
54
58
|
end
|
|
55
59
|
end
|
|
56
60
|
end
|
data/lib/mangadex/version.rb
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
# typed:
|
|
1
|
+
# typed: false
|
|
2
2
|
module Mangadex
|
|
3
|
-
|
|
3
|
+
module Version
|
|
4
|
+
MAJOR = "5"
|
|
5
|
+
MINOR = "3"
|
|
6
|
+
TINY = "1"
|
|
7
|
+
PATCH = "2"
|
|
8
|
+
|
|
9
|
+
STRING = [MAJOR, MINOR, TINY].compact.join('.')
|
|
10
|
+
FULL = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
|
|
11
|
+
end
|
|
4
12
|
end
|
data/mangadex.gemspec
CHANGED
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.
|
|
4
|
+
version: 5.3.1.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-
|
|
11
|
+
date: 2021-09-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: psych
|
|
@@ -136,7 +136,7 @@ dependencies:
|
|
|
136
136
|
- - ">="
|
|
137
137
|
- !ruby/object:Gem::Version
|
|
138
138
|
version: '0'
|
|
139
|
-
description:
|
|
139
|
+
description:
|
|
140
140
|
email:
|
|
141
141
|
- me@akinyele.ca
|
|
142
142
|
executables: []
|
|
@@ -162,7 +162,7 @@ files:
|
|
|
162
162
|
- lib/mangadex/api/context.rb
|
|
163
163
|
- lib/mangadex/api/response.rb
|
|
164
164
|
- lib/mangadex/api/user.rb
|
|
165
|
-
- lib/mangadex/api/
|
|
165
|
+
- lib/mangadex/api/version_checker.rb
|
|
166
166
|
- lib/mangadex/artist.rb
|
|
167
167
|
- lib/mangadex/auth.rb
|
|
168
168
|
- lib/mangadex/author.rb
|
|
@@ -221,7 +221,7 @@ homepage: https://github.com/thedrummeraki/mangadex
|
|
|
221
221
|
licenses:
|
|
222
222
|
- MIT
|
|
223
223
|
metadata: {}
|
|
224
|
-
post_install_message:
|
|
224
|
+
post_install_message:
|
|
225
225
|
rdoc_options: []
|
|
226
226
|
require_paths:
|
|
227
227
|
- lib
|
|
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
237
237
|
version: '0'
|
|
238
238
|
requirements: []
|
|
239
239
|
rubygems_version: 3.2.15
|
|
240
|
-
signing_key:
|
|
240
|
+
signing_key:
|
|
241
241
|
specification_version: 4
|
|
242
242
|
summary: Your next favourite Ruby gem for interacting with Mangadex.org
|
|
243
243
|
test_files: []
|
data/lib/mangadex/api/version.rb
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# typed: true
|
|
2
|
-
require "psych"
|
|
3
|
-
|
|
4
|
-
module Mangadex
|
|
5
|
-
module Api
|
|
6
|
-
VERSION = -> do
|
|
7
|
-
version = Psych.load(
|
|
8
|
-
RestClient.get(
|
|
9
|
-
'https://api.mangadex.org/api.yaml',
|
|
10
|
-
).body,
|
|
11
|
-
).dig('info', 'version')
|
|
12
|
-
|
|
13
|
-
if version != Mangadex::VERSION
|
|
14
|
-
warn(
|
|
15
|
-
"[Warning] This gem is compatible with #{Mangadex::VERSION} but it looks like Mangadex is at #{version}",
|
|
16
|
-
"[Warning] Check out #{Mangadex::Internal::Request::BASE_URI} for more information.",
|
|
17
|
-
)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
version
|
|
21
|
-
end.call
|
|
22
|
-
end
|
|
23
|
-
end
|