Module: Shikimori::API::V1::Messages

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

Overview

Methods for the Messages API

Instance Method Summary collapse

Instance Method Details

#create_message(message, frontend: nil, headers: nil, **query) ⇒ Hash

Create a message Requires ‘messages` oauth scope

Examples:

Send message by user with id 1 to user with 2

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.create_message({ body: 'Hello, kitty! :)', from_id: 1, to_id: 2, kind: 'Private' })

Parameters:

  • message (Hash)

    Message data for creating

  • 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 (message):

  • :body (String)

    message text

  • :from_id (Integer)

    user id, that sending a message

  • :to_id (Integer)

    user id, that receiving a message

  • :kind ('Private')

    message type

Returns:

  • (Hash)

    Hash representing created message

See Also:



53
54
55
56
57
58
59
# File 'lib/shikimori/api/v1/messages.rb', line 53

def create_message(message, frontend: nil, headers: nil, **query)
  rest.post(
    base_url.join('messages').url,
    { message: message, frontend: frontend }.compact,
    headers: headers, query: query
  )
end

#delete_all_messages(type:, frontend: nil, headers: nil, **query) ⇒ Hash

Delete all messages by type Requires ‘messages` oauth scope

Examples:

Delete all notifications

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.delete_all_messages(type: 'notifications')

Parameters:

  • type ('news', 'notifications')

    Type of messages to delete

  • 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

Returns:

  • (Hash)

    Hash representing of deleted messages

See Also:



156
157
158
159
160
161
162
163
164
# File 'lib/shikimori/api/v1/messages.rb', line 156

def delete_all_messages(type:, frontend: nil, headers: nil, **query)
  rest.post(
    base_url.join('messages', 'delete_all').url,
    { type: type, frontend: frontend }.compact,
    headers: headers, query: query
  )

  true
end

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

Delete message. Requires ‘messages` oauth scope

Examples:

Delete a message with id equal to 1

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

Parameters:

  • id (String, Integer)

    message 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:



106
107
108
# File 'lib/shikimori/api/v1/messages.rb', line 106

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

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

Get a message by id.

Requires ‘messages` oauth scope

Examples:

Get a message with id equal to 1

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

Parameters:

  • id (#to_s)

    message id

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Returns:

  • (Hash)

    Hash representing message

See Also:



27
28
29
# File 'lib/shikimori/api/v1/messages.rb', line 27

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

#read_all_messages(type:, frontend: nil, headers: nil, **query) ⇒ Hash

Mark all messages as read by type Requires ‘messages` oauth scope

Examples:

Read all notifications

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.read_all_messages(type: 'notifications')

Parameters:

  • type ('news', 'notifications')

    Type of messages to read

  • 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

Returns:

  • (Hash)

    Hash representing of readed messages

See Also:



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

def read_all_messages(type:, frontend: nil, headers: nil, **query)
  rest.post(
    base_url.join('messages', 'read_all').url,
    { type: type, frontend: frontend }.compact,
    headers: headers, query: query
  )

  true
end

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

Update message. Requires ‘messages` oauth scope

Examples:

Update a message’s text with id equal to 1

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

Parameters:

  • id (#to_s)

    message id

  • message (Hash)

    message data for updating

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Options Hash (message):

  • :body (String)

    message text

Options Hash (**query):

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

    Used by shikimori frontend code. Ignore it.

Returns:

  • (Hash)

    Hash representing updated message

See Also:



81
82
83
84
85
86
87
# File 'lib/shikimori/api/v1/messages.rb', line 81

def update_message(id, message, headers: nil, **query)
  rest.put(
    base_url.join('messages', id.to_s).url,
    { message: message, frontend: query.delete(:frontend) }.compact,
    headers: headers, query: query
  )
end