shikimori-api 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +20 -0
  3. data/lib/shikimori/api/client.rb +34 -0
  4. data/lib/shikimori/api/errors.rb +21 -0
  5. data/lib/shikimori/api/rest.rb +115 -0
  6. data/lib/shikimori/api/uri.rb +18 -0
  7. data/lib/shikimori/api/v1/achievements.rb +32 -0
  8. data/lib/shikimori/api/v1/animes.rb +252 -0
  9. data/lib/shikimori/api/v1/appear.rb +40 -0
  10. data/lib/shikimori/api/v1/bans.rb +31 -0
  11. data/lib/shikimori/api/v1/calendars.rb +32 -0
  12. data/lib/shikimori/api/v1/characters.rb +52 -0
  13. data/lib/shikimori/api/v1/clubs.rb +329 -0
  14. data/lib/shikimori/api/v1/comments.rb +161 -0
  15. data/lib/shikimori/api/v1/constants.rb +107 -0
  16. data/lib/shikimori/api/v1/dialogs.rb +78 -0
  17. data/lib/shikimori/api/v1/favorites.rb +148 -0
  18. data/lib/shikimori/api/v1/forums.rb +31 -0
  19. data/lib/shikimori/api/v1/friends.rb +57 -0
  20. data/lib/shikimori/api/v1/genres.rb +31 -0
  21. data/lib/shikimori/api/v1/ignores.rb +62 -0
  22. data/lib/shikimori/api/v1/mangas.rb +211 -0
  23. data/lib/shikimori/api/v1/messages.rb +168 -0
  24. data/lib/shikimori/api/v1/people.rb +53 -0
  25. data/lib/shikimori/api/v1/publishers.rb +31 -0
  26. data/lib/shikimori/api/v1/ranobe.rb +206 -0
  27. data/lib/shikimori/api/v1/reviews.rb +89 -0
  28. data/lib/shikimori/api/v1/stats.rb +31 -0
  29. data/lib/shikimori/api/v1/studios.rb +31 -0
  30. data/lib/shikimori/api/v1/styles.rb +112 -0
  31. data/lib/shikimori/api/v1/topic_ignores.rb +63 -0
  32. data/lib/shikimori/api/v1/topics.rb +237 -0
  33. data/lib/shikimori/api/v1/user_images.rb +36 -0
  34. data/lib/shikimori/api/v1/user_rates.rb +194 -0
  35. data/lib/shikimori/api/v1/users.rb +310 -0
  36. data/lib/shikimori/api/v1/videos.rb +85 -0
  37. data/lib/shikimori/api/v1.rb +77 -0
  38. data/lib/shikimori/api/v2/abuse_requests.rb +103 -0
  39. data/lib/shikimori/api/v2/episode_notifications.rb +54 -0
  40. data/lib/shikimori/api/v2/topic_ignore.rb +54 -0
  41. data/lib/shikimori/api/v2/user_ignore.rb +54 -0
  42. data/lib/shikimori/api/v2/user_rates.rb +171 -0
  43. data/lib/shikimori/api/v2.rb +27 -0
  44. data/lib/shikimori/api/version.rb +8 -0
  45. data/lib/shikimori/api.rb +14 -0
  46. data/lib/shikimori-api.rb +3 -0
  47. data/shikimori-api.gemspec +40 -0
  48. data/sig/shikimori/api/client.rbs +12 -0
  49. data/sig/shikimori/api/rest.rbs +30 -0
  50. data/sig/shikimori/api/uri.rbs +10 -0
  51. data/sig/shikimori/api/v1/achievements.rbs +15 -0
  52. data/sig/shikimori/api/v1/animes.rbs +23 -0
  53. data/sig/shikimori/api/v1/appear.rbs +15 -0
  54. data/sig/shikimori/api/v1/bans.rbs +15 -0
  55. data/sig/shikimori/api/v1/calendars.rbs +15 -0
  56. data/sig/shikimori/api/v1/characters.rbs +16 -0
  57. data/sig/shikimori/api/v1/clubs.rbs +29 -0
  58. data/sig/shikimori/api/v1/comments.rbs +19 -0
  59. data/sig/shikimori/api/v1/constants.rbs +19 -0
  60. data/sig/shikimori/api/v1/dialogs.rbs +17 -0
  61. data/sig/shikimori/api/v1/favorites.rbs +23 -0
  62. data/sig/shikimori/api/v1/forums.rbs +15 -0
  63. data/sig/shikimori/api/v1/friends.rbs +16 -0
  64. data/sig/shikimori/api/v1/genres.rbs +15 -0
  65. data/sig/shikimori/api/v1/ignores.rbs +16 -0
  66. data/sig/shikimori/api/v1/mangas.rbs +23 -0
  67. data/sig/shikimori/api/v1/messages.rbs +20 -0
  68. data/sig/shikimori/api/v1/people.rbs +16 -0
  69. data/sig/shikimori/api/v1/publishers.rbs +15 -0
  70. data/sig/shikimori/api/v1/ranobe.rbs +23 -0
  71. data/sig/shikimori/api/v1/reviews.rbs +19 -0
  72. data/sig/shikimori/api/v1/stats.rbs +15 -0
  73. data/sig/shikimori/api/v1/studios.rbs +15 -0
  74. data/sig/shikimori/api/v1/styles.rbs +18 -0
  75. data/sig/shikimori/api/v1/topic_ignores.rbs +16 -0
  76. data/sig/shikimori/api/v1/topics.rbs +40 -0
  77. data/sig/shikimori/api/v1/user_images.rbs +15 -0
  78. data/sig/shikimori/api/v1/user_rates.rbs +44 -0
  79. data/sig/shikimori/api/v1/users.rbs +28 -0
  80. data/sig/shikimori/api/v1/videos.rbs +23 -0
  81. data/sig/shikimori/api/v1.rbs +41 -0
  82. data/sig/shikimori/api/v2/abuse_requests.rbs +18 -0
  83. data/sig/shikimori/api/v2/episode_notifications.rbs +25 -0
  84. data/sig/shikimori/api/v2/topic_ignore.rbs +16 -0
  85. data/sig/shikimori/api/v2/user_ignore.rbs +16 -0
  86. data/sig/shikimori/api/v2/user_rates.rbs +43 -0
  87. data/sig/shikimori/api/v2.rbs +16 -0
  88. data/sig/shikimori/api/version.rbs +5 -0
  89. data/sig/shikimori/api.rbs +18 -0
  90. metadata +137 -0
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shikimori
4
+ module API
5
+ class V1
6
+ # Methods for the Styles API
7
+ #
8
+ # @see https://shikimori.one/api/doc/1.0/styles Shikimori's API documentation
9
+ module Styles
10
+ # Get a style
11
+ #
12
+ # @param id [#to_s] Style id
13
+ # @param headers [Hash] Request headers
14
+ # @param query [Hash] Query string parameters for request
15
+ #
16
+ # @return [Hash] Hash representing style
17
+ #
18
+ # @see https://shikimori.one/api/doc/1.0/styles/show Shikimori's API documentation
19
+ # @example Get a style with id equal to 1
20
+ # client = Shikimori::API::Client.new(
21
+ # app_name: 'Api Test',
22
+ # aceess_token: '****',
23
+ # refresh_token: '****'
24
+ # )
25
+ # client.v1.style(1)
26
+ def style(id, headers: nil, **query)
27
+ rest.get base_url.join('styles', id.to_s).url, headers: headers, query: query
28
+ end
29
+
30
+ # Create style
31
+ #
32
+ # @param style [Hash] Style data for creating
33
+ # @option style [String] :css Style CSS content
34
+ # @option style [String] :name Style name
35
+ # @option style [Integer] :owner_id Owner ID
36
+ # @option style ['User', 'Club'] :owner_type Owner type
37
+ # @param headers [Hash] Request headers
38
+ # @param query [Hash] Query string parameters for request
39
+ #
40
+ # @return [Hash] Hash representing created style
41
+ #
42
+ # @see https://shikimori.one/api/doc/1.0/styles/create Shikimori's API documentation
43
+ # @example Create a red background style
44
+ # client = Shikimori::API::Client.new(
45
+ # app_name: 'Api Test',
46
+ # aceess_token: '****',
47
+ # refresh_token: '****'
48
+ # )
49
+ # client.v1.create_style({
50
+ # name: 'Red background',
51
+ # css: 'body: { background: red !important; }',
52
+ # owner_id: 1,
53
+ # owner_type: 'User'
54
+ # })
55
+ def create_style(style, headers: nil, **query)
56
+ rest.post base_url.join('styles').url, { style: style }, headers: headers, query: query
57
+ end
58
+
59
+ # Update style
60
+ #
61
+ # @param id [Hash] Style's ID
62
+ # @param style [Hash] Style data for updating
63
+ # @option style [String] :css Style CSS content
64
+ # @option style [String] :name Style name
65
+ # @param headers [Hash] Request headers
66
+ # @param query [Hash] Query string parameters for request
67
+ #
68
+ # @return [Hash] Hash representing updated style
69
+ #
70
+ # @see https://shikimori.one/api/doc/1.0/styles/update Shikimori's API documentation
71
+ # @example Change style from red background to green
72
+ # client = Shikimori::API::Client.new(
73
+ # app_name: 'Api Test',
74
+ # aceess_token: '****',
75
+ # refresh_token: '****'
76
+ # )
77
+ #
78
+ # client.v1.update_style(
79
+ # 1,
80
+ # { name: 'Green background', css: 'body: { background: green !important; }', }
81
+ # )
82
+ def update_style(id, style, headers: nil, **query)
83
+ rest.put base_url.join('styles', id.to_s).url, { style: style }, headers: headers, query: query
84
+ end
85
+
86
+ # Preview style
87
+ #
88
+ # @param style [Hash] Style data for preview
89
+ # @option style [String] :css Style CSS content
90
+ # @param headers [Hash] Request headers
91
+ # @param query [Hash] Query string parameters for request
92
+ #
93
+ # @return [Hash] Hash representing updated style
94
+ #
95
+ # @see https://shikimori.one/api/doc/1.0/styles/preview Shikimori's API documentation
96
+ # @example Preview style with green background
97
+ # client = Shikimori::API::Client.new(
98
+ # app_name: 'Api Test',
99
+ # aceess_token: '****',
100
+ # refresh_token: '****'
101
+ # )
102
+ # client.v1.preview_style(
103
+ # 1,
104
+ # { css: 'body: { background: green !important; }', }
105
+ # )
106
+ def preview_style(style, headers: nil, **query)
107
+ rest.post base_url.join('styles', 'preview').url, { style: style }, headers: headers, query: query
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shikimori
4
+ module API
5
+ class V1
6
+ # Methods for the Topic ignores API
7
+ #
8
+ # @deprecated Use {Shikimori::API::V2::TopicIgnore} instead
9
+ #
10
+ # @see https://shikimori.one/api/doc/1.0/topic_ignores Shikimori's API documentation
11
+ module TopicIgnores
12
+ # Add user to ignore at topic by user id and topic id.
13
+ # Requires `topics` oauth scope
14
+ #
15
+ # @param topic_id [Integer] Topic id where to add
16
+ # @param user_id [Integer] User id that add to ignores
17
+ # @param headers [Hash] Request headers
18
+ # @param query [Hash] Query string parameters for request
19
+ #
20
+ # @return [Hash] Hash representing created topic ignore
21
+ #
22
+ # @see https://shikimori.one/api/doc/1.0/topic_ignores/create Shikimori's API documentation
23
+ # @example Add to ignore a user with id equal to 1 at topic with id equal to 1
24
+ # client = Shikimori::API::Client.new(
25
+ # app_name: 'Api Test',
26
+ # aceess_token: '****',
27
+ # refresh_token: '****'
28
+ # )
29
+ # client.v1.create_topic_ignore(topic_id: 1, user_id: 1)
30
+ #
31
+ # @deprecated Use {Shikimori::API::V2::TopicIgnore#create_topic_ignore} instead
32
+ def create_topic_ignore(topic_id:, user_id:, headers: nil, **query)
33
+ payload = { topic_ignore: { topic_id: topic_id, user_id: user_id } }
34
+
35
+ rest.post base_url.join('topic_ignores').url, payload, headers: headers, query: query
36
+ end
37
+
38
+ # Delete a user from topic ignores by id.
39
+ # Requires `ignores` oauth scope
40
+ #
41
+ # @param id [#to_s] Topic ignore id
42
+ # @param headers [Hash] Request headers
43
+ # @param query [Hash] Query string parameters for request
44
+ #
45
+ # @return [Boolean] True if deletion successful, false otherwise.
46
+ #
47
+ # @see https://shikimori.one/api/doc/1.0/topic_ignores/destroy Shikimori's API documentation
48
+ # @example Delete a topic ignore
49
+ # client = Shikimori::API::Client.new(
50
+ # app_name: 'Api Test',
51
+ # aceess_token: '****',
52
+ # refresh_token: '****'
53
+ # )
54
+ # client.v1.delete_topic_ignore(1)
55
+ #
56
+ # @deprecated Use {Shikimori::API::V2::TopicIgnore#delete_topic_ignore} instead
57
+ def delete_topic_ignore(id, headers: nil, **query)
58
+ rest.delete base_url.join('topic_ignores', id.to_s).url, headers: headers, query: query
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,237 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shikimori
4
+ module API
5
+ class V1
6
+ # Methods for the Topics API
7
+ #
8
+ # @see https://shikimori.one/api/doc/1.0/topics Shikimori's API documentation
9
+ module Topics
10
+ TOPIC_TYPES_MAP = {
11
+ 'topic' => 'Topic',
12
+ 'club_user' => 'Topics::ClubUserTopic',
13
+ 'entry_topic' => 'Topics::EntryTopic',
14
+ 'anime' => 'Topics::EntryTopics::AnimeTopic',
15
+ 'article' => 'Topics::EntryTopics::ArticleTopic',
16
+ 'character' => 'Topics::EntryTopics::CharacterTopic',
17
+ 'club_page' => 'Topics::EntryTopics::ClubPageTopic',
18
+ 'club' => 'Topics::EntryTopics::ClubTopic',
19
+ 'collection' => 'Topics::EntryTopics::CollectionTopic',
20
+ 'contest' => 'Topics::EntryTopics::ContestTopic',
21
+ 'cosplay_gallery' => 'Topics::EntryTopics::CosplayGalleryTopic',
22
+ 'manga' => 'Topics::EntryTopics::MangaTopic',
23
+ 'person' => 'Topics::EntryTopics::PersonTopic',
24
+ 'ranobe' => 'Topics::EntryTopics::RanobeTopic',
25
+ 'critique' => 'Topics::EntryTopics::CritiqueTopic',
26
+ 'review' => 'Topics::EntryTopics::ReviewTopic',
27
+ 'news' => 'Topics::NewsTopic',
28
+ 'contest_status' => 'Topics::NewsTopics::ContestStatusTopic'
29
+ }.freeze
30
+
31
+ # Get list of topics
32
+ #
33
+ # @param headers [Hash] Request headers
34
+ # @param query [Hash] Query string parameters for request
35
+ # @option query [Integer] :page Number of page. Must be between 1 and 100000
36
+ # @option query [Integer] :limit Number of titles per page. Must be a lower or equal that 30
37
+ # @option query ['all', 'animanga', 'site',
38
+ # 'games', 'vn', 'contests',
39
+ # 'offtopic', 'clubs', 'my_clubs',
40
+ # 'critiques', 'news', 'collections',
41
+ # 'articles', 'cosplay'] :forum Forum type
42
+ # @option query [Integer] :linked_id Linked object ID
43
+ # @option query ['Anime', 'Manga', 'Ranobe',
44
+ # 'Character', 'Person', 'Club',
45
+ # 'ClubPage', 'Critique', 'Review',
46
+ # 'Contest', 'CosplayGallery',
47
+ # 'Collection', 'Article'] :linked_type Linked object type
48
+ # @option query ['topic', 'club_user', 'entry_topic',
49
+ # 'anime', 'article', 'character',
50
+ # 'club_page', 'club', 'collection',
51
+ # 'contest', 'cosplay_gallery', 'manga',
52
+ # 'person', 'ranobe', 'critique',
53
+ # 'review', 'news', 'contest_status'] :type Type of topic
54
+ #
55
+ # @return [Array<Hash>] Array of hashes representing topics
56
+ #
57
+ # @see https://shikimori.one/api/doc/1.0/topics/index Shikimori's API documentation
58
+ # @example Get list of topics
59
+ # client = Shikimori::API::Client.new(
60
+ # app_name: 'Api Test',
61
+ # aceess_token: '****',
62
+ # refresh_token: '****'
63
+ # )
64
+ # client.v1.topics #=> [{ id: 1, ... }, ...]
65
+ def topics(type: nil, headers: nil, **query)
66
+ topic_type = type && TOPIC_TYPES_MAP[type]
67
+
68
+ rest.get base_url.join('topics').url, headers: headers, query: query.merge(
69
+ type: topic_type
70
+ ).compact
71
+ end
72
+
73
+ # Get an topic by id
74
+ #
75
+ # @param id [#to_s] Topic id
76
+ # @param headers [Hash] Request headers
77
+ # @param query [Hash] Query string parameters for request
78
+ #
79
+ # @return [Hash] Hash representing topic
80
+ #
81
+ # @see https://shikimori.one/api/doc/1.0/topics/show Shikimori's API documentation
82
+ # @example Get topic with id equal to 1
83
+ # client = Shikimori::API::Client.new(
84
+ # app_name: 'Api Test',
85
+ # aceess_token: '****',
86
+ # refresh_token: '****'
87
+ # )
88
+ # client.v1.topic(1) #=> { id: 1, ... }
89
+ def topic(id, headers: nil, **query)
90
+ rest.get base_url.join('topics', id.to_s).url, headers: headers, query: query
91
+ end
92
+
93
+ # Create a topic.
94
+ # Requires `topics` oauth scope
95
+ #
96
+ # @param topic [Hash] Topic data for creating
97
+ # @option topic [String] :title Topic title
98
+ # @option topic ['Topic'] :type Topic type
99
+ # @option topic [String] :body Topic text
100
+ # @option topic [Integer] :forum_id ID of forum
101
+ # @option topic [Integer] :user_id ID of user created a topic
102
+ # @option topic [Integer] :linked_id ID of linked object to topic
103
+ # @option topic ['Anime', 'Manga', 'Ranobe',
104
+ # 'Character', 'Person', 'Club',
105
+ # 'ClubPage', 'Critique', 'Review',
106
+ # 'Contest', 'CosplayGallery',
107
+ # 'Collection', 'Article'] :linked_type Type of linked object to topic
108
+ # @param headers [Hash] Request headers
109
+ # @param query [Hash] Query string parameters for request
110
+ #
111
+ # @return [Hash] Hash representing created topic
112
+ #
113
+ # @see https://shikimori.one/api/doc/1.0/topics/create Shikimori's API documentation
114
+ # @example Create a topic
115
+ # client = Shikimori::API::Client.new(
116
+ # app_name: 'Api Test',
117
+ # aceess_token: '****',
118
+ # refresh_token: '****'
119
+ # )
120
+ # topic = {
121
+ # body: "text",
122
+ # forum_id: "1",
123
+ # linked_id: "41",
124
+ # linked_type: "Anime",
125
+ # title: "zxc",
126
+ # type: "Topic",
127
+ # user_id: "23456791"
128
+ # }
129
+ # client.v1.create_topic(topic)
130
+ def create_topic(topic, headers: nil, **query)
131
+ rest.post(
132
+ base_url.join('topics').url,
133
+ { topic: topic }.compact,
134
+ headers: headers, query: query
135
+ )
136
+ end
137
+
138
+ # Update Topic
139
+ # Requires `topics` oauth scope
140
+ #
141
+ # @param id [#to_s] Topic id
142
+ # @param topic [Hash] Topic data for updating
143
+ # @option topic [String] :title Topic title
144
+ # @option topic [String] :body Topic text
145
+ # @option topic [Integer] :linked_id ID of linked object to topic
146
+ # @option topic ['Anime', 'Manga', 'Ranobe',
147
+ # 'Character', 'Person', 'Club',
148
+ # 'ClubPage', 'Critique', 'Review',
149
+ # 'Contest', 'CosplayGallery',
150
+ # 'Collection', 'Article'] :linked_type Type of linked object to topic
151
+ # @param headers [Hash] Request headers
152
+ # @param query [Hash] Query string parameters for request
153
+ #
154
+ # @return [Hash] Hash representing updated topic
155
+ #
156
+ # @see https://shikimori.one/api/doc/1.0/topics/update Shikimori's API documentation
157
+ # @example Update a topic
158
+ # client = Shikimori::API::Client.new(
159
+ # app_name: 'Api Test',
160
+ # aceess_token: '****',
161
+ # refresh_token: '****'
162
+ # )
163
+ # topic = {
164
+ # body: "text",
165
+ # linked_id: "41",
166
+ # linked_type: "Anime",
167
+ # title: "zxc",
168
+ # }
169
+ # client.v1.update_topic(topic)
170
+ def update_topic(id, topic, headers: nil, **query)
171
+ rest.put base_url.join('topics', id.to_s).url, { topic: topic }, headers: headers, query: query
172
+ end
173
+
174
+ # Delete Topic
175
+ #
176
+ # @param id [String, Integer] Topic id
177
+ # @param headers [Hash] Request headers
178
+ # @param query [Hash] Query string parameters for request
179
+ #
180
+ # @return [Boolean] True if deletion successful, false otherwise.
181
+ #
182
+ # @see https://shikimori.one/api/doc/1.0/topics/destroy Shikimori's API documentation
183
+ # @example Delete a topic with id equal to 1
184
+ # client = Shikimori::API::Client.new(
185
+ # app_name: 'Api Test',
186
+ # aceess_token: '****',
187
+ # refresh_token: '****'
188
+ # )
189
+ # client.v1.delete_topic(1)
190
+ def delete_topic(id, headers: nil, **query)
191
+ rest.delete base_url.join('topics', id.to_s).url, headers: headers, query: query
192
+ end
193
+
194
+ # Get topics updates
195
+ #
196
+ # @param headers [Hash] Request headers
197
+ # @param query [Hash] Query string parameters for request
198
+ # @option query [Integer] :page Number of page. Must be between 1 and 100000
199
+ # @option query [Integer] :limit Number of titles per page. Must be a lower or equal that 30
200
+ #
201
+ # @return [Array<Hash>] Array of hashes representing topic updates
202
+ #
203
+ # @see https://shikimori.one/api/doc/1.0/topics/updates Shikimori's API documentation
204
+ # @example Get list of topics updates
205
+ # client = Shikimori::API::Client.new(
206
+ # app_name: 'Api Test',
207
+ # aceess_token: '****',
208
+ # refresh_token: '****'
209
+ # )
210
+ # client.v1.topics_updates #=> [{ id: 1, ... }, ...]
211
+ def topics_updates(headers: nil, **query)
212
+ rest.get base_url.join('topics', 'updates').url, headers: headers, query: query
213
+ end
214
+
215
+ # Get hot topics
216
+ #
217
+ # @param headers [Hash] Request headers
218
+ # @param query [Hash] Query string parameters for request
219
+ # @option query [Integer] :limit Number of titles per page. Must be a lower or equal that 10
220
+ #
221
+ # @return [Array<Hash>] Array of hashes representing topic updates
222
+ #
223
+ # @see https://shikimori.one/api/doc/1.0/topics/hot Shikimori's API documentation
224
+ # @example Get list of hot topics
225
+ # client = Shikimori::API::Client.new(
226
+ # app_name: 'Api Test',
227
+ # aceess_token: '****',
228
+ # refresh_token: '****'
229
+ # )
230
+ # client.v1.hot_topics #=> [{ id: 1, ... }, ...]
231
+ def hot_topics(headers: nil, **query)
232
+ rest.get base_url.join('topics', 'hot').url, headers: headers, query: query
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shikimori
4
+ module API
5
+ class V1
6
+ # Methods for the User images API
7
+ #
8
+ # @see https://shikimori.one/api/doc/1.0/user_images Shikimori's API documentation
9
+ module UserImages
10
+ # Create User image.
11
+ # Requires `comments` oauth scope
12
+ #
13
+ # @param image [File] Image file
14
+ # @param linked_type ['Comment'] Linking type
15
+ # @param headers [Hash] Request headers
16
+ # @param query [Hash] Query string parameters for request
17
+ #
18
+ # @return [Hash] Hash representing created user image
19
+ #
20
+ # @see https://shikimori.one/api/doc/1.0/user_images/create Shikimori's API documentation
21
+ # @example Create user's image
22
+ # client = Shikimori::API::Client.new(
23
+ # app_name: 'Api Test',
24
+ # aceess_token: '****',
25
+ # refresh_token: '****'
26
+ # )
27
+ # client.v1.create_user_image(File.open('/tmp/file.jpg'), linked_type: 'Comment')
28
+ def create_user_image(image, linked_type: nil, headers: nil, **query)
29
+ rest.post base_url.join('user_images').url,
30
+ { 'image' => image, 'linked_type' => linked_type }.compact,
31
+ headers: headers, query: query, as_form: true
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,194 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shikimori
4
+ module API
5
+ class V1
6
+ # Methods for the User rates API
7
+ #
8
+ # @see https://shikimori.one/api/doc/1.0/user_rates Shikimori's API documentation
9
+ module UserRates
10
+ # Get an user rate by id
11
+ #
12
+ # @param id [#to_s] user rate id
13
+ # @param headers [Hash] Request headers
14
+ # @param query [Hash] Query string parameters for request
15
+ #
16
+ # @return [Hash] Hash representing user rate
17
+ #
18
+ # @see https://shikimori.one/api/doc/1.0/user_rates/show Shikimori's API documentation
19
+ # @example Get user rate with id equal to 1
20
+ # client = Shikimori::API::Client.new(
21
+ # app_name: 'Api Test',
22
+ # aceess_token: '****',
23
+ # refresh_token: '****'
24
+ # )
25
+ # client.v1.user_rate(1) #=> { id: 1, ... }
26
+ #
27
+ # @deprecated Use {Shikimori::API::V2::UserRates#user_rate} instead
28
+ def user_rate(id, headers: nil, **query)
29
+ rest.get base_url.join('user_rates', id.to_s).url, headers: headers, query: query
30
+ end
31
+
32
+ # Create a user rate.
33
+ # Requires `user_rates` oauth scope
34
+ #
35
+ # @param user_rate [Hash] User rate data for creating
36
+ # @option user_rate [Integer] :user_id User id
37
+ # @option user_rate [Integer] :target_id Target id
38
+ # @option user_rate ['Anime', 'Manga'] :target_type Target type
39
+ # @option user_rate ["planned", "watching", "rewatching",
40
+ # "completed", "on_hold", "dropped"] :status Watching status
41
+ # @option user_rate [Numeric] :score Score
42
+ # @option user_rate [Numeric] :chapters Current chapter number
43
+ # @option user_rate [Numeric] :episodes Current episode number
44
+ # @option user_rate [Numeric] :volumes Current volume number
45
+ # @option user_rate [Numeric] :rewatches Count of rewatching
46
+ # @option user_rate [String] :text Rate text
47
+ # @param headers [Hash] Request headers
48
+ # @param query [Hash] Query string parameters for request
49
+ #
50
+ # @return [Hash] Hash representing created user rate
51
+ #
52
+ # @see https://shikimori.one/api/doc/1.0/user_rates/create Shikimori's API documentation
53
+ # @example Create a user rate
54
+ # client = Shikimori::API::Client.new(
55
+ # app_name: 'Api Test',
56
+ # aceess_token: '****',
57
+ # refresh_token: '****'
58
+ # )
59
+ # user_rate = {
60
+ # text: "text",
61
+ # user_id: 1,
62
+ # target_id: "41",
63
+ # target_type: "Anime"
64
+ # }
65
+ # client.v1.create_user_rate(user_rate)
66
+ #
67
+ # @deprecated Use {Shikimori::API::V2::UserRates#create_user_rate} instead
68
+ def create_user_rate(user_rate, headers: nil, **query)
69
+ rest.post base_url.join('user_rates').url, { user_rate: user_rate }, headers: headers, query: query
70
+ end
71
+
72
+ # Update a user rate.
73
+ # Requires `user_rates` oauth scope
74
+ #
75
+ # @param id [#to_s] User rate id
76
+ # @param user_rate [Hash] User rate data for creating
77
+ # @option user_rate ["planned", "watching", "rewatching",
78
+ # "completed", "on_hold", "dropped"] :status Watching status
79
+ # @option user_rate [Numeric] :score Score
80
+ # @option user_rate [Numeric] :chapters Current chapter number
81
+ # @option user_rate [Numeric] :episodes Current episode number
82
+ # @option user_rate [Numeric] :volumes Current volume number
83
+ # @option user_rate [Numeric] :rewatches Count of rewatching
84
+ # @option user_rate [String] :text Rate text
85
+ # @param headers [Hash] Request headers
86
+ # @param query [Hash] Query string parameters for request
87
+ #
88
+ # @return [Hash] Hash representing updated user rate
89
+ #
90
+ # @see https://shikimori.one/api/doc/1.0/user_rates/update Shikimori's API documentation
91
+ # @example Update a user rate text
92
+ # client = Shikimori::API::Client.new(
93
+ # app_name: 'Api Test',
94
+ # aceess_token: '****',
95
+ # refresh_token: '****'
96
+ # )
97
+ # user_rate = {
98
+ # text: "text"
99
+ # }
100
+ # client.v1.update_user_rate(1, user_rate)
101
+ #
102
+ # @deprecated Use {Shikimori::API::V2::UserRates#update_user_rate} instead
103
+ def update_user_rate(id, user_rate, headers: nil, **query)
104
+ rest.put base_url.join('user_rates', id.to_s).url, { user_rate: user_rate }, headers: headers, query: query
105
+ end
106
+
107
+ # Delete user rate
108
+ #
109
+ # @param id [#to_s] User rate id
110
+ # @param headers [Hash] Request headers
111
+ # @param query [Hash] Query string parameters for request
112
+ #
113
+ # @return [Boolean] True if deletion successful, false otherwise.
114
+ #
115
+ # @see https://shikimori.one/api/doc/1.0/user_rates/destroy Shikimori's API documentation
116
+ # @example Delete user rate
117
+ # client = Shikimori::API::Client.new(
118
+ # app_name: 'Api Test',
119
+ # aceess_token: '****',
120
+ # refresh_token: '****'
121
+ # )
122
+ # client.v1.delete_user_rate(1)
123
+ #
124
+ # @deprecated Use {Shikimori::API::V2::UserRates#delete_user_rate} instead
125
+ def delete_user_rate(id, headers: nil, **query)
126
+ rest.delete base_url.join('user_rates', id.to_s).url, headers: headers, query: query
127
+ end
128
+
129
+ # Increment episodes/chapters by 1
130
+ # Requires `user_rates` oauth scope
131
+ #
132
+ # @param id [#to_s] User rate ID
133
+ # @param headers [Hash] Request headers
134
+ # @param query [Hash] Query string parameters for request
135
+ #
136
+ # @return [Hash] Hash representing created user rate
137
+ #
138
+ # @see https://shikimori.one/api/doc/1.0/user_rates/increment Shikimori's API documentation
139
+ # @example Increment episodes/chapters by 1
140
+ # client = Shikimori::API::Client.new(
141
+ # app_name: 'Api Test',
142
+ # aceess_token: '****',
143
+ # refresh_token: '****'
144
+ # )
145
+ # client.v1.increment_user_rate(1)
146
+ #
147
+ # @deprecated Use {Shikimori::API::V2::UserRates#increment_user_rate} instead
148
+ def increment_user_rate(id, headers: nil, **query)
149
+ rest.post base_url.join('user_rates', id.to_s, 'increment').url, {}, headers: headers, query: query
150
+ end
151
+
152
+ # Delete entire user rates and history
153
+ #
154
+ # @param type ['anime', 'manga'] Type of cleanup
155
+ # @param headers [Hash] Request headers
156
+ # @param query [Hash] Query string parameters for request
157
+ #
158
+ # @return [Boolean] True if deletion successful, false otherwise.
159
+ #
160
+ # @see https://shikimori.one/api/doc/1.0/user_rates/cleanup Shikimori's API documentation
161
+ # @example Delete entire user rates and history
162
+ # client = Shikimori::API::Client.new(
163
+ # app_name: 'Api Test',
164
+ # aceess_token: '****',
165
+ # refresh_token: '****'
166
+ # )
167
+ # client.v1.cleanup_user_rates('manga')
168
+ def cleanup_user_rates(type, headers: nil, **query)
169
+ rest.delete base_url.join('user_rates', type.to_s, 'cleanup').url, headers: headers, query: query
170
+ end
171
+
172
+ # Reset all user scores to 0
173
+ #
174
+ # @param type ['anime', 'manga'] Type of reset
175
+ # @param headers [Hash] Request headers
176
+ # @param query [Hash] Query string parameters for request
177
+ #
178
+ # @return [Boolean] True if deletion successful, false otherwise.
179
+ #
180
+ # @see https://shikimori.one/api/doc/1.0/user_rates/reset Shikimori's API documentation
181
+ # @example Reset all user scores to 0
182
+ # client = Shikimori::API::Client.new(
183
+ # app_name: 'Api Test',
184
+ # aceess_token: '****',
185
+ # refresh_token: '****'
186
+ # )
187
+ # client.v1.reset_user_rates('manga')
188
+ def reset_user_rates(type, headers: nil, **query)
189
+ rest.delete base_url.join('user_rates', type.to_s, 'reset').url, headers: headers, query: query
190
+ end
191
+ end
192
+ end
193
+ end
194
+ end