Class: Jikanrb::Client
- Inherits:
-
Object
- Object
- Jikanrb::Client
- Defined in:
- lib/jikanrb/client.rb
Overview
Main HTTP client for interacting with the Jikan API v4. Handles requests, rate limiting, retries, and error handling.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#anime(id) ⇒ Resources::AnimeResource
Returns an AnimeResource for fluent API access to anime sub-resources.
-
#character(id) ⇒ Resources::CharacterResource
Returns a CharacterResource for fluent API access to character sub-resources.
-
#get(path, params = {}) ⇒ Hash
Performs a GET request.
-
#initialize {|config| ... } ⇒ Client
constructor
Initializes the client with optional configuration.
-
#manga(id) ⇒ Resources::MangaResource
Returns a MangaResource for fluent API access to manga sub-resources.
-
#paginate(method, **params) ⇒ Pagination::Paginator
Create a paginator for iterating through all pages of a paginated endpoint.
-
#pagination_info(response) ⇒ Pagination::PaginationInfo
Extract pagination information from a response.
-
#person(id) ⇒ Resources::PersonResource
Returns a PersonResource for fluent API access to person sub-resources.
-
#schedules(day: nil) ⇒ Hash
Weekly schedule.
-
#search_anime(query, **params) ⇒ Hash
Search anime.
-
#search_manga(query, **params) ⇒ Hash
Search manga.
-
#season(year, season, page: 1) ⇒ Hash
Seasonal anime.
-
#season_now(page: 1) ⇒ Hash
Current season.
-
#top_anime(type: nil, filter: nil, page: 1) ⇒ Hash
Top anime.
-
#top_manga(type: nil, filter: nil, page: 1) ⇒ Hash
Top manga.
Constructor Details
#initialize {|config| ... } ⇒ Client
Initializes the client with optional configuration
36 37 38 39 |
# File 'lib/jikanrb/client.rb', line 36 def initialize @config = Configuration.new yield(@config) if block_given? end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
21 22 23 |
# File 'lib/jikanrb/client.rb', line 21 def config @config end |
Instance Method Details
#anime(id) ⇒ Resources::AnimeResource
Returns an AnimeResource for fluent API access to anime sub-resources
67 68 69 |
# File 'lib/jikanrb/client.rb', line 67 def anime(id) Resources::AnimeResource.new(self, id) end |
#character(id) ⇒ Resources::CharacterResource
Returns a CharacterResource for fluent API access to character sub-resources
109 110 111 |
# File 'lib/jikanrb/client.rb', line 109 def character(id) Resources::CharacterResource.new(self, id) end |
#get(path, params = {}) ⇒ Hash
Performs a GET request
46 47 48 |
# File 'lib/jikanrb/client.rb', line 46 def get(path, params = {}) request(:get, path, params) end |
#manga(id) ⇒ Resources::MangaResource
Returns a MangaResource for fluent API access to manga sub-resources
88 89 90 |
# File 'lib/jikanrb/client.rb', line 88 def manga(id) Resources::MangaResource.new(self, id) end |
#paginate(method, **params) ⇒ Pagination::Paginator
Create a paginator for iterating through all pages of a paginated endpoint
221 222 223 |
# File 'lib/jikanrb/client.rb', line 221 def paginate(method, **params) Pagination::Paginator.new(self, method, **params) end |
#pagination_info(response) ⇒ Pagination::PaginationInfo
Extract pagination information from a response
234 235 236 |
# File 'lib/jikanrb/client.rb', line 234 def pagination_info(response) Pagination::PaginationInfo.new(response) end |
#person(id) ⇒ Resources::PersonResource
Returns a PersonResource for fluent API access to person sub-resources
130 131 132 |
# File 'lib/jikanrb/client.rb', line 130 def person(id) Resources::PersonResource.new(self, id) end |
#schedules(day: nil) ⇒ Hash
Weekly schedule
200 201 202 203 |
# File 'lib/jikanrb/client.rb', line 200 def schedules(day: nil) path = day ? "schedules/#{day}" : 'schedules' get(path) end |
#search_anime(query, **params) ⇒ Hash
Search anime
139 140 141 |
# File 'lib/jikanrb/client.rb', line 139 def search_anime(query, **params) get('anime', params.merge(q: query)) end |
#search_manga(query, **params) ⇒ Hash
Search manga
148 149 150 |
# File 'lib/jikanrb/client.rb', line 148 def search_manga(query, **params) get('manga', params.merge(q: query)) end |
#season(year, season, page: 1) ⇒ Hash
Seasonal anime
184 185 186 |
# File 'lib/jikanrb/client.rb', line 184 def season(year, season, page: 1) get("seasons/#{year}/#{season}", page: page) end |
#season_now(page: 1) ⇒ Hash
Current season
192 193 194 |
# File 'lib/jikanrb/client.rb', line 192 def season_now(page: 1) get('seasons/now', page: page) end |
#top_anime(type: nil, filter: nil, page: 1) ⇒ Hash
Top anime
158 159 160 161 162 163 |
# File 'lib/jikanrb/client.rb', line 158 def top_anime(type: nil, filter: nil, page: 1) params = { page: page } params[:type] = type if type params[:filter] = filter if filter get('top/anime', params) end |
#top_manga(type: nil, filter: nil, page: 1) ⇒ Hash
Top manga
171 172 173 174 175 176 |
# File 'lib/jikanrb/client.rb', line 171 def top_manga(type: nil, filter: nil, page: 1) params = { page: page } params[:type] = type if type params[:filter] = filter if filter get('top/manga', params) end |