gracenote 1.0.0 → 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 +7 -0
  2. data/lib/gracenote/HTTP.rb +2 -0
  3. data/lib/gracenote.rb +120 -14
  4. metadata +13 -23
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5d4bdc1ae286f082a3230f516c9750a09a010ed2
4
+ data.tar.gz: e921c97c0b4946b1487e7c1c1e05db37ec535674
5
+ SHA512:
6
+ metadata.gz: d6b4e28f592b05afa5441469288ea7e0a606d7bc882ba2f0a1c9cb646060032a185003cb067c07296430b0c73e36d64b09fa5527eba0e306de6fd6efce9fd7d7
7
+ data.tar.gz: b2d9b321bb97a238a5e7b94a752b7dac1ebde804df27dcf34cf638d8e0fd08deb5cec6c4c1938fcf4528a555df04859c03f0e99277f91ed0c582de36bfa072a5
@@ -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
 
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
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gracenote
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - nobelium
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-05 00:00:00.000000000 Z
11
+ date: 2014-03-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,49 +27,43 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: curb
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: crack
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  description: Gracenote web api gem
@@ -87,26 +78,25 @@ files:
87
78
  homepage: http://rubygems.org/gems/gracenote
88
79
  licenses:
89
80
  - MIT
81
+ metadata: {}
90
82
  post_install_message:
91
83
  rdoc_options: []
92
84
  require_paths:
93
85
  - lib
94
86
  required_ruby_version: !ruby/object:Gem::Requirement
95
- none: false
96
87
  requirements:
97
- - - ! '>='
88
+ - - '>='
98
89
  - !ruby/object:Gem::Version
99
90
  version: '0'
100
91
  required_rubygems_version: !ruby/object:Gem::Requirement
101
- none: false
102
92
  requirements:
103
- - - ! '>='
93
+ - - '>='
104
94
  - !ruby/object:Gem::Version
105
95
  version: '0'
106
96
  requirements: []
107
97
  rubyforge_project:
108
- rubygems_version: 1.8.23
98
+ rubygems_version: 2.1.11
109
99
  signing_key:
110
- specification_version: 3
100
+ specification_version: 4
111
101
  summary: This gem is a wrapper for the gracenote web api
112
102
  test_files: []