Class: Search

Inherits:
Object
  • Object
show all
Defined in:
lib/nhentai-api/search.rb

Instance Method Summary collapse

Constructor Details

#initialize(options:, sort: :none, page: 1) ⇒ Search

Returns a new instance of Search.



4
5
6
7
8
9
10
# File 'lib/nhentai-api/search.rb', line 4

def initialize(options:, sort: :none, page: 1)
  @options = options
  @client = Net::HTTP.get_response(URI("https://nhentai.net/api/galleries/search?query=#{string_options}&sort=#{SORT[sort]}&page=#{page}"))
  return unless exists?

  @response = JSON.parse(client.body)
end

Instance Method Details

#countObject



16
17
18
# File 'lib/nhentai-api/search.rb', line 16

def count
  response['result'].count
end

#exists?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/nhentai-api/search.rb', line 12

def exists?
  client.code == '200'
end

#listingObject



28
29
30
# File 'lib/nhentai-api/search.rb', line 28

def listing
  response['result'].map { |doujin| Doujinshi.new(id: doujin) }
end

#num_pagesObject



20
21
22
# File 'lib/nhentai-api/search.rb', line 20

def num_pages
  response['num_pages']
end

#per_pageObject



24
25
26
# File 'lib/nhentai-api/search.rb', line 24

def per_page
  response['per_page']
end