mangadex 5.3.0

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.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +7 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +6 -0
  8. data/Gemfile.lock +81 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +42 -0
  11. data/Rakefile +6 -0
  12. data/bin/console +23 -0
  13. data/bin/setup +8 -0
  14. data/lib/extensions.rb +12 -0
  15. data/lib/mangadex/README.md +93 -0
  16. data/lib/mangadex/api/context.rb +53 -0
  17. data/lib/mangadex/api/response.rb +104 -0
  18. data/lib/mangadex/api/user.rb +48 -0
  19. data/lib/mangadex/api/version.rb +21 -0
  20. data/lib/mangadex/api.rb +5 -0
  21. data/lib/mangadex/artist.rb +13 -0
  22. data/lib/mangadex/auth.rb +56 -0
  23. data/lib/mangadex/author.rb +101 -0
  24. data/lib/mangadex/chapter.rb +105 -0
  25. data/lib/mangadex/content_rating.rb +75 -0
  26. data/lib/mangadex/cover_art.rb +93 -0
  27. data/lib/mangadex/custom_list.rb +127 -0
  28. data/lib/mangadex/internal/definition.rb +162 -0
  29. data/lib/mangadex/internal/request.rb +121 -0
  30. data/lib/mangadex/internal/with_attributes.rb +120 -0
  31. data/lib/mangadex/internal.rb +3 -0
  32. data/lib/mangadex/manga.rb +188 -0
  33. data/lib/mangadex/mangadex_object.rb +62 -0
  34. data/lib/mangadex/relationship.rb +46 -0
  35. data/lib/mangadex/report_reason.rb +39 -0
  36. data/lib/mangadex/scanlation_group.rb +97 -0
  37. data/lib/mangadex/sorbet.rb +42 -0
  38. data/lib/mangadex/tag.rb +10 -0
  39. data/lib/mangadex/types.rb +24 -0
  40. data/lib/mangadex/upload.rb +78 -0
  41. data/lib/mangadex/user.rb +103 -0
  42. data/lib/mangadex/version.rb +4 -0
  43. data/lib/mangadex.rb +35 -0
  44. data/mangadex.gemspec +35 -0
  45. data/sorbet/config +3 -0
  46. data/sorbet/rbi/gems/activesupport.rbi +1267 -0
  47. data/sorbet/rbi/gems/coderay.rbi +285 -0
  48. data/sorbet/rbi/gems/concurrent-ruby.rbi +1662 -0
  49. data/sorbet/rbi/gems/domain_name.rbi +52 -0
  50. data/sorbet/rbi/gems/http-accept.rbi +101 -0
  51. data/sorbet/rbi/gems/http-cookie.rbi +119 -0
  52. data/sorbet/rbi/gems/i18n.rbi +133 -0
  53. data/sorbet/rbi/gems/method_source.rbi +64 -0
  54. data/sorbet/rbi/gems/mime-types-data.rbi +17 -0
  55. data/sorbet/rbi/gems/mime-types.rbi +218 -0
  56. data/sorbet/rbi/gems/netrc.rbi +51 -0
  57. data/sorbet/rbi/gems/pry.rbi +1898 -0
  58. data/sorbet/rbi/gems/psych.rbi +471 -0
  59. data/sorbet/rbi/gems/rake.rbi +660 -0
  60. data/sorbet/rbi/gems/rest-client.rbi +454 -0
  61. data/sorbet/rbi/gems/rspec-core.rbi +1939 -0
  62. data/sorbet/rbi/gems/rspec-expectations.rbi +1150 -0
  63. data/sorbet/rbi/gems/rspec-mocks.rbi +1100 -0
  64. data/sorbet/rbi/gems/rspec-support.rbi +280 -0
  65. data/sorbet/rbi/gems/rspec.rbi +15 -0
  66. data/sorbet/rbi/gems/tzinfo.rbi +586 -0
  67. data/sorbet/rbi/gems/unf.rbi +19 -0
  68. data/sorbet/rbi/hidden-definitions/errors.txt +3942 -0
  69. data/sorbet/rbi/hidden-definitions/hidden.rbi +8210 -0
  70. data/sorbet/rbi/sorbet-typed/lib/activesupport/>=6/activesupport.rbi +37 -0
  71. data/sorbet/rbi/sorbet-typed/lib/activesupport/all/activesupport.rbi +1850 -0
  72. data/sorbet/rbi/sorbet-typed/lib/minitest/all/minitest.rbi +108 -0
  73. data/sorbet/rbi/sorbet-typed/lib/rake/all/rake.rbi +645 -0
  74. data/sorbet/rbi/sorbet-typed/lib/rspec-core/all/rspec-core.rbi +1891 -0
  75. data/sorbet/rbi/todo.rbi +7 -0
  76. metadata +243 -0
