Module: Genius::Search
- Defined in:
- lib/genius/api/search.rb
Overview
Genius::Search
module provides methods to work with Genius search database
Class Method Summary collapse
-
.search(token: nil, query: nil, search_by: nil) ⇒ String, ...
Genius::Search.search
-> NilClass.
Class Method Details
.search(token: nil, query: nil, search_by: nil) ⇒ String, ...
Genius::Search.search
-> NilClass
@todo: refactor example group in method documentation This method is a standard Genius API method and it is needed to send a request to the server and get information about artists, tracks and everything else that may be inside the response body. According to docs.genius.com/#search-h2, token is required to be in response, but you can use this method without use of it! =)
Also, you can use this method with search_by
param, which is needed to search interested data through returned JSON
. It uses deep_find
extension under the hood.
37 38 39 40 41 42 43 44 45 |
# File 'lib/genius/api/search.rb', line 37 def search(token: nil, query: nil, search_by: nil) return if token.nil? && !Auth..nil? Errors.validate_token(token) unless token.nil? response = HTTParty.get("#{Api::RESOURCE}/search?q=#{query}&access_token=#{token_ext(token)}").body search = JSON.parse(response) search_by ? search.deep_find(search_by) : search end |