Class: Mangadex::CustomList

Inherits:
MangadexObject show all
Defined in:
lib/mangadex/custom_list.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

.add_manga(id, list_id:) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/mangadex/custom_list.rb', line 61

def self.add_manga(id, list_id:)
  response = Mangadex::Internal::Request.post(
    '/manga/%{id}/list/%{list_id}' % {id: id, list_id: list_id},
  )
  if response.is_a?(Hash)
    response['result'] == 'ok'
  else
    !response.errored?
  end
end

.create(**args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mangadex/custom_list.rb', line 12

def self.create(**args)
  Mangadex::Internal::Request.post(
    '/list',
    payload: Mangadex::Internal::Definition.validate(args, {
      name: { accepts: String, required: true },
      visibility: { accepts: %w(public private), converts: :to_s },
      manga: { accepts: String },
      version: { accepts: Integer },
    }),
    auth: true,
  )
end

.delete(id) ⇒ Object



46
47
48
49
50
# File 'lib/mangadex/custom_list.rb', line 46

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

.feed(id, **args) ⇒ Object



53
54
55
56
57
58
# File 'lib/mangadex/custom_list.rb', line 53

def self.feed(id, **args)
  Mangadex::Internal::Request.get(
    '/list/%{id}/feed' % {id: id},
    Mangadex::Internal::Definition.chapter_list(args),
  )
end

.get(id) ⇒ Object



26
27
28
29
30
# File 'lib/mangadex/custom_list.rb', line 26

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

.inspect_attributesObject



122
123
124
# File 'lib/mangadex/custom_list.rb', line 122

def self.inspect_attributes
  [:name, :visibility]
end

.list(**args) ⇒ Object



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

def self.list(**args)
  Mangadex::Internal::Request.get(
    '/user/list',
    Mangadex::Internal::Definition.validate(args, {
      limit: { accepts: Integer },
      offset: { accepts: Integer },
    }),
  )
end

.remove_manga(id, list_id:) ⇒ Object



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

def self.remove_manga(id, list_id:)
  response = Mangadex::Internal::Request.delete(
    '/manga/%{id}/list/%{list_id}' % {id: id, list_id: list_id},
  )
  if response.is_a?(Hash)
    response['result'] == 'ok'
  else
    !response.errored?
  end
end

.update(id, **args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mangadex/custom_list.rb', line 33

def self.update(id, **args)
  Mangadex::Internal::Request.put(
    '/list/%{id}' % {id: id},
    payload: Mangadex::Internal::Definition.validate(args, {
      name: { accepts: String },
      visibility: { accepts: %w(private public) },
      manga: { accepts: String },
      version: { accepts: Integer, required: true },
    })
  )
end

.user_list(user_id, **args) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'lib/mangadex/custom_list.rb', line 96

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

Instance Method Details

#add_manga(id) ⇒ Object



107
108
109
# File 'lib/mangadex/custom_list.rb', line 107

def add_manga(id)
  Mangadex::CustomList.add_manga(id, list_id: self.id)
end

#manga_details(**args) ⇒ Object



117
118
119
120
# File 'lib/mangadex/custom_list.rb', line 117

def manga_details(**args)
  ids = mangas.map(&:id)
  ids.any? ? Mangadex::Manga.list(**args.merge(ids: ids)) : nil
end

#remove_manga(id) ⇒ Object



112
113
114
# File 'lib/mangadex/custom_list.rb', line 112

def remove_manga(id)
  Mangadex::CustomList.remove_manga(id, list_id: self.id)
end