Module: Shikimori::API::V1::Topics

Included in:
Shikimori::API::V1
Defined in:
lib/shikimori/api/v1/topics.rb

Overview

Methods for the Topics API

Constant Summary collapse

TOPIC_TYPES_MAP =
{
  'topic' => 'Topic',
  'club_user' => 'Topics::ClubUserTopic',
  'entry_topic' => 'Topics::EntryTopic',
  'anime' => 'Topics::EntryTopics::AnimeTopic',
  'article' => 'Topics::EntryTopics::ArticleTopic',
  'character' => 'Topics::EntryTopics::CharacterTopic',
  'club_page' => 'Topics::EntryTopics::ClubPageTopic',
  'club' => 'Topics::EntryTopics::ClubTopic',
  'collection' => 'Topics::EntryTopics::CollectionTopic',
  'contest' => 'Topics::EntryTopics::ContestTopic',
  'cosplay_gallery' => 'Topics::EntryTopics::CosplayGalleryTopic',
  'manga' => 'Topics::EntryTopics::MangaTopic',
  'person' => 'Topics::EntryTopics::PersonTopic',
  'ranobe' => 'Topics::EntryTopics::RanobeTopic',
  'critique' => 'Topics::EntryTopics::CritiqueTopic',
  'review' => 'Topics::EntryTopics::ReviewTopic',
  'news' => 'Topics::NewsTopic',
  'contest_status' => 'Topics::NewsTopics::ContestStatusTopic'
}.freeze

Instance Method Summary collapse

Instance Method Details

#create_topic(topic, headers: nil, **query) ⇒ Hash

