Sha256: 698581415ec877a974f11dd0e78f89c2dd44d3352577b3293f492aba6f5c2717

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

warn "[rapgenius] The RapGenius gem is now deprecated in favour of the more powerful " \
     "and more robust Genius gem. See https://github.com/timrogers/genius for more " \
     "details."

require 'rapgenius/version'
require 'rapgenius/client'
require 'rapgenius/line'
require 'rapgenius/song'
require 'rapgenius/artist'
require 'rapgenius/media'
require 'rapgenius/exceptions'

module RapGenius
  extend RapGenius::Client

  def self.search(query, options = {})
    response = fetch(build_api_url("/search"), { 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rapgenius-1.1.2 lib/rapgenius.rb