Class: UnderFire::Client

Inherits:
Object
  • Object
show all
Includes:
UnderFire
Defined in:
lib/under_fire/client.rb

Overview

Public interface to UnderFire’s functionality.

Examples:

client = UnderFire::Client.new
client.album_search(:artist => 'Miles Davis') #=> lots of results

client = UnderFire::Client.new
client.find_by_toc space_delimited_toc_offsets

Constant Summary

Constants included from UnderFire

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

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_urlString (readonly)

Returns API URL for application.

Returns:

  • (String)

    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

Returns:

See Also:



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.

Parameters:



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

Returns:

See Also:



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.

Returns:

See Also:



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

Returns:

See Also:



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