Skip to content

Commit

Permalink
Merge pull request #46 from thedrummeraki/bump-to-latest-version-5.7.5
Browse files Browse the repository at this point in the history
Bump to latest version 5.7.5
  • Loading branch information
thedrummeraki authored Nov 3, 2022
2 parents e99f409 + 4fead2c commit d3f5260
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 7 deletions.
47 changes: 47 additions & 0 deletions lib/mangadex/chapter_read_marker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module Mangadex
class ChapterReadMarker
extend T::Sig

sig { params(id: String).returns(T::Api::GenericResponse) }
def self.get(id)
Mangadex::Internal::Definition.must(id)

Mangadex::Internal::Request.get(
'/manga/{id}/read' % {id: id}
)
end

sig { params(id: String, args: T::Api::Arguments).returns(T::Api::GenericResponse) }
def self.create(id, **args)
Mangadex::Internal::Definition.must(id)

Mangadex::Internal::Request.post(
'/manga/{id}/read' % {id: id},
payload: Mangadex::Internal::Definition.validate(args, {
update_history: { accepts: [true, false] }
})
)
end

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 },
grouped: { accepts: [true, false] },
})
)
end

sig { returns(T::Api::GenericResponse) }
def self.user_list
Mangadex::Internal::Request.get(
'/user/history',
auth: true,
)
end
end
end
8 changes: 7 additions & 1 deletion lib/mangadex/internal/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ def validate_accepts!

class << self
def converts(key=nil)
procs = { to_a: -> ( x ) { Array(x) } }
procs = {
to_a: -> ( x ) { Array(x) },
to_i: -> ( x ) { Integer(x.to_s, 10) if x },
}
return procs if key.nil?

procs[key]
Expand Down Expand Up @@ -128,6 +131,9 @@ def chapter_list(args)
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) },
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) },
},
)
end
Expand Down
10 changes: 8 additions & 2 deletions lib/mangadex/manga.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ def self.list(**args)
limit: { accepts: Integer },
offset: { accepts: Integer },
title: { accepts: String },
author_or_artist: { accepts: String },
authors: { accepts: [String] },
artists: { accepts: [String] },
year: { accepts: Integer },
included_tags: { accepts: [String] },
included_tags_mode: { accepts: %w(OR AND), converts: to_a },
included_tags_mode: { accepts: %w(OR AND) },
excluded_tags: { accepts: [String] },
excluded_tags_mode: { accepts: %w(OR AND), converts: to_a },
excluded_tags_mode: { accepts: %w(OR AND) },
status: { accepts: %w(ongoing completed hiatus cancelled), converts: to_a },
original_language: { accepts: [String] },
excluded_original_language: { accepts: [String] },
Expand Down Expand Up @@ -116,11 +117,16 @@ 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 },
included_tags: { accepts: [String] },
included_tags_mode: { accepts: %w(OR AND) },
excluded_tags: { accepts: [String] },
excluded_tags_mode: { accepts: %w(OR AND) },
})
)
end
Expand Down
42 changes: 42 additions & 0 deletions lib/mangadex/report.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Mangadex
class Report < MangadexObject
has_attributes \
:details,
:object_id,
:status,
:created_at

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 },
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 },
}),
auth: true,
)
end

sig { params(args: T::Api::Arguments).returns(T::Api::GenericResponse) }
def create(**args)
Mangadex::Internal::Request.post(
'/report',
payload: Mangadex::Internal::Definition.validate(args, {
category: { accepts: %w(manga chapter scanlation_group user), required: true },
reason: { accepts: String, required: true },
object_id: { accepts: String, required: true },
details: { accepts: String },
}),
)
end
end
end
5 changes: 4 additions & 1 deletion lib/mangadex/report_reason.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ReportReason < MangadexObject
class << self
def list(category)
args = Mangadex::Internal::Definition.validate({category: category}, {
category: { accepts: %w(manga chapter scanlation_group user), required: true },
category: { accepts: %w(manga chapter scanlation_group user author), required: true },
})

Mangadex::Internal::Request.get(
Expand All @@ -19,6 +19,9 @@ def list(category)
end

def create(**args)
# TODO: create a "deprecated" log function
puts("[DEPRECATED] Use Mangadex::Report.create(...) instead.")

Mangadex::Internal::Request.post(
'/report',
payload: Mangadex::Internal::Definition.validate(args, {
Expand Down
1 change: 1 addition & 0 deletions lib/mangadex/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require_relative "tag"
require_relative "scanlation_group"
require_relative "report_reason"
require_relative "report"
require_relative "rating"
require_relative "statistic"

Expand Down
6 changes: 3 additions & 3 deletions lib/mangadex/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
module Mangadex
module Version
MAJOR = "5"
MINOR = "6"
TINY = "0"
PATCH = "1"
MINOR = "7"
TINY = "5"
PATCH = nil

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

0 comments on commit d3f5260

Please sign in to comment.