Class: Gracenote
- Inherits:
-
Object
- Object
- Gracenote
- Defined in:
- lib/gracenote.rb
Constant Summary collapse
- @@ALL_RESULTS =
class variables
'1'
- @@BEST_MATCH_ONLY =
'0'
Instance Method Summary collapse
-
#albumToc(toc) ⇒ Object
Function: albumToc Fetches album metadata based on a table of contents.
-
#fetchOETData(gn_id) ⇒ Object
Function: fetchOETData Gets data based on gn_id Arguments: gn_id.
-
#findAlbum(artistName, albumTitle, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findAlbum finds an Album Arguments: artistName albumTitle trackTitle matchMode.
-
#findArtist(artistName, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findArtist Finds a Artist Arguments: artistName matchMode.
-
#findTrack(artistName, albumTitle, trackTitle, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findTrack Finds a track Arguments: artistName albumTitle trackTitle matchMode.
-
#initialize(spec) ⇒ Gracenote
constructor
Function: initialize Sets the following instance variables clientID clientTag userID apiURL.
-
#registerUser(clientID = nil) ⇒ Object
Function: registerUser Registers a user and returns userID.
Constructor Details
#initialize(spec) ⇒ Gracenote
Function: initialize Sets the following instance variables
clientID
clientTag
userID
apiURL
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gracenote.rb', line 16 def initialize (spec) if(spec[:clientID].nil? || spec[:clientID] == "") raise "clientID cannot be nil" end if(spec[:clientTag].nil? || spec[:clientTag] == "") raise "clientTag cannot be nil" end @clientID = spec[:clientID] @clientTag = spec[:clientTag] @userID = spec[:userID].nil? ? nil : spec[:userID] @apiURL = "https://c" + @clientID + ".web.cddbp.net/webapi/xml/1.0/" end |
Instance Method Details
#albumToc(toc) ⇒ Object
Function: albumToc Fetches album metadata based on a table of contents. Arguments:
toc
98 99 100 101 102 103 104 105 |
# File 'lib/gracenote.rb', line 98 def albumToc(toc) if @userID == nil registerUser end body = "<TOC><OFFSETS>" + toc + "</OFFSETS></TOC>" data = constructQueryBody(body, "ALBUM_TOC") return api(data) end |
#fetchOETData(gn_id) ⇒ Object
Function: fetchOETData Gets data based on gn_id Arguments:
gn_id
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/gracenote.rb', line 111 def fetchOETData(gn_id) if @userID == nil registerUser end body = "<GN_ID>" + gn_id + "</GN_ID> <OPTION> <PARAMETER>SELECT_EXTENDED</PARAMETER> <VALUE>ARTIST_OET</VALUE> </OPTION> <OPTION> <PARAMETER>SELECT_DETAIL</PARAMETER> <VALUE>ARTIST_ORIGIN:4LEVEL,ARTIST_ERA:2LEVEL,ARTIST_TYPE:2LEVEL</VALUE> </OPTION>" data = constructQueryReq(body, "ALBUM_FETCH") resp = HTTP.post(@apiURL, data) resp = checkRES resp json = resp["RESPONSES"] output = Array.new() output[:artist_origin] = json["RESPONSE"]["ALBUM"]["ARTIST_ORIGIN"].nil? ? "" : _getOETElem(json["RESPONSE"]["ALBUM"]["ARTIST_ORIGIN"]) output[:artist_era] = json["RESPONSE"]["ALBUM"]["ARTIST_ERA"].nil? ? "" : _getOETElem(json["RESPONSE"]["ALBUM"]["ARTIST_ERA"]) output[:artist_type] = json["RESPONSE"]["ALBUM"]["ARTIST_TYPE"].nil? ? "" : _getOETElem(json["RESPONSE"]["ALBUM"]["ARTIST_TYPE"]) return output end |
#findAlbum(artistName, albumTitle, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findAlbum finds an Album Arguments:
artistName
albumTitle
trackTitle
matchMode
90 91 92 |
# File 'lib/gracenote.rb', line 90 def findAlbum(artistName, albumTitle, matchMode = @@ALL_RESULTS) return findTrack(artistName, albumTitle, "", matchMode) end |
#findArtist(artistName, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findArtist Finds a Artist Arguments:
artistName
matchMode
79 80 81 |
# File 'lib/gracenote.rb', line 79 def findArtist(artistName, matchMode = @@ALL_RESULTS) return findTrack(artistName, "", "", matchMode) end |
#findTrack(artistName, albumTitle, trackTitle, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findTrack Finds a track Arguments:
artistName
albumTitle
trackTitle
matchMode
65 66 67 68 69 70 71 72 |
# File 'lib/gracenote.rb', line 65 def findTrack(artistName, albumTitle, trackTitle, matchMode = @@ALL_RESULTS) if @userID == nil registerUser end body = constructQueryBody(artistName, albumTitle, trackTitle, "", "ALBUM_SEARCH", matchMode) data = constructQueryReq(body) return api(data); end |
#registerUser(clientID = nil) ⇒ Object
Function: registerUser Registers a user and returns userID
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gracenote.rb', line 35 def registerUser (clientID = nil) if(clientID.nil?) clientID = @clientID + "-" + @clientTag end if not @userID.nil? p "user already registered. No need to register again" return @userID end #send req to server and get user ID data = "<QUERIES> <QUERY CMD='REGISTER'> <CLIENT>"+ clientID +"</CLIENT> </QUERY> </QUERIES>" resp = HTTP.post(@apiURL, data) resp = checkRES resp @userID = resp['RESPONSES']['RESPONSE']['USER'] return @userID end |