Class: Mangadex::CoverArt

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

Instance Attribute Summary

Attributes included from Internal::WithAttributes

#attributes, #id, #relationships, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MangadexObject

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

Constructor Details

This class inherits a constructor from Mangadex::MangadexObject

Class Method Details

.delete(id) ⇒ Object



71
72
73
74
75
# File 'lib/mangadex/cover_art.rb', line 71

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

.edit(id, **args) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/mangadex/cover_art.rb', line 59

def self.edit(id, **args)
  Mangadex::Internal::Request.put(
    '/cover/%{id}' % {id: id},
    Mangadex::Internal::Definition.validate(args, {
      volume: { accepts: String },
      description: { accepts: String },
      version: { accepts: Integer, required: true }
    })
  )
end

.get(id, **args) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/mangadex/cover_art.rb', line 49

def self.get(id, **args)
  Mangadex::Internal::Request.get(
    '/cover/%{id}' % {id: id},
    Mangadex::Internal::Definition.validate(args, {
      includes: { accepts: [String] },
    })
  )
end

.list(**args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mangadex/cover_art.rb', line 15

def self.list(**args)
  Mangadex::Internal::Request.get(
    '/cover',
    Mangadex::Internal::Definition.validate(args, {
      limit: { accepts: Integer },
      offset: { accepts: Integer },
      manga: { accepts: [String] },
      ids: { accepts: [String] },
      uploaders: { accepts: [String] },
      order: { accepts: Hash },
      includes: { accepts: [String] },
    })
  )
end

.upload(file, volume = nil, manga_id:) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/mangadex/cover_art.rb', line 37

def self.upload(file, volume=nil, manga_id:)
  args = { file: file, volume: volume }
  Mangadex::Internal::Request.post(
    '/cover/%{manga_id}' % {manga_id: manga_id},
    payload: Mangadex::Internal::Definition.validate(args, {
      file: { accepts: String, required: true },
      volume: { accepts: %r{^(0|[1-9]\\d*)((\\.\\d+){1,2})?[a-z]?$} } # todo: double check regexp here
    })
  )
end

Instance Method Details

#image_url(size: :small) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/mangadex/cover_art.rb', line 78

def image_url(size: :small)
  return unless manga.present?

  extension = case size.to_sym
  when :original
    ''
  when :medium
    '.512.jpg'
  else # :small by default
    '.256.jpg'
  end

  "https://uploads.mangadex.org/covers/#{manga.id}/#{file_name}#{extension}"
end