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, full: false) ⇒ Hash
Anime information by ID.
-
#character(id, full: false) ⇒ Hash
Character information by ID.
-
#get(path, params = {}) ⇒ Hash
Performs a GET request.
-
#initialize {|config| ... } ⇒ Client
constructor
Initializes the client with optional configuration.
-
#manga(id, full: false) ⇒ Hash
Manga information by ID.
-
#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, full: false) ⇒ Hash
Person information by ID.
-
#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, full: false) ⇒ Hash
Anime information by ID
55 56 57 58 |
# File 'lib/jikanrb/client.rb', line 55 def anime(id, full: false) path = full ? "/anime/#{id}/full" : "/anime/#{id}" get(path) end |
#character(id, full: false) ⇒ Hash
Character information by ID
75 76 77 78 |
# File 'lib/jikanrb/client.rb', line 75 def character(id, full: false) path = full ? "/characters/#{id}/full" : "/characters/#{id}" get(path) 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, full: false) ⇒ Hash
Manga information by ID
65 66 67 68 |
# File 'lib/jikanrb/client.rb', line 65 def manga(id, full: false) path = full ? "/manga/#{id}/full" : "/manga/#{id}" get(path) end |
#paginate(method, **params) ⇒ Pagination::Paginator
Create a paginator for iterating through all pages of a paginated endpoint
177 178 179 |
# File 'lib/jikanrb/client.rb', line 177 def paginate(method, **params) Pagination::Paginator.new(self, method, **params) end |
#pagination_info(response) ⇒ Pagination::PaginationInfo
Extract pagination information from a response
190 191 192 |
# File 'lib/jikanrb/client.rb', line 190 def pagination_info(response) Pagination::PaginationInfo.new(response) end |
#person(id, full: false) ⇒ Hash
Person information by ID
85 86 87 88 |
# File 'lib/jikanrb/client.rb', line 85 def person(id, full: false) path = full ? "/people/#{id}/full" : "/people/#{id}" get(path) end |
#schedules(day: nil) ⇒ Hash
Weekly schedule
156 157 158 159 |
# File 'lib/jikanrb/client.rb', line 156 def schedules(day: nil) path = day ? "/schedules/#{day}" : '/schedules' get(path) end |
#search_anime(query, **params) ⇒ Hash
Search anime
95 96 97 |
# File 'lib/jikanrb/client.rb', line 95 def search_anime(query, **params) get('/anime', params.merge(q: query)) end |
#search_manga(query, **params) ⇒ Hash
Search manga
104 105 106 |
# File 'lib/jikanrb/client.rb', line 104 def search_manga(query, **params) get('/manga', params.merge(q: query)) end |
#season(year, season, page: 1) ⇒ Hash
Seasonal anime
140 141 142 |
# File 'lib/jikanrb/client.rb', line 140 def season(year, season, page: 1) get("/seasons/#{year}/#{season}", page: page) end |
#season_now(page: 1) ⇒ Hash
Current season
148 149 150 |
# File 'lib/jikanrb/client.rb', line 148 def season_now(page: 1) get('/seasons/now', page: page) end |
#top_anime(type: nil, filter: nil, page: 1) ⇒ Hash
Top anime
114 115 116 117 118 119 |
# File 'lib/jikanrb/client.rb', line 114 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
127 128 129 130 131 132 |
# File 'lib/jikanrb/client.rb', line 127 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 |