Class: Gracenote
- Inherits:
-
Object
- Object
- Gracenote
- Defined in:
- lib/gracenote.rb,
lib/gracenote/HTTP.rb
Defined Under Namespace
Classes: HTTP
Constant Summary collapse
- @@ALL_RESULTS =
class variables
'1'
- @@BEST_MATCH_ONLY =
'0'
Instance Attribute Summary collapse
-
#apiURL ⇒ Object
Returns the value of attribute apiURL.
-
#clientID ⇒ Object
Returns the value of attribute clientID.
-
#clientTag ⇒ Object
Returns the value of attribute clientTag.
-
#userID ⇒ Object
Returns the value of attribute userID.
Instance Method Summary collapse
-
#albumToc(toc) ⇒ Object
Function: albumToc Fetches album metadata based on a table of contents.
-
#fetchContributor(gn_id) ⇒ Object
Function: fetchContributor Fetches details of a contributor from gn_id Arguments: gn_id.
-
#fetchOETData(gn_id) ⇒ Object
Function: fetchOETData Gets data based on gn_id Arguments: gn_id.
-
#fetchSeason(gn_id) ⇒ Object
Function: fetchSeason Fetches details of a season from gn_id Arguments: gn_id.
-
#fetchTVShow(gn_id) ⇒ Object
Function: fetchTVShow Fetches details of TV Show from 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.
-
#findContributor(name) ⇒ Object
Function: findContributor Find details of a contributor from name Arguments: name.
-
#findTrack(artistName, albumTitle, trackTitle, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findTrack Finds a track Arguments: artistName albumTitle trackTitle matchMode.
-
#findTVShow(name, single = true) ⇒ Object
Function: findTVShow Finds TVShows which matches the name Arguments: name single.
-
#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
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gracenote.rb', line 18 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 Attribute Details
#apiURL ⇒ Object
Returns the value of attribute apiURL.
10 11 12 |
# File 'lib/gracenote.rb', line 10 def apiURL @apiURL end |
#clientID ⇒ Object
Returns the value of attribute clientID.
10 11 12 |
# File 'lib/gracenote.rb', line 10 def clientID @clientID end |
#clientTag ⇒ Object
Returns the value of attribute clientTag.
10 11 12 |
# File 'lib/gracenote.rb', line 10 def clientTag @clientTag end |
#userID ⇒ Object
Returns the value of attribute userID.
10 11 12 |
# File 'lib/gracenote.rb', line 10 def userID @userID end |
Instance Method Details
#albumToc(toc) ⇒ Object
Function: albumToc Fetches album metadata based on a table of contents. Arguments:
toc
100 101 102 103 104 105 106 107 |
# File 'lib/gracenote.rb', line 100 def albumToc(toc) if @userID == nil registerUser end body = "<TOC><OFFSETS>" + toc + "</OFFSETS></TOC>" data = constructAlbumQueryBody(body, "ALBUM_TOC") return parseAlbumRES(data) end |
#fetchContributor(gn_id) ⇒ Object
Function: fetchContributor Fetches details of a contributor from gn_id Arguments:
gn_id
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/gracenote.rb', line 209 def fetchContributor (gn_id) if @userID == nil registerUser end body = "<GN_ID>" + gn_id + "</GN_ID> <OPTION> <PARAMETER>SELECT_EXTENDED</PARAMETER> <VALUE>IMAGE,MEDIAGRAPHY_IMAGES</VALUE> </OPTION>" data = constructQueryReq(body, "CONTRIBUTOR_FETCH") resp = api(data) return checkRES(resp) end |
#fetchOETData(gn_id) ⇒ Object
Function: fetchOETData Gets data based on gn_id Arguments:
gn_id
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 138 139 |
# File 'lib/gracenote.rb', line 113 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 = api(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 |
#fetchSeason(gn_id) ⇒ Object
Function: fetchSeason Fetches details of a season from gn_id Arguments:
gn_id
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/gracenote.rb', line 147 def fetchSeason (gn_id) if @userID == nil registerUser end body = "<GN_ID>" + gn_id + "</GN_ID>" data = constructQueryReq(body, "SEASON_FETCH") resp = api(data) return checkRES(resp) end |
#fetchTVShow(gn_id) ⇒ Object
Function: fetchTVShow Fetches details of TV Show from gn_id Arguments:
gn_id
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/gracenote.rb', line 163 def fetchTVShow (gn_id) if @userID == nil registerUser end body = "<GN_ID>" + gn_id + "</GN_ID> <OPTION> <PARAMETER>SELECT_EXTENDED</PARAMETER> <VALUE>IMAGE</VALUE> </OPTION>" data = constructQueryReq(body, "SERIES_FETCH") resp = api(data) return checkRES(resp) end |
#findAlbum(artistName, albumTitle, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findAlbum finds an Album Arguments:
artistName
albumTitle
trackTitle
matchMode
92 93 94 |
# File 'lib/gracenote.rb', line 92 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
81 82 83 |
# File 'lib/gracenote.rb', line 81 def findArtist(artistName, matchMode = @@ALL_RESULTS) return findTrack(artistName, "", "", matchMode) end |
#findContributor(name) ⇒ Object
Function: findContributor Find details of a contributor from name Arguments:
name
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/gracenote.rb', line 230 def findContributor (name) if @userID == nil registerUser end body = "<TEXT TYPE='NAME'>" + name + "</TEXT> <MODE>SINGLE_BEST</MODE> <OPTION> <PARAMETER>SELECT_EXTENDED</PARAMETER> <VALUE>IMAGE,MEDIAGRAPHY_IMAGES</VALUE> </OPTION>" data = constructQueryReq(body, "CONTRIBUTOR_SEARCH") resp = api(data) return checkRES(resp) end |
#findTrack(artistName, albumTitle, trackTitle, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findTrack Finds a track Arguments:
artistName
albumTitle
trackTitle
matchMode
67 68 69 70 71 72 73 74 |
# File 'lib/gracenote.rb', line 67 def findTrack(artistName, albumTitle, trackTitle, matchMode = @@ALL_RESULTS) if @userID == nil registerUser end body = constructAlbumQueryBody(artistName, albumTitle, trackTitle, "", "ALBUM_SEARCH", matchMode) data = api(constructQueryReq(body)) return parseAlbumRES(data); end |
#findTVShow(name, single = true) ⇒ Object
Function: findTVShow Finds TVShows which matches the name Arguments:
name
single
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/gracenote.rb', line 185 def findTVShow (name, single=true) if @userID == nil registerUser end singleText = single ? '<MODE>SINGLE_BEST</MODE>' : '' body = "<TEXT TYPE='TITLE'>" + name + "</TEXT> " + singleText + " <OPTION> <PARAMETER>SELECT_EXTENDED</PARAMETER> <VALUE>IMAGE</VALUE> </OPTION>" data = constructQueryReq(body, "SERIES_SEARCH") resp = api(data) return checkRES(resp) end |
#registerUser(clientID = nil) ⇒ Object
Function: registerUser Registers a user and returns userID
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gracenote.rb', line 37 def registerUser (clientID = nil) if(clientID.nil?) clientID = @clientID + "-" + @clientTag end if not @userID.nil? puts "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 = api(data) resp = checkRES resp @userID = resp['RESPONSES']['RESPONSE']['USER'] return @userID end |