Sha256: 03fd7d840d018356c2a21b0c827380dde1a5e6eb47afc17f2b6de45925f86853

Contents?: true

Size: 894 Bytes

Versions: 1

Compression:

Stored size: 894 Bytes

Contents

module NBS
  
  require 'net/http'
  require 'uri'
  
  class Search
    
    #extend NBS::MemcachedMemoize
    
    
    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 = []
      begin
        hash["Results"][0]["Result"].each do |item|
          a << Artist.new(item["NBSArtistID"][0],item["NBSArtistName"][0])
        end
      rescue
      end
      return a
    end
    def to_xml
      self.xml ||=fetch
    end
    
    #remember :fetch
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
next-big-sound-0.4.2 lib/search.rb