Class: LastFM::Query
- Inherits:
-
Object
- Object
- LastFM::Query
- Defined in:
- lib/last_fm/query.rb
Class Method Summary collapse
-
.get_info(args = {}) ⇒ Object
Query.get_info(‘album.get_info’, artist, album).
- .retrieve_from_api(args = {}) ⇒ Object
- .search(args = {}) ⇒ Object
Class Method Details
.get_info(args = {}) ⇒ Object
Query.get_info(‘album.get_info’, artist, album)
28 29 30 31 32 33 34 35 |
# File 'lib/last_fm/query.rb', line 28 def get_info(args={}) parsed_results = retrieve_from_api(args) if parsed_results['album'] Album.new(parsed_results['album']) else nil end end |
.retrieve_from_api(args = {}) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/last_fm/query.rb', line 4 def retrieve_from_api(args={}) response = connection.get('/2.0/', { api_key: LastFM.api_key, format: 'json' }.merge(args)) parsed_results = JSON.parse(response.body) end |
.search(args = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/last_fm/query.rb', line 13 def search(args={}) type = args[:method].split('.').first.downcase parsed_results = retrieve_from_api(args) type_matches = type + 'matches' if parsed_results['results'] && parsed_results['results'][type_matches] parsed_results['results'][type_matches][type].map do |attributes| LastFM.const_get(type.capitalize).new(attributes) end else [] end end |