Class: UnderFire::Client
- Inherits:
-
Object
- Object
- UnderFire::Client
- Includes:
- UnderFire
- Defined in:
- lib/under_fire/client.rb
Overview
Public interface to UnderFire’s functionality.
Constant Summary
Constants included from UnderFire
Instance Attribute Summary collapse
-
#api_url ⇒ String
readonly
API URL for application.
Instance Method Summary collapse
-
#fetch_album(args) ⇒ APIResponse
Fetches album with given album :gn_id or track :gn_id.
-
#fetch_cover(response, file_name) ⇒ Object
Fetches cover art using results of query.
-
#find_album(args) ⇒ APIResponse
Finds album using one or more of :artist, :track_title and :album_title.
-
#find_by_toc(*offsets) ⇒ APIResponse
Searches for album using provided toc offsets.
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#register(client_id) ⇒ APIResponse
Registers user with given client_id.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
25 26 27 |
# File 'lib/under_fire/client.rb', line 25 def initialize @api_url = Configuration.instance.api_url end |
Instance Attribute Details
#api_url ⇒ String (readonly)
Returns API URL for application.
23 24 25 |
# File 'lib/under_fire/client.rb', line 23 def api_url @api_url end |
Instance Method Details
#fetch_album(args) ⇒ APIResponse
Fetches album with given album :gn_id or track :gn_id
51 52 53 54 55 |
# File 'lib/under_fire/client.rb', line 51 def fetch_album(args) search = AlbumFetch.new(args) response = APIRequest.post(search.query, api_url) APIResponse.new(response.body) end |
#fetch_cover(response, file_name) ⇒ Object
Fetches cover art using results of query.
68 69 70 71 72 73 74 75 |
# File 'lib/under_fire/client.rb', line 68 def fetch_cover(response, file_name) res = response.to_h response_url = res['RESPONSE']['ALBUM']['URL'] title = res['RESPONSE']['ALBUM']['TITLE'] file_name = file_name || "#{title}-cover.jpg" APIRequest.get_file(response_url, filename) end |
#find_album(args) ⇒ APIResponse
Finds album using one or more of :artist, :track_title and :album_title
42 43 44 45 46 |
# File 'lib/under_fire/client.rb', line 42 def find_album(args) search = AlbumSearch.new(args) response = APIRequest.post(search.query, api_url) APIResponse.new(response.body) end |
#find_by_toc(*offsets) ⇒ APIResponse
Searches for album using provided toc offsets.
32 33 34 35 36 37 |
# File 'lib/under_fire/client.rb', line 32 def find_by_toc(*offsets) offsets = offsets.join(" ") search = AlbumTOCSearch.new(:toc => offsets) response = APIRequest.post(search.query, api_url) APIResponse.new(response.body) end |
#register(client_id) ⇒ APIResponse
Registers user with given client_id
60 61 62 63 64 |
# File 'lib/under_fire/client.rb', line 60 def register(client_id) search = Registration.new(client_id) response = APIRequest.post(search.query, api_url) APIResponse.new(response.body) end |