Sha256: 8e4f4a31b661f42b61b7fd01d74a50abad6b4952b5a0ec1e36a6b5ab6ac095f0

Contents?: true

Size: 780 Bytes

Versions: 8

Compression:

Stored size: 780 Bytes

Contents

module NBS
  
  require 'net/http'
  require 'uri'
  
  class Search
  
    attr_accessor :options, :query, :api_key,:base_url, :xml
      
    def initialize(query, options={})
      self.options = {"query"=>query,"apiKey"=>$nbs_api_key,"format"=>"xml"}.merge(options)
      self.query = query
      self.api_key = api_key
      self.base_url = base_url
    end
    def fetch
      self.xml=Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}search?#{self.options.to_url_params}")).to_s
    end
    def artists
      hash = Hash.from_xml(self.to_xml)
      a = []
      hash["Results"][0]["Result"].each do |item|
       a << Artist.new(item["NBSArtistID"][0],item["NBSArtistName"][0])
      end
      return a
    end
    def to_xml
      self.xml ||=fetch
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
next-big-sound-0.3.5 lib/search.rb
next-big-sound-0.3.4 lib/search.rb
next-big-sound-0.3.3 lib/search.rb
next-big-sound-0.3.2 lib/search.rb
next-big-sound-0.3.1 lib/search.rb
next-big-sound-0.3.0 lib/search.rb
next-big-sound-0.2.0 lib/search.rb
next-big-sound-0.1.2 lib/search.rb