Skip to content

Commit

Permalink
Merge pull request #53 from thedrummeraki/use-symbol-converts
Browse files Browse the repository at this point in the history
Make use of symbol converts
  • Loading branch information
thedrummeraki authored Nov 7, 2022
2 parents 24b2784 + 2910949 commit 13ed292
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
mangadex (5.7.5.1)
mangadex (5.7.5.2)
psych (~> 4.0.1)
rest-client (~> 2.1)
sorbet-runtime
Expand Down
4 changes: 2 additions & 2 deletions lib/mangadex/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def self.list(**args)
Mangadex::Internal::Request.get(
'/author',
Mangadex::Internal::Definition.validate(args, {
limit: { accepts: Integer },
offset: { accepts: Integer },
limit: { accepts: Integer, converts: :to_i },
offset: { accepts: Integer, converts: :to_i },
ids: { accepts: [String] },
name: { accepts: String },
order: { accepts: Hash },
Expand Down
4 changes: 1 addition & 3 deletions lib/mangadex/chapter_read_marker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ def self.create(id, **args)

sig { sig(args: T::Api::Arguments).returns(T::Api::GenericResponse) }
def self.list(**args)
to_a = Mangadex::Internal::Definition.converts(:to_a)

Mangadex::Internal::Request.get(
'/manga/list',
Mangadex::Internal::Definition.validate(args, {
ids: { accepts: [String], converts: to_a, required: true },
ids: { accepts: [String], converts: :to_a, required: true },
grouped: { accepts: [true, false] },
})
)
Expand Down
4 changes: 2 additions & 2 deletions lib/mangadex/cover_art.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def self.list(**args)
Mangadex::Internal::Request.get(
'/cover',
Mangadex::Internal::Definition.validate(args, {
limit: { accepts: Integer },
offset: { accepts: Integer },
limit: { accepts: Integer, converts: :to_i },
offset: { accepts: Integer, converts: :to_i },
manga: { accepts: [String] },
ids: { accepts: [String] },
uploaders: { accepts: [String] },
Expand Down
8 changes: 4 additions & 4 deletions lib/mangadex/custom_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def self.list(**args)
Mangadex::Internal::Request.get(
'/user/list',
Mangadex::Internal::Definition.validate(args, {
limit: { accepts: Integer },
offset: { accepts: Integer },
limit: { accepts: Integer, converts: :to_i },
offset: { accepts: Integer, converts: :to_i },
}),
)
end
Expand All @@ -112,8 +112,8 @@ def self.user_list(user_id, **args)
Mangadex::Internal::Request.get(
'/user/%{id}/list' % {id: user_id},
Mangadex::Internal::Definition.validate(args, {
limit: { accepts: Integer },
offset: { accepts: Integer },
limit: { accepts: Integer, converts: :to_i },
offset: { accepts: Integer, converts: :to_i },
}),
)
end
Expand Down
12 changes: 6 additions & 6 deletions lib/mangadex/internal/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ def chapter_list(args)
validate(
args,
{
limit: { accepts: Integer },
offset: { accepts: Integer },
limit: { accepts: Integer, converts: :to_i },
offset: { accepts: Integer, converts: :to_i },
ids: { accepts: [String] },
title: { accepts: String },
manga: { accepts: String },
groups: { accepts: [String] },
uploader: { accepts: [String], converts: converts(:to_a) },
chapter: { accepts: [String], converts: converts(:to_a) },
translated_language: { accepts: [String], converts: converts(:to_a) },
uploader: { accepts: [String], converts: :to_a },
chapter: { accepts: [String], converts: :to_a },
translated_language: { accepts: [String], converts: :to_a },
original_language: { accepts: [String] },
excluded_original_language: { accepts: [String] },
content_rating: Definitions::ContentRating,
Expand All @@ -134,7 +134,7 @@ def chapter_list(args)
updated_at_since: { accepts: %r{^\d{4}-[0-1]\d-([0-2]\d|3[0-1])T([0-1]\d|2[0-3]):[0-5]\d:[0-5]\d$} },
publish_at_since: { accepts: %r{^\d{4}-[0-1]\d-([0-2]\d|3[0-1])T([0-1]\d|2[0-3]):[0-5]\d:[0-5]\d$} },
order: { accepts: Hash },
includes: { accepts: [String], converts: converts(:to_a) },
includes: { accepts: [String], converts: :to_a },
include_empty_pages: { accepts: [0, 1], converts: converts(:to_i) },
include_future_publish_at: { accepts: [0, 1], converts: converts(:to_i) },
include_external_url: { accepts: [0, 1], converts: converts(:to_i) },
Expand Down
19 changes: 7 additions & 12 deletions lib/mangadex/manga.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ class Manga < MangadexObject

sig { params(args: T::Api::Arguments).returns(T::Api::MangaResponse) }
def self.list(**args)
to_a = Mangadex::Internal::Definition.converts(:to_a)

Mangadex::Internal::Request.get(
'/manga',
Mangadex::Internal::Definition.validate(args, {
limit: { accepts: Integer, converts: :to_i },
offset: { accepts: Integer },
offset: { accepts: Integer, converts: :to_i },
title: { accepts: String },
author_or_artist: { accepts: String },
authors: { accepts: [String] },
Expand All @@ -43,17 +41,17 @@ def self.list(**args)
included_tags_mode: { accepts: %w(OR AND) },
excluded_tags: { accepts: [String] },
excluded_tags_mode: { accepts: %w(OR AND) },
status: { accepts: %w(ongoing completed hiatus cancelled), converts: to_a },
status: { accepts: %w(ongoing completed hiatus cancelled), converts: :to_a },
original_language: { accepts: [String] },
excluded_original_language: { accepts: [String] },
available_translated_language: { accepts: [String] },
publication_demographic: { accepts: %w(shounen shoujo josei seinen none), converts: to_a },
publication_demographic: { accepts: %w(shounen shoujo josei seinen none), converts: :to_a },
ids: { accepts: Array },
content_rating: { accepts: %w(safe suggestive erotica pornographic), converts: to_a },
content_rating: { accepts: %w(safe suggestive erotica pornographic), converts: :to_a },
created_at_since: { accepts: %r{^\d{4}-[0-1]\d-([0-2]\d|3[0-1])T([0-1]\d|2[0-3]):[0-5]\d:[0-5]\d$} },
updated_at_since: { accepts: %r{^\d{4}-[0-1]\d-([0-2]\d|3[0-1])T([0-1]\d|2[0-3]):[0-5]\d:[0-5]\d$} },
order: { accepts: Hash },
includes: { accepts: Array, converts: to_a },
includes: { accepts: Array, converts: :to_a },
has_available_chapters: { accepts: ['0', '1', 'true', 'false'] },
group: { accepts: String },
}),
Expand All @@ -74,13 +72,12 @@ def self.volumes_and_chapters(id, **args)

sig { params(id: String, args: T::Api::Arguments).returns(T::Api::MangaResponse) }
def self.view(id, **args)
to_a = Mangadex::Internal::Definition.converts(:to_a)
Mangadex::Internal::Definition.must(id)

Mangadex::Internal::Request.get(
'/manga/%{id}' % {id: id},
Mangadex::Internal::Definition.validate(args, {
includes: { accepts: Array, converts: to_a },
includes: { accepts: Array, converts: :to_a },
})
)
end
Expand Down Expand Up @@ -116,13 +113,11 @@ def self.feed(id, **args)

sig { params(args: T::Api::Arguments).returns(T::Api::MangaResponse) }
def self.random(**args)
to_a = Mangadex::Internal::Definition.converts(:to_a)

Mangadex::Internal::Request.get(
'/manga/random',
Mangadex::Internal::Definition.validate(args, {
includes: { accepts: Array },
content_rating: { accepts: %w(safe suggestive erotica pornographic), converts: to_a },
content_rating: { accepts: %w(safe suggestive erotica pornographic), converts: :to_a },
included_tags: { accepts: [String] },
included_tags_mode: { accepts: %w(OR AND) },
excluded_tags: { accepts: [String] },
Expand Down
8 changes: 3 additions & 5 deletions lib/mangadex/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ class Report < MangadexObject

sig { params(args: T::Api::Arguments).returns(Mangadex::Api::Response[Report]) }
def self.list(**args)
to_a = Mangadex::Internal::Definition.converts(:to_a)

Mangadex::Internal::Request.get(
'/report',
Mangadex::Internal::Definition.validate(args, {
limit: { accepts: Integer },
offset: { accepts: Integer },
limit: { accepts: Integer, converts: :to_i },
offset: { accepts: Integer, converts: :to_i },
category: { accepts: %w(manga chapter scanlation_group user author) },
reason_id: { accepts: String },
object_id: { accepts: String },
status: { accepts: %w(waiting accepted refused autoresolved) },
order: { accepts: Hash },
includes: { accepts: Array, converts: to_a },
includes: { accepts: Array, converts: :to_a },
}),
auth: true,
)
Expand Down
4 changes: 2 additions & 2 deletions lib/mangadex/scanlation_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def list(**args)
Mangadex::Internal::Request.get(
'/group',
Mangadex::Internal::Definition.validate(args, {
limit: { accepts: Integer },
offset: { accepts: Integer },
limit: { accepts: Integer, converts: :to_i },
offset: { accepts: Integer, converts: :to_i },
ids: { accepts: [String] },
name: { accepts: String },
includes: { accepts: [String] },
Expand Down
4 changes: 1 addition & 3 deletions lib/mangadex/statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ def self.get(uuid)

sig { params(args: T::Api::Arguments).returns(T::Api::GenericResponse) }
def self.list(**args)
to_a = Mangadex::Internal::Definition.converts(:to_a)

Mangadex::Internal::Request.get(
'/statistics/manga',
Mangadex::Internal::Definition.validate(args, {
manga: { accepts: [String], converts: to_a },
manga: { accepts: [String], converts: :to_a },
})
)
end
Expand Down
12 changes: 6 additions & 6 deletions lib/mangadex/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def self.list(**args)
Mangadex::Internal::Request.get(
'/user',
Mangadex::Internal::Definition.validate(args, {
limit: { accepts: Integer },
offset: { accepts: Integer },
limit: { accepts: Integer, converts: :to_i },
offset: { accepts: Integer, converts: :to_i },
ids: { accepts: Array },
username: { accepts: String },
order: { accepts: Hash },
Expand Down Expand Up @@ -89,8 +89,8 @@ def self.followed_groups(**args)
Mangadex::Internal::Request.get(
'/user/follows/group',
Mangadex::Internal::Definition.validate(args, {
limit: { accepts: Integer },
offset: { accepts: Integer },
limit: { accepts: Integer, converts: :to_i },
offset: { accepts: Integer, converts: :to_i },
includes: { accepts: Array },
}),
auth: true,
Expand All @@ -117,8 +117,8 @@ def self.followed_users(**args)
Mangadex::Internal::Request.get(
'/user/follows/user',
Mangadex::Internal::Definition.validate(args, {
limit: { accepts: Integer },
offset: { accepts: Integer },
limit: { accepts: Integer, converts: :to_i },
offset: { accepts: Integer, converts: :to_i },
}),
auth: true,
)
Expand Down
2 changes: 1 addition & 1 deletion lib/mangadex/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Version
MAJOR = "5"
MINOR = "7"
TINY = "5"
PATCH = "1"
PATCH = "2"

STRING = [MAJOR, MINOR, TINY].compact.join('.')
FULL = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
Expand Down

0 comments on commit 13ed292

Please sign in to comment.