lib/rapgenius.rb in rapgenius-0.1.0 vs lib/rapgenius.rb in rapgenius-1.0.0

- old
+ new

@@ -1,5 +1,42 @@ require 'rapgenius/version' -require 'rapgenius/scraper' -require 'rapgenius/annotation' +require 'rapgenius/client' +require 'rapgenius/line' require 'rapgenius/song' -require 'rapgenius/exceptions' +require 'rapgenius/artist' +require 'rapgenius/media' +require 'rapgenius/exceptions' + +module RapGenius + extend RapGenius::Client + + def self.search(query, options={}) + response = Client::HTTPClient.get("/search", query: {q: query}.merge(options)) + + response["response"]["hits"].map do |song| + result = song["result"] + + Song.new( + id: result["id"], + name: result["name"], + artist: Artist.new( + id: result["primary_artist"]["id"], + name: result["primary_artist"]["name"], + type: :primary + ), + title: result["title"] + ) + end + end + + def self.search_by_artist(query) + self.search(query, field: "primary_artist_name") + end + + def self.search_by_title(query) + self.search(query, field: "title") + end + + def self.search_by_lyrics(query) + self.search(query, field: "lyrics") + end +end \ No newline at end of file