Create a topic. Requires ‘topics` oauth scope

Examples:

Create a topic

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
topic = {
  body: "text",
  forum_id: "1",
  linked_id: "41",
  linked_type: "Anime",
  title: "zxc",
  type: "Topic",
  user_id: "23456791"
}
client.v1.create_topic(topic)

Parameters:

  • topic (Hash)

    Topic data for creating

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Options Hash (topic):

  • :title (String)

    Topic title

  • :type ('Topic')

    Topic type

  • :body (String)

    Topic text

  • :forum_id (Integer)

    ID of forum

  • :user_id (Integer)

    ID of user created a topic

  • :linked_id (Integer)

    ID of linked object to topic

  • :linked_type ('Anime', 'Manga', 'Ranobe', 'Character', 'Person', 'Club', 'ClubPage', 'Critique', 'Review', 'Contest', 'CosplayGallery', 'Collection', 'Article')

    Type of linked object to topic

Returns:

  • (Hash)

    Hash representing created topic

See Also:



130
131
132
133
134
135
136
# File 'lib/shikimori/api/v1/topics.rb', line 130

def create_topic(topic, headers: nil, **query)
  rest.post(
    base_url.join('topics').url,
    { topic: topic }.compact,
    headers: headers, query: query
  )
end

#delete_topic(id, headers: nil, **query) ⇒ Boolean

Delete Topic

Examples:

Delete a topic with id equal to 1

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.delete_topic(1)

Parameters:

  • id (String, Integer)

    Topic id

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Returns:

  • (Boolean)

    True if deletion successful, false otherwise.

See Also:



190
191
192
# File 'lib/shikimori/api/v1/topics.rb', line 190

def delete_topic(id, headers: nil, **query)
  rest.delete base_url.join('topics', id.to_s).url, headers: headers, query: query
end

#hot_topics(headers: nil, **query) ⇒ Array<Hash>

Get hot topics

Examples:

Get list of hot topics

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.hot_topics #=> [{ id: 1, ... }, ...]

Parameters:

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Options Hash (**query):

  • :limit (Integer)

    Number of titles per page. Must be a lower or equal that 10

Returns:

  • (Array<Hash>)

    Array of hashes representing topic updates

See Also:



231
232
233
# File 'lib/shikimori/api/v1/topics.rb', line 231

def hot_topics(headers: nil, **query)
  rest.get base_url.join('topics', 'hot').url, headers: headers, query: query
end

#topic(id, headers: nil, **query) ⇒ Hash

Get an topic by id

Examples:

Get topic with id equal to 1

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.topic(1) #=> { id: 1, ... }

Parameters:

  • id (#to_s)

    Topic id

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Returns:

  • (Hash)

    Hash representing topic

See Also:



89
90
91
# File 'lib/shikimori/api/v1/topics.rb', line 89

def topic(id, headers: nil, **query)
  rest.get base_url.join('topics', id.to_s).url, headers: headers, query: query
end

#topics(type: nil, headers: nil, **query) ⇒ Array<Hash>

Get list of topics

Examples:

Get list of topics

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.topics #=> [{ id: 1, ... }, ...]

Parameters:

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Options Hash (**query):

  • :page (Integer)

    Number of page. Must be between 1 and 100000

  • :limit (Integer)

    Number of titles per page. Must be a lower or equal that 30

  • :forum ('all', 'animanga', 'site', 'games', 'vn', 'contests', 'offtopic', 'clubs', 'my_clubs', 'critiques', 'news', 'collections', 'articles', 'cosplay')

    Forum type

  • :linked_id (Integer)

    Linked object ID

  • :linked_type ('Anime', 'Manga', 'Ranobe', 'Character', 'Person', 'Club', 'ClubPage', 'Critique', 'Review', 'Contest', 'CosplayGallery', 'Collection', 'Article')

    Linked object type

  • :type ('topic', 'club_user', 'entry_topic', 'anime', 'article', 'character', 'club_page', 'club', 'collection', 'contest', 'cosplay_gallery', 'manga', 'person', 'ranobe', 'critique', 'review', 'news', 'contest_status')

    Type of topic

Returns:

  • (Array<Hash>)

    Array of hashes representing topics

See Also:



65
66
67
68
69
70
71
# File 'lib/shikimori/api/v1/topics.rb', line 65

def topics(type: nil, headers: nil, **query)
  topic_type = type && TOPIC_TYPES_MAP[type]

  rest.get base_url.join('topics').url, headers: headers, query: query.merge(
    type: topic_type
  ).compact
end

#topics_updates(headers: nil, **query) ⇒ Array<Hash>

Get topics updates

Examples:

Get list of topics updates

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.topics_updates #=> [{ id: 1, ... }, ...]

Parameters:

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Options Hash (**query):

  • :page (Integer)

    Number of page. Must be between 1 and 100000

  • :limit (Integer)

    Number of titles per page. Must be a lower or equal that 30

Returns:

  • (Array<Hash>)

    Array of hashes representing topic updates

See Also:



211
212
213
# File 'lib/shikimori/api/v1/topics.rb', line 211

def topics_updates(headers: nil, **query)
  rest.get base_url.join('topics', 'updates').url, headers: headers, query: query
end

#update_topic(id, topic, headers: nil, **query) ⇒ Hash

Update Topic Requires ‘topics` oauth scope

Examples:

Update a topic

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
topic = {
  body: "text",
  linked_id: "41",
  linked_type: "Anime",
  title: "zxc",
}
client.v1.update_topic(topic)

Parameters:

  • id (#to_s)

    Topic id

  • topic (Hash)

    Topic data for updating

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Options Hash (topic):

  • :title (String)

    Topic title

  • :body (String)

    Topic text

  • :linked_id (Integer)

    ID of linked object to topic

  • :linked_type ('Anime', 'Manga', 'Ranobe', 'Character', 'Person', 'Club', 'ClubPage', 'Critique', 'Review', 'Contest', 'CosplayGallery', 'Collection', 'Article')

    Type of linked object to topic

Returns:

  • (Hash)

    Hash representing updated topic

See Also:



170
171
172
# File 'lib/shikimori/api/v1/topics.rb', line 170

def update_topic(id, topic, headers: nil, **query)
  rest.put base_url.join('topics', id.to_s).url, { topic: topic }, headers: headers, query: query
end