@@ -0,0 +1,39 @@
1
+ # typed: true
2
+ module Mangadex
3
+ class ReportReason < MangadexObject
4
+ has_attributes \
5
+ :reason,
6
+ :details_required,
7
+ :category,
8
+ :version
9
+
10
+ class << self
11
+ def list(category)
12
+ args = Mangadex::Internal::Definition.validate({category: category}, {
13
+ category: { accepts: %w(manga chapter scanlation_group user), required: true },
14
+ })
15
+
16
+ Mangadex::Internal::Request.get(
17
+ '/report/reasons/%{category}' % args,
18
+ )
19
+ end
20
+
21
+ def create(**args)
22
+ Mangadex::Internal::Request.post(
23
+ '/report',
24
+ payload: Mangadex::Internal::Definition.validate(args, {
25
+ category: { accepts: %w(manga chapter scanlation_group user), required: true },
26
+ reason: { accepts: String, required: true },
27
+ object_id: { accepts: String, required: true },
28
+ details: { accepts: String },
29
+ }),
30
+ )
31
+ end
32
+ end
33
+
34
+ def self.attributes_to_inspect
35
+ self.attributes
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,97 @@
1
+ # typed: false
2
+ module Mangadex
3
+ class ScanlationGroup < MangadexObject
4
+ has_attributes \
5
+ :name,
6
+ :website,
7
+ :irc_channel,
8
+ :irc_server,
9
+ :discord,
10
+ :contact_email,
11
+ :description,
12
+ :locked,
13
+ :official,
14
+ :verified,
15
+ :version,
16
+ :created_at,
17
+ :updated_at
18
+
19
+ class << self
20
+ def list(**args)
21
+ Mangadex::Internal::Request.get(
22
+ '/group',
23
+ Mangadex::Internal::Definition.validate(args, {
24
+ limit: { accepts: Integer },
25
+ offset: { accepts: Integer },
26
+ ids: { accepts: [String] },
27
+ name: { accepts: String },
28
+ includes: { accepts: [String] },
29
+ }),
30
+ )
31
+ end
32
+
33
+ def create(**args)
34
+ Mangadex::Internal::Request.post(
35
+ '/group',
36
+ payload: Mangadex::Internal::Definition.validate(args, {
37
+ name: { accepts: String, required: true },
38
+ website: { accepts: String },
39
+ irc_server: { accepts: String },
40
+ irc_channel: { accepts: String },
41
+ discord: { accepts: String },
42
+ contact_email: { accepts: String },
43
+ description: { accepts: String },
44
+ }),
45
+ )
46
+ end
47
+
48
+ def view(id)
49
+ Mangadex::Internal::Request.get(
50
+ '/group/%{id}' % {id: id},
51
+ Mangadex::Internal::Definition.validate(args, {
52
+ includes: { accepts: [String] },
53
+ }),
54
+ )
55
+ end
56
+
57
+ def update(id, **args)
58
+ Mangadex::Internal::Request.put(
59
+ '/group/%{id}' % {id: id},
60
+ payload: Mangadex::Internal::Definition.validate(args, {
61
+ name: { accepts: String },
62
+ website: { accepts: String },
63
+ irc_server: { accepts: String },
64
+ irc_channel: { accepts: String },
65
+ discord: { accepts: String },
66
+ contact_email: { accepts: String },
67
+ description: { accepts: String },
68
+ locked: { accepts: [true, false] },
69
+ version: { accepts: Integer, required: true },
70
+ }),
71
+ )
72
+ end
73
+
74
+ def delete(id)
75
+ Mangadex::Internal::Request.delete(
76
+ '/group/%{id}' % {id: id},
77
+ )
78
+ end
79
+
80
+ def follow(id)
81
+ Mangadex::Internal::Request.post(
82
+ '/group/%{id}/follow' % {id: id},
83
+ )
84
+ end
85
+
86
+ def unfollow(id)
87
+ Mangadex::Internal::Request.delete(
88
+ '/group/%{id}/follow' % {id: id},
89
+ )
90
+ end
91
+ end
92
+
93
+ def self.inspect_attributes
94
+ self.attributes - [:version, :created_at, :updated_at]
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,42 @@
1
+ # typed: false
2
+
3
+ # These are custom alias Sorbet types
4
+
5
+ module T
6
+ module Api
7
+ Text = T.type_alias { T.any(String, Symbol) }
8
+
9
+ Arguments = T.type_alias do
10
+ T.any(
11
+ Text,
12
+ T::Array[Text],
13
+ Integer,
14
+ T::Hash[Text, Text],
15
+ )
16
+ end
17
+ MangaResponse = T.type_alias do
18
+ T.any(
19
+ Mangadex::Api::Response[Mangadex::Manga],
20
+ Mangadex::Api::Response[T::Array[Mangadex::Manga]]
21
+ )
22
+ end
23
+ ChapterResponse = T.type_alias do
24
+ T.any(
25
+ Mangadex::Api::Response[Mangadex::Chapter],
26
+ Mangadex::Api::Response[T::Array[Mangadex::Chapter]]
27
+ )
28
+ end
29
+ GenericResponse = T.type_alias do
30
+ T.any(
31
+ ::Hash,
32
+ Mangadex::Api::Response,
33
+ )
34
+ end
35
+ ContentRating = T.type_alias do
36
+ T.any(
37
+ String,
38
+ ::Mangadex::ContentRating,
39
+ )
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,10 @@
1
+ # typed: true
2
+ module Mangadex
3
+ class Tag < MangadexObject
4
+ has_attributes :name, :description, :group, :version
5
+
6
+ def self.attributes_to_inspect
7
+ %i(name)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ # typed: strict
2
+ # Utilitary classes
3
+ require_relative "sorbet"
4
+ require_relative "content_rating"
5
+ require_relative "mangadex_object"
6
+
7
+ # Authorization
8
+ require_relative "auth"
9
+
10
+ # Mangadex objects
11
+ require_relative "author"
12
+ require_relative "artist"
13
+ require_relative "chapter"
14
+ require_relative "cover_art"
15
+ require_relative "custom_list"
16
+ require_relative "manga"
17
+ require_relative "upload"
18
+ require_relative "user"
19
+ require_relative "tag"
20
+ require_relative "scanlation_group"
21
+ require_relative "report_reason"
22
+
23
+ # Relationship
24
+ require_relative "relationship"
@@ -0,0 +1,78 @@
1
+ # typed: false
2
+ module Mangadex
3
+ class Upload < MangadexObject
4
+ has_attributes \
5
+ :is_committed,
6
+ :is_processed,
7
+ :is_deleted,
8
+ :version,
9
+ :created_at,
10
+ :updated_at
11
+
12
+ class << self
13
+ def current
14
+ Mangadex::Internal::Request.get(
15
+ '/upload',
16
+ )
17
+ end
18
+
19
+ def start(**args)
20
+ Mangadex::Internal::Request.post(
21
+ '/upload/begin',
22
+ payload: Mangadex::Internal::Definition.validate(args, {
23
+ groups: { accepts: [String], required: true },
24
+ manga: { accepts: String, required: true },
25
+ }),
26
+ )
27
+ end
28
+ alias_method :begin, :start
29
+
30
+ def upload_images(upload_session_id)
31
+ Mangadex::Internal::Request.post(
32
+ '/upload/%{upload_session_id}' % {upload_session_id: upload_session_id},
33
+ payload: Mangadex::Internal::Definition.validate(args, {
34
+ file: { accepts: String },
35
+ }),
36
+ )
37
+ end
38
+
39
+ def abandon(upload_session_id)
40
+ Mangadex::Internal::Request.delete(
41
+ '/upload/%{upload_session_id}' % {upload_session_id: upload_session_id},
42
+ )
43
+ end
44
+ alias_method :stop, :abandon
45
+
46
+ def commit(upload_session_id, **args)
47
+ Mangadex::Internal::Request.post(
48
+ '/upload/%{upload_session_id}/commit' % {upload_session_id: upload_session_id},
49
+ payload: Mangadex::Internal::Definition.validate(args, {
50
+ chapter_draft: { accepts: Hash }, # todo enforce chapter_draft content?
51
+ page_order: { accepts: [String] },
52
+ }),
53
+ )
54
+ end
55
+
56
+ def delete_uploaded_image(upload_session_id, upload_session_file_id)
57
+ Mangadex::Internal::Request.delete(
58
+ '/upload/%{upload_session_id}/%{upload_session_file_id}' % {
59
+ upload_session_id: upload_session_id,
60
+ upload_session_file_id: upload_session_file_id,
61
+ },
62
+ )
63
+ end
64
+
65
+ def delete_uploaded_images(upload_session_id, upload_session_file_ids)
66
+ Mangadex::Internal::Request.delete(
67
+ '/upload/%{upload_session_id}' % {upload_session_id: upload_session_id},
68
+ payload: Array(upload_session_file_id),
69
+ )
70
+ end
71
+ end
72
+
73
+ def self.inspect_attributes
74
+ [:is_committed, :is_processed, :is_deleted]
75
+ end
76
+ end
77
+ end
78
+
@@ -0,0 +1,103 @@
1
+ # typed: false
2
+ module Mangadex
3
+ class User < MangadexObject
4
+ has_attributes \
5
+ :username,
6
+ :roles,
7
+ :version
8
+
9
+ sig { params(args: T::Api::Arguments).returns(Mangadex::Api::Response[Mangadex::Chapter]) }
10
+ def self.feed(**args)
11
+ Mangadex::Internal::Request.get(
12
+ '/user/follows/manga/feed',
13
+ Mangadex::Internal::Definition.chapter_list(args),
14
+ auth: true,
15
+ )
16
+ end
17
+
18
+ sig { params(args: T::Api::Arguments).returns(Mangadex::Api::Response[Mangadex::ScanlationGroup]) }
19
+ def self.followed_groups(**args)
20
+ Mangadex::Internal::Request.get(
21
+ '/user/follows/group',
22
+ Mangadex::Internal::Definition.validate(args, {
23
+ limit: { accepts: Integer },
24
+ offset: { accepts: Integer },
25
+ includes: { accepts: Array },
26
+ }),
27
+ auth: true,
28
+ )
29
+ end
30
+
31
+ sig { params(id: String).returns(T::Boolean) }
32
+ def self.follows_group(id)
33
+ data = Mangadex::Internal::Request.get(
34
+ '/user/follows/group/%{id}' % {id: id},
35
+ raw: true,
36
+ auth: true,
37
+ )
38
+ JSON.parse(data)['result'] == 'ok'
39
+ rescue JSON::ParserError => error
40
+ warn(error)
41
+ false
42
+ end
43
+
44
+ sig { params(args: T::Api::Arguments).returns(Mangadex::Api::Response[Mangadex::User]) }
45
+ def self.followed_users(**args)
46
+ Mangadex::Internal::Request.get(
47
+ '/user/follows/user',
48
+ Mangadex::Internal::Definition.validate(args, {
49
+ limit: { accepts: Integer },
50
+ offset: { accepts: Integer },
51
+ }),
52
+ auth: true,
53
+ )
54
+ end
55
+
56
+ sig { params(id: String).returns(T::Boolean) }
57
+ def self.follows_user(id)
58
+ return if Mangadex::Api::Context.user.nil?
59
+
60
+ data = Mangadex::Internal::Request.get(
61
+ '/user/follows/user/%{id}' % {id: id},
62
+ raw: true,
63
+ auth: true,
64
+ )
65
+ JSON.parse(data)['result'] == 'ok'
66
+ rescue JSON::ParserError => error
67
+ warn(error)
68
+ false
69
+ end
70
+
71
+ sig { params(args: T::Api::Arguments).returns(Mangadex::Api::Response[Mangadex::Manga]) }
72
+ def self.followed_manga(**args)
73
+ Mangadex::Internal::Request.get(
74
+ '/user/follows/manga',
75
+ Mangadex::Internal::Definition.validate(args, {
76
+ limit: { accepts: Integer },
77
+ offset: { accepts: Integer },
78
+ includes: { accepts: Array },
79
+ }),
80
+ auth: true,
81
+ )
82
+ end
83
+
84
+ sig { params(id: String).returns(T::Boolean) }
85
+ def self.follows_manga(id)
86
+ return if Mangadex::Api::Context.user.nil?
87
+
88
+ data = Mangadex::Internal::Request.get(
89
+ '/user/follows/manga/%{id}' % {id: id},
90
+ raw: true,
91
+ auth: true,
92
+ )
93
+ JSON.parse(data)['result'] == 'ok'
94
+ rescue JSON::ParserError => error
95
+ warn(error)
96
+ false
97
+ end
98
+
99
+ def self.attributes_to_inspect
100
+ [:username, :roles]
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,4 @@
1
+ # typed: strict
2
+ module Mangadex
3
+ VERSION = "5.3.0"
4
+ end
data/lib/mangadex.rb ADDED
@@ -0,0 +1,35 @@
1
+ # typed: strict
2
+ require 'sorbet-runtime'
3
+
4
+ require 'active_support'
5
+ require_relative 'extensions'
6
+
7
+ # The insides of the gem
8
+ require "mangadex/version"
9
+ require "mangadex/internal"
10
+
11
+ # Types that represent all of the resources (ie: objects)
12
+ require "mangadex/types"
13
+
14
+ # API, to interact with Mangadex
15
+ require "mangadex/api"
16
+
17
+ # Namespace for classes and modules for this gem.
18
+ # @since 5.3.0
19
+
20
+ 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
28
+
29
+ class UserNotLoggedIn < Error
30
+ sig { returns(String) }
31
+ def message
32
+ "You are not logged in. Use [Mangadex::Auth.login] to log in."
33
+ end
34
+ end
35
+ end
data/mangadex.gemspec ADDED
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mangadex/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mangadex"
8
+ spec.version = Mangadex::VERSION
9
+ spec.authors = ["Akinyele Cafe-Febrissy"]
10
+ spec.email = ["me@akinyele.ca"]
11
+
12
+ spec.summary = "Your next favourite Ruby gem for interacting with Mangadex.org"
13
+ spec.homepage = "https://github.com/thedrummeraki/mangadex"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "psych", "~> 4.0.1"
26
+ spec.add_dependency "rest-client", "~> 2.1"
27
+ spec.add_dependency "activesupport", "~> 6.1"
28
+ spec.add_dependency "sorbet-runtime"
29
+
30
+ spec.add_development_dependency "bundler", "~> 2.2.19"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "pry"
34
+ spec.add_development_dependency "sorbet"
35
+ end
data/sorbet/config ADDED
@@ -0,0 +1,3 @@
1
+ --dir
2
+ .
3
+ --ignore=/vendor/bundle