Module: Shikimori::API::V1::Comments

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

Overview

Methods for the Comments API

Instance Method Summary collapse

Instance Method Details

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

Get a comment by id

Examples:

Get a comment with id equal to 1

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

Parameters:

  • id (#to_s)

    Comment id

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Returns:

  • (Hash)

    Hash representing comment

Raises:

See Also:



55
56
57
# File 'lib/shikimori/api/v1/comments.rb', line 55

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

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

Get list of comments

Examples:

Get a 10 comments for topic with id equal to 1

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.comments(commentable_id: 1, commentable_type: 'Topic', limit: 10) #=> [{ 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 comments per page. Must be a lower or equal that 30

  • :desc (1, 0)

    Sorting direction

  • :commentable_id (Integer)

    ID of object to comments requested

  • :commentable_type ('Topic', 'User')

    Type of object to comments requested

Returns:

  • (Array<Hash>)

    Array of hashes representing comments

Raises:

See Also:



33
34
35
# File 'lib/shikimori/api/v1/comments.rb', line 33

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

#create_comment(comment, broadcast: nil, frontend: nil, headers: nil, **query) ⇒ Hash

Create a comment Requires ‘comments` oauth scope

Examples:

Create a comment for topic with id equal to 1

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.create_comment({ body: 'Hello, kitty! :)', commentable_type: 'Topic', commentable_id: 1 })

Parameters:

  • comment (Hash)

    Comment data for creating

  • broadcast ('false', 'true', 1, 0) (defaults to: nil)

    Used to broadcast comment in club’s topic. Only club admins can broadcast.

  • frontend ('false', 'true', 1, 0) (defaults to: nil)

    Used by shikimori frontend code. Ignore it.

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Options Hash (comment):

  • :body (String)

    Comment text

  • :commentable_id (Integer)

    ID of object to comment

  • :commentable_type ('Topic', 'User', 'Anime', 'Manga', 'Character', 'Person', 'Article', 'Club', 'ClubPage', 'Collection', 'Critique', 'Review')

    Type of object to comment

  • :is_offtopic ('true', 'false', 1, 0)

    Mark comment as offtopic

Returns:

  • (Hash)

    Hash representing created comment

Raises:

See Also:



89
90
91
92
93
94
95
# File 'lib/shikimori/api/v1/comments.rb', line 89

def create_comment(comment, broadcast: nil, frontend: nil, headers: nil, **query)
  rest.post(
    base_url.join('comments').url,
    { broadcast: broadcast, comment: comment, frontend: frontend }.compact,
    headers: headers, query: query
  )
end

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

Delete Comment. Requires ‘comments` oauth scope

Examples:

Delete a comment with id equal to 1

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

Parameters:

  • id (String, Integer)

    Comment id

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Returns:

  • (Boolean)

    True if deletion successful, false otherwise.

Raises:

See Also:



155
156
157
# File 'lib/shikimori/api/v1/comments.rb', line 155

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

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

Update Comment. Requires ‘comments` oauth scope. Use Shikimori::API::V2::AbuseRequests#abuse_offtopic_request to change is_offtopic field.

Examples:

Update a comment’s text with id equal to 1

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.update_comment(1, { body: "new text!" })

Parameters:

  • id (#to_s)

    Comment id

  • comment (Hash)

    Comment data for updating

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Options Hash (comment):

  • :body (String)

    Comment text

  • :commentable_id (Integer)

    ID of object to comment

  • :commentable_type ('Topic', 'User', 'Anime', 'Manga', 'Character', 'Person', 'Article', 'Club', 'ClubPage', 'Collection', 'Critique', 'Review')

    Type of object to comment

Options Hash (**query):

  • :broadcast ('false', 'true', 1, 0)

    Used to broadcast comment in club’s topic. Only club admins can broadcast.

  • :frontend ('false', 'true', 1, 0)

    Used by shikimori frontend code. Ignore it.

Returns:

  • (Hash)

    Hash representing updated comment

Raises:

See Also:



128
129
130
131
132
133
134
# File 'lib/shikimori/api/v1/comments.rb', line 128

def update_comment(id, comment, headers: nil, **query)
  rest.put(
    base_url.join('comments', id.to_s).url,
    { broadcast: query.delete(:broadcast), comment: comment, frontend: query.delete(:frontend) }.compact,
    headers: headers, query: query
  )
end