Class: Jikanrb::Resources::CharacterResource

Inherits:
BaseResource show all
Defined in:
lib/jikanrb/resources/character_resource.rb

Overview

Resource class for accessing Character sub-resources from the Jikan API. Provides fluent API access to character details, anime appearances, manga appearances, voice actors, and pictures.

Examples:

Basic usage

client = Jikanrb::Client.new
character = client.character(1)
character.info                  # GET /characters/1
character.info(full: true)      # GET /characters/1/full
character.anime                 # GET /characters/1/anime
character.voices                # GET /characters/1/voices

See Also:

Instance Attribute Summary

Attributes inherited from BaseResource

#id

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from Jikanrb::Resources::BaseResource

Instance Method Details

#animesHash

Returns anime appearances for this character

Examples:

client.character(1).anime
# => { data: [{ role: "Main", anime: { mal_id: 1, title: "..." } }, ...] }

Returns:

  • (Hash)

    List of anime appearances as IndifferentHash



44
45
46
# File 'lib/jikanrb/resources/character_resource.rb', line 44

def animes
  get("characters/#{@id}/anime")
end

#info(full: false) ⇒ Hash

Returns character details

Examples:

Get basic info

client.character(1).info
# => { data: { mal_id: 1, name: "Spike Spiegel", ... } }

Get full info

client.character(1).info(full: true)
# => { data: { mal_id: 1, name: "...", anime: [...], voices: [...] } }

Parameters:

  • full (Boolean) (defaults to: false)

    If true, returns extended information including anime appearances, manga appearances, and voice actors

Returns:

  • (Hash)

    Character data as IndifferentHash



32
33
34
35
# File 'lib/jikanrb/resources/character_resource.rb', line 32

def info(full: false)
  path = full ? "characters/#{@id}/full" : "characters/#{@id}"
  get(path)
end

#mangasHash

Returns manga appearances for this character

Examples:

client.character(1).manga
# => { data: [{ role: "Main", manga: { mal_id: 1, title: "..." } }, ...] }

Returns:

  • (Hash)

    List of manga appearances as IndifferentHash



55
56
57
# File 'lib/jikanrb/resources/character_resource.rb', line 55

def mangas
  get("characters/#{@id}/manga")
end

#picturesHash

Returns pictures of this character

Examples:

client.character(1).pictures
# => { data: [{ jpg: { image_url: "https://..." } }, ...] }

Returns:

  • (Hash)

    List of pictures as IndifferentHash



77
78
79
# File 'lib/jikanrb/resources/character_resource.rb', line 77

def pictures
  get("characters/#{@id}/pictures")
end

#voicesHash

Returns voice actors for this character

Examples:

client.character(1).voices
# => { data: [{ language: "Japanese", person: { mal_id: 11, name: "..." } }, ...] }

Returns:

  • (Hash)

    List of voice actors as IndifferentHash



66
67
68
# File 'lib/jikanrb/resources/character_resource.rb', line 66

def voices
  get("characters/#{@id}/voices")
end