Class: Search
- Inherits:
-
Object
- Object
- Search
- Defined in:
- lib/nhentai-api/search.rb
Instance Method Summary collapse
- #count ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(options:, sort: :none, page: 1) ⇒ Search
constructor
A new instance of Search.
- #listing ⇒ Object
- #num_pages ⇒ Object
- #per_page ⇒ Object
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 = @client = Net::HTTP.get_response(URI("https://nhentai.net/api/galleries/search?query=#{}&sort=#{SORT[sort]}&page=#{page}")) return unless exists? @response = JSON.parse(client.body) end |
Instance Method Details
#count ⇒ Object
16 17 18 |
# File 'lib/nhentai-api/search.rb', line 16 def count response['result'].count end |
#exists? ⇒ Boolean
12 13 14 |
# File 'lib/nhentai-api/search.rb', line 12 def exists? client.code == '200' end |
#listing ⇒ Object
28 29 30 |
# File 'lib/nhentai-api/search.rb', line 28 def listing response['result'].map { |doujin| Doujinshi.new(id: doujin) } end |
#num_pages ⇒ Object
20 21 22 |
# File 'lib/nhentai-api/search.rb', line 20 def num_pages response['num_pages'] end |
#per_page ⇒ Object
24 25 26 |
# File 'lib/nhentai-api/search.rb', line 24 def per_page response['per_page'] end |