Class: Mangadex::Manga

Inherits:
MangadexObject show all
Defined in:
lib/mangadex/manga.rb

Instance Attribute Summary

Attributes included from Internal::WithAttributes

#attributes, #id, #related_type, #relationships, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MangadexObject

#eq?, #hash, #initialize, #inspect

Methods included from Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Constructor Details

This class inherits a constructor from Mangadex::MangadexObject

Class Method Details

.all_reading_status(status = nil) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/mangadex/manga.rb', line 137

def self.all_reading_status(status = nil)
  args = { status: status } if status.present?

  Mangadex::Internal::Request.get(
    '/manga/status',
    Mangadex::Internal::Definition.validate(args, {
      status: {
        accepts: %w(reading on_hold dropped plan_to_read re_reading completed),
        converts: :to_s,
      },
    })
  )
end

.attributes_to_inspectObject



205
206
207
# File 'lib/mangadex/manga.rb', line 205

def self.attributes_to_inspect
  [:id, :type, :title, :content_rating, :original_language, :year]
end

.create(**args) ⇒ Object



201
202
203
# File 'lib/mangadex/manga.rb', line 201

def self.create(**args)
  Mangadex::Internal::Request.post('/manga', payload: args)
end

.delete(id) ⇒ Object



193
194
195
196
197
198
199
# File 'lib/mangadex/manga.rb', line 193

def self.delete(id)
  Mangadex::Internal::Definition.must(id)

  Mangadex::Internal::Request.delete(
    '/manga/%{id}' % {id: id},
  )
end

.feed(id, **args) ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/mangadex/manga.rb', line 104

def self.feed(id, **args)
  Mangadex::Internal::Definition.must(id)

  Mangadex::Internal::Request.get(
    '/manga/%{id}/feed' % {id: id},
    Mangadex::Internal::Definition.chapter_list(args),
    content_rating: true,
  )
end

.follow(id) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/mangadex/manga.rb', line 95

def self.follow(id)
  Mangadex::Internal::Definition.must(id)

  Mangadex::Internal::Request.post(
    '/manga/%{id}/follow' % {id: id},
  )
end

.list(**args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mangadex/manga.rb', line 29

def self.list(**args)
  Mangadex::Internal::Request.get(
    '/manga',
    Mangadex::Internal::Definition.validate(args, {
      limit: { accepts: Integer, converts: :to_i },
      offset: { accepts: Integer, converts: :to_i },
      title: { accepts: String },
      author_or_artist: { accepts: String },
      authors: { accepts: [String], converts: :to_a },
      artists: { accepts: [String], converts: :to_a },
      year: { accepts: Integer },
      included_tags: { accepts: [String], converts: :to_a },
      included_tags_mode: { accepts: %w(OR AND) },
      excluded_tags: { accepts: [String], converts: :to_a },
      excluded_tags_mode: { accepts: %w(OR AND) },
      status: { accepts: %w(ongoing completed hiatus cancelled), converts: :to_a },
      original_language: { accepts: [String], converts: :to_a },
      excluded_original_language: { accepts: [String], converts: :to_a },
      available_translated_language: { accepts: [String], 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 },
      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 },
      has_available_chapters: { accepts: ['0', '1', 'true', 'false'] },
      group: { accepts: String },
    }),
    content_rating: true,
  )
end

.random(**args) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/mangadex/manga.rb', line 115

def self.random(**args)
  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], converts: :to_a },
      included_tags_mode: { accepts: %w(OR AND) },
      excluded_tags: { accepts: [String], converts: :to_a },
      excluded_tags_mode: { accepts: %w(OR AND) },
    })
  )
end

.read_markers(id, grouped: false) ⇒ Object



176
177
178
179
180
181
182
# File 'lib/mangadex/manga.rb', line 176

def self.read_markers(id, grouped: false)
  Mangadex::Internal::Request.get(
    '/manga/read',
    { ids: Array(id), grouped: grouped },
    auth: true,
  )
end

.reading_status(id) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/mangadex/manga.rb', line 152

def self.reading_status(id)
  Mangadex::Internal::Definition.must(id)

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

.tag_listObject



130
131
132
133
134
# File 'lib/mangadex/manga.rb', line 130

def self.tag_list
  Mangadex::Internal::Request.get(
    '/manga/tag'
  )
end

.unfollow(id) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/mangadex/manga.rb', line 86

def self.unfollow(id)
  Mangadex::Internal::Definition.must(id)

  Mangadex::Internal::Request.delete(
    '/manga/%{id}/follow' % {id: id},
  )
end

.update(id, **args) ⇒ Object Also known as: edit



186
187
188
189
190
# File 'lib/mangadex/manga.rb', line 186

def self.update(id, **args)
  Mangadex::Internal::Definition.must(id)

  Mangadex::Internal::Request.put('/manga/%{id}' % {id: id}, payload: args)
end

.update_reading_status(id, status) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/mangadex/manga.rb', line 161

def self.update_reading_status(id, status)
  Mangadex::Internal::Definition.must(id)

  Mangadex::Internal::Request.post(
    '/manga/%{id}/status' % {id: id},
    payload: Mangadex::Internal::Definition.validate({status: status}, {
      status: {
        accepts: %w(reading on_hold dropped plan_to_read re_reading completed),
        required: true,
      },
    })
  )
end

.view(id, **args) ⇒ Object Also known as: get



74
75
76
77
78
79
80
81
82
83
# File 'lib/mangadex/manga.rb', line 74

def self.view(id, **args)
  Mangadex::Internal::Definition.must(id)

  Mangadex::Internal::Request.get(
    '/manga/%{id}' % {id: id},
    Mangadex::Internal::Definition.validate(args, {
      includes: { accepts: Array, converts: :to_a },
    })
  )
end

.volumes_and_chapters(id, **args) ⇒ Object Also known as: aggregate



63
64
65
66
67
68
69
70
71
# File 'lib/mangadex/manga.rb', line 63

def self.volumes_and_chapters(id, **args)
  Mangadex::Internal::Request.get(
    '/manga/%{id}/aggregate' % {id: id},
    Mangadex::Internal::Definition.validate(args, {
      translated_language: { accepts: Array },
      groups: { accepts: Array },
    }),
  )
end

Instance Method Details

#chapters(**args) ⇒ Object



223
224
225
226
# File 'lib/mangadex/manga.rb', line 223

def chapters(**args)
  chapter_args = args.merge({manga: id})
  Chapter.list(**chapter_args)
end

#comments_infoObject Also known as: comments



238
239
240
# File 'lib/mangadex/manga.rb', line 238

def comments_info
  statistics.comments
end

#content_ratingObject



216
217
218
219
220
# File 'lib/mangadex/manga.rb', line 216

def content_rating
  return unless attributes&.content_rating.present?

  ContentRating.new(attributes.content_rating)
end

#has_comments?Boolean

Returns:

  • (Boolean)


229
230
231
# File 'lib/mangadex/manga.rb', line 229

def has_comments?
  !comments_info.nil? && comments_info.repliesCount > 0
end

#statisticsObject Also known as: stats



233
234
235
# File 'lib/mangadex/manga.rb', line 233

def statistics
  @statistics ||= Mangadex::Statistic.get(id).data
end