Class: NBS::Search
- Inherits:
-
Object
- Object
- NBS::Search
- Defined in:
- lib/next-big-sound/search.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#options ⇒ Object
Returns the value of attribute options.
-
#query ⇒ Object
Returns the value of attribute query.
-
#xml ⇒ Object
Returns the value of attribute xml.
Instance Method Summary collapse
-
#artists(options = {}) ⇒ Object
puts self.xml.
- #fetch ⇒ Object
-
#initialize(query, options = {}) ⇒ Search
constructor
A new instance of Search.
- #to_xml ⇒ Object
Constructor Details
#initialize(query, options = {}) ⇒ Search
Returns a new instance of Search.
10 11 12 13 14 15 |
# File 'lib/next-big-sound/search.rb', line 10 def initialize(query, ={}) self. = {"q"=>query,"format"=>"xml"}.merge() self.query = query self.api_key = api_key self.base_url = base_url end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/next-big-sound/search.rb', line 8 def api_key @api_key end |
#base_url ⇒ Object
Returns the value of attribute base_url.
8 9 10 |
# File 'lib/next-big-sound/search.rb', line 8 def base_url @base_url end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/next-big-sound/search.rb', line 8 def @options end |
#query ⇒ Object
Returns the value of attribute query.
8 9 10 |
# File 'lib/next-big-sound/search.rb', line 8 def query @query end |
#xml ⇒ Object
Returns the value of attribute xml.
8 9 10 |
# File 'lib/next-big-sound/search.rb', line 8 def xml @xml end |
Instance Method Details
#artists(options = {}) ⇒ Object
puts self.xml
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/next-big-sound/search.rb', line 21 def artists(={}) hash = Hash.from_xml(self.to_xml) a = [] #puts hash.inspect begin hash["data"][0]["artists"][0]["artist"].each do |item| a << NBS::Artist.new(item["id"],item["name"][0],) end rescue end return a end |
#fetch ⇒ Object
16 17 18 19 20 |
# File 'lib/next-big-sound/search.rb', line 16 def fetch puts "#{$nbs_api_key}artists/search?#{self..to_url_params}" self.xml=Net::HTTP.get(URI.parse("#{$nbs_api_key}artists/search.#{self.["format"]}?#{self..to_url_params}")).to_s #puts self.xml end |
#to_xml ⇒ Object
33 34 35 |
# File 'lib/next-big-sound/search.rb', line 33 def to_xml self.xml ||=fetch end |