Module: Shikimori::API::V1::Favorites

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

Overview

Methods for the Favorites API

Instance Method Summary collapse

Instance Method Details

#create_favorite(id, type:, person_type: 'person', headers: nil, **query) ⇒ Bool

Add object to favorites

Examples:

Add mangaka with id equal to 1 to favorites

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.create_favorite(1, type: 'person', person_type: 'mangaka')

Add anime with id equal to 1 to favorites

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.create_favorite(1, type: 'anime') #=> { success: true, notice: '...' }

Parameters:

  • id (#to_s)

    Favorite’s object id

  • type ('person', 'anime', 'manga', 'ranobe', 'character')

    Favorite’s object type

  • person_type ('common', 'seyu', 'mangaka', 'producer', 'person') (defaults to: 'person')

    Person type. Required for :type equal to person

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Returns:

  • (Bool)

    True if create a new favorite is successful

See Also:



36
37
38
39
40
41
# File 'lib/shikimori/api/v1/favorites.rb', line 36

def create_favorite(id, type:, person_type: 'person', headers: nil, **query)
  path = creation_favorite_path_by(type.to_s.downcase, id.to_s, person_type)
  rest.post base_url.join('favorites', *path).url, {}, headers: headers, query: query

  true
end

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

Delete Favorite

Examples:

Delete person with id equal to 1 from favorites

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

Delete anime with id equal to 1 from favorites

client = Shikimori::API::Client.new(
  app_name: 'Api Test',
  aceess_token: '****',
  refresh_token: '****'
)
client.v1.delete_favorite(1, type: 'anime') #=> true

Parameters:

  • id (String, Integer)

    Favorite id

  • type ('person', 'anime', 'manga', 'ranobe', 'character')

    Favorite’s object type

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Returns:

  • (Boolean)

    True if deletion successful, false otherwise.

See Also:



67
68
69
70
71
72
# File 'lib/shikimori/api/v1/favorites.rb', line 67

def delete_favorite(id, type:, headers: nil, **query)
  path = deletion_favorite_path_by(type.to_s.downcase, id.to_s)
  rest.delete base_url.join('favorites', *path).url, headers: headers, query: query

  true
end

#reorder_favorite(id, position:, headers: nil, **query) ⇒ Bool

Reorder favorite

Examples:

Reorder favorite with id equal to 1 to 10 position

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

Parameters:

  • id (#to_s)

    Favorite’s id

  • position (Integer)

    New position for favroite. Must be greater or equal than 0

  • headers (Hash) (defaults to: nil)

    Request headers

  • query (Hash)

    Query string parameters for request

Returns:

  • (Bool)

    True if reordering is successful

See Also:



91
92
93
94
95
96
97
98
99
# File 'lib/shikimori/api/v1/favorites.rb', line 91

def reorder_favorite(id, position:, headers: nil, **query)
  rest.post(
    base_url.join('favorites', id.to_s, 'reorder').url,
    { new_index: position },
    headers: headers, query: query
  )

  true
end