Class: Mangadex::CustomList
- Inherits:
-
MangadexObject
- Object
- MangadexObject
- Mangadex::CustomList
- Defined in:
- lib/mangadex/custom_list.rb
Instance Attribute Summary
Attributes included from Internal::WithAttributes
#attributes, #id, #related_type, #relationships, #type
Class Method Summary collapse
- .add_manga(id, list_id:) ⇒ Object
- .create(**args) ⇒ Object
- .delete(id) ⇒ Object
- .feed(id, **args) ⇒ Object
- .get(id) ⇒ Object (also: view)
- .inspect_attributes ⇒ Object
- .list(**args) ⇒ Object
- .remove_manga(id, list_id:) ⇒ Object
- .update(id, **args) ⇒ Object (also: edit)
- .user_list(user_id, **args) ⇒ Object
Instance Method Summary collapse
Methods inherited from MangadexObject
attributes_to_inspect, #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
.add_manga(id, list_id:) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mangadex/custom_list.rb', line 70 def self.add_manga(id, list_id:) Mangadex::Internal::Definition.must(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
50 51 52 53 54 55 56 |
# File 'lib/mangadex/custom_list.rb', line 50 def self.delete(id) Mangadex::Internal::Definition.must(id) Mangadex::Internal::Request.delete( '/list/%{id}' % {id: id}, ) end |
.feed(id, **args) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/mangadex/custom_list.rb', line 59 def self.feed(id, **args) Mangadex::Internal::Definition.must(id) Mangadex::Internal::Request.get( '/list/%{id}/feed' % {id: id}, Mangadex::Internal::Definition.chapter_list(args), content_rating: true, ) end |
.get(id) ⇒ Object Also known as: view
26 27 28 29 30 31 32 |
# File 'lib/mangadex/custom_list.rb', line 26 def self.get(id) Mangadex::Internal::Definition.must(id) Mangadex::Internal::Request.get( '/list/%{id}' % {id: id}, ) end |
.inspect_attributes ⇒ Object
143 144 145 |
# File 'lib/mangadex/custom_list.rb', line 143 def self.inspect_attributes [:name, :visibility] end |
.list(**args) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/mangadex/custom_list.rb', line 98 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
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mangadex/custom_list.rb', line 84 def self.remove_manga(id, list_id:) Mangadex::Internal::Definition.must(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 Also known as: edit
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mangadex/custom_list.rb', line 35 def self.update(id, **args) Mangadex::Internal::Definition.must(id) 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
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/mangadex/custom_list.rb', line 109 def self.user_list(user_id, **args) Mangadex::Internal::Definition.must(user_id) 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
127 128 129 |
# File 'lib/mangadex/custom_list.rb', line 127 def add_manga(id) Mangadex::CustomList.add_manga(id, list_id: self.id) end |
#manga_details(**args) ⇒ Object
137 138 139 140 141 |
# File 'lib/mangadex/custom_list.rb', line 137 def manga_details(**args) custom_list = Mangadex::CustomList.get(id).data ids = custom_list.mangas.map(&:id) ids.any? ? Mangadex::Manga.list(**args.merge(ids: ids)) : nil end |
#remove_manga(id) ⇒ Object
132 133 134 |
# File 'lib/mangadex/custom_list.rb', line 132 def remove_manga(id) Mangadex::CustomList.remove_manga(id, list_id: self.id) end |