Class: Tinysong::Search
- Inherits:
-
Struct
- Object
- Struct
- Tinysong::Search
- Defined in:
- lib/tinysong/search.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#search ⇒ Object
Returns the value of attribute search.
Class Method Summary collapse
-
.all(search, options = {}) ⇒ Object
Search and return all songs.
-
.find(search) ⇒ Object
Search and return first result.
Instance Method Summary collapse
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount
8 9 10 |
# File 'lib/tinysong/search.rb', line 8 def amount @amount end |
#search ⇒ Object
Returns the value of attribute search
8 9 10 |
# File 'lib/tinysong/search.rb', line 8 def search @search end |
Class Method Details
Instance Method Details
#perform ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/tinysong/search.rb', line 31 def perform res = JSON.parse(RestClient.post("http://tinysong.com/?s=s", {q: [search, 0]})) res = Nokogiri::HTML(res["html"]).css("ul.result") res.take(limit(res)).map do |result| song_id = result.attr("rel").match(/^(\d+)/).to_a.last res = JSON.parse(RestClient.post("http://tinysong.com/?s=sh", {q: [song_id, "search", search]})) build(Nokogiri::HTML(res["message"]), song_id) end end |