gracenote 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gracenote.rb +120 -14
  3. data/lib/gracenote/HTTP.rb +2 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f7545f432cea511b488d6ea632200ec5a775eaf
4
- data.tar.gz: 5b0957e4b9a669bcabafaab628c84742f021a424
3
+ metadata.gz: 5d4bdc1ae286f082a3230f516c9750a09a010ed2
4
+ data.tar.gz: e921c97c0b4946b1487e7c1c1e05db37ec535674
5
5
  SHA512:
6
- metadata.gz: ee0cc2b2186097c6ff6f80f2ce67a2bc14777ca19ab37e271578e35a126a1df9c5bcfea47b97030d7aaa9c225b50a9734e0370659f63751d4d31ce98bb77b93a
7
- data.tar.gz: e205b23194913789b75a5cfbeca4be023a3ef0e28c9790ae924b56fb82ab12a42fa9cdadc1c7d62e8c7cb445c86f124bdfd287df14573b7499eabca4413c1737
6
+ metadata.gz: d6b4e28f592b05afa5441469288ea7e0a606d7bc882ba2f0a1c9cb646060032a185003cb067c07296430b0c73e36d64b09fa5527eba0e306de6fd6efce9fd7d7
7
+ data.tar.gz: b2d9b321bb97a238a5e7b94a752b7dac1ebde804df27dcf34cf638d8e0fd08deb5cec6c4c1938fcf4528a555df04859c03f0e99277f91ed0c582de36bfa072a5
data/lib/gracenote.rb CHANGED
@@ -48,7 +48,7 @@ class Gracenote
48
48
  <CLIENT>"+ clientID +"</CLIENT>
49
49
  </QUERY>
50
50
  </QUERIES>"
51
- resp = HTTP.post(@apiURL, data)
51
+ resp = api(data)
52
52
  resp = checkRES resp
53
53
  @userID = resp['RESPONSES']['RESPONSE']['USER']
54
54
 
@@ -66,9 +66,9 @@ class Gracenote
66
66
  if @userID == nil
67
67
  registerUser
68
68
  end
69
- body = constructQueryBody(artistName, albumTitle, trackTitle, "", "ALBUM_SEARCH", matchMode)
70
- data = constructQueryReq(body)
71
- return api(data);
69
+ body = constructAlbumQueryBody(artistName, albumTitle, trackTitle, "", "ALBUM_SEARCH", matchMode)
70
+ data = api(constructQueryReq(body))
71
+ return parseAlbumRES(data);
72
72
  end
73
73
 
74
74
  # Function: findArtist
@@ -100,8 +100,8 @@ class Gracenote
100
100
  registerUser
101
101
  end
102
102
  body = "<TOC><OFFSETS>" + toc + "</OFFSETS></TOC>"
103
- data = constructQueryBody(body, "ALBUM_TOC")
104
- return api(data)
103
+ data = constructAlbumQueryBody(body, "ALBUM_TOC")
104
+ return parseAlbumRES(data)
105
105
  end
106
106
 
107
107
  # Function: fetchOETData
@@ -124,7 +124,7 @@ class Gracenote
124
124
  </OPTION>"
125
125
 
126
126
  data = constructQueryReq(body, "ALBUM_FETCH")
127
- resp = HTTP.post(@apiURL, data)
127
+ resp = api(data)
128
128
  resp = checkRES resp
129
129
 
130
130
  json = resp["RESPONSES"]
@@ -136,15 +136,121 @@ class Gracenote
136
136
  return output
137
137
  end
138
138
 
139
- # protected methods
139
+ # TVShow methods
140
+
141
+ # Function: fetchSeason
142
+ # Fetches details of a season from gn_id
143
+ # Arguments:
144
+ # gn_id
145
+ def fetchSeason (gn_id)
146
+ if @userID == nil
147
+ registerUser
148
+ end
149
+
150
+ body = "<GN_ID>" + gn_id + "</GN_ID>"
151
+ data = constructQueryReq(body, "SEASON_FETCH")
152
+
153
+ resp = api(data)
154
+ return checkRES(resp)
155
+ end
156
+
157
+ # Function: fetchTVShow
158
+ # Fetches details of TV Show from gn_id
159
+ # Arguments:
160
+ # gn_id
161
+ def fetchTVShow (gn_id)
162
+ if @userID == nil
163
+ registerUser
164
+ end
165
+
166
+ body = "<GN_ID>" + gn_id + "</GN_ID>
167
+ <OPTION>
168
+ <PARAMETER>SELECT_EXTENDED</PARAMETER>
169
+ <VALUE>IMAGE</VALUE>
170
+ </OPTION>"
171
+
172
+ data = constructQueryReq(body, "SERIES_FETCH")
173
+
174
+ resp = api(data)
175
+ return checkRES(resp)
176
+ end
177
+
178
+ # Function: findTVShow
179
+ # Finds TVShows which matches the name
180
+ # Arguments:
181
+ # name
182
+ # single
183
+ def findTVShow (name, single=true)
184
+ if @userID == nil
185
+ registerUser
186
+ end
187
+
188
+ singleText = single ? '<MODE>SINGLE_BEST</MODE>' : ''
189
+
190
+ body = "<TEXT TYPE='TITLE'>" + name + "</TEXT>
191
+ " + singleText + "
192
+ <OPTION>
193
+ <PARAMETER>SELECT_EXTENDED</PARAMETER>
194
+ <VALUE>IMAGE</VALUE>
195
+ </OPTION>"
196
+
197
+ data = constructQueryReq(body, "SERIES_SEARCH")
198
+
199
+ resp = api(data)
200
+ return checkRES(resp)
201
+ end
202
+
203
+ # Function: fetchContributor
204
+ # Fetches details of a contributor from gn_id
205
+ # Arguments:
206
+ # gn_id
207
+ def fetchContributor (gn_id)
208
+ if @userID == nil
209
+ registerUser
210
+ end
211
+
212
+ body = "<GN_ID>" + gn_id + "</GN_ID>
213
+ <OPTION>
214
+ <PARAMETER>SELECT_EXTENDED</PARAMETER>
215
+ <VALUE>IMAGE,MEDIAGRAPHY_IMAGES</VALUE>
216
+ </OPTION>"
217
+
218
+ data = constructQueryReq(body, "CONTRIBUTOR_FETCH")
219
+
220
+ resp = api(data)
221
+ return checkRES(resp)
222
+ end
223
+
224
+ # Function: findContributor
225
+ # Find details of a contributor from name
226
+ # Arguments:
227
+ # name
228
+ def findContributor (name)
229
+ if @userID == nil
230
+ registerUser
231
+ end
232
+
233
+ body = "<TEXT TYPE='NAME'>" + name + "</TEXT>
234
+ <MODE>SINGLE_BEST</MODE>
235
+ <OPTION>
236
+ <PARAMETER>SELECT_EXTENDED</PARAMETER>
237
+ <VALUE>IMAGE,MEDIAGRAPHY_IMAGES</VALUE>
238
+ </OPTION>"
239
+
240
+ data = constructQueryReq(body, "CONTRIBUTOR_SEARCH")
241
+
242
+ resp = api(data)
243
+ return checkRES(resp)
244
+ end
245
+
246
+ ###################################################### protected methods ######################################################
140
247
  protected
141
248
  # Function: api
142
249
  # execute a query on gracenote webapi
143
250
  # Arguments:
144
251
  # query
145
252
  def api (query)
146
- resp = HTTP.post(@apiURL, query)
147
- return parseRES(resp)
253
+ return HTTP.post(@apiURL, query)
148
254
  end
149
255
 
150
256
  # Function: constructQueryReq
@@ -165,7 +271,7 @@ class Gracenote
165
271
  </QUERIES>"
166
272
  end
167
273
 
168
- # Function: constructQueryBody
274
+ # Function: constructAlbumQueryBody
169
275
  # Constructs query body
170
276
  # Arguments:
171
277
  # artist
@@ -174,7 +280,7 @@ class Gracenote
174
280
  # gn_id
175
281
  # command
176
282
  # matchMode
177
- def constructQueryBody(artist, album, track, gn_id, command = "ALBUM_SEARCH", matchMode = @@ALL_RESULTS)
283
+ def constructAlbumQueryBody(artist, album, track, gn_id, command = "ALBUM_SEARCH", matchMode = @@ALL_RESULTS)
178
284
  body = ""
179
285
  # If a fetch scenario, user the Gracenote ID.
180
286
  if command == "ALBUM_FETCH"
@@ -247,11 +353,11 @@ class Gracenote
247
353
  return json
248
354
  end
249
355
 
250
- # Function: parseRES
356
+ # Function: parseAlbumRES
251
357
  # Parse's an XML response
252
358
  # Arguments:
253
359
  # resp
254
- def parseRES resp
360
+ def parseAlbumRES resp
255
361
  json = nil
256
362
  begin
257
363
  json = checkRES resp
@@ -13,6 +13,7 @@ class HTTP
13
13
  def self.get(path, cookie='')
14
14
  uri = URI(path)
15
15
  req = Net::HTTP.new(uri.host, uri.port)
16
+ req.read_timeout = 60
16
17
  req.use_ssl = (uri.scheme == "https") ? true : false
17
18
  headers = {'Cookie' => cookie}
18
19
 
@@ -23,6 +24,7 @@ class HTTP
23
24
  def self.post(path, data='', cookie='')
24
25
  uri = URI(path)
25
26
  req = Net::HTTP.new(uri.host, uri.port)
27
+ req.read_timeout = 60
26
28
  req.use_ssl = (uri.scheme == "https") ? true : false
27
29
  headers = {'Cookie' => cookie, "Content-Type" => "application/xml"}
28
30
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gracenote
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nobelium
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-21 00:00:00.000000000 Z
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler