ur-product 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/features/product.feature +4 -0
- data/features/step_definitions/product_steps.rb +12 -0
- data/features/support/env.rb +3 -1
- data/lib/ur/metadata_cache.rb +13 -12
- data/lib/ur/product.rb +1 -1
- data/lib/ur/search.rb +5 -3
- data/lib/ur/streaming.rb +3 -2
- data/lib/ur/version.rb +1 -1
- metadata +16 -16
data/features/product.feature
CHANGED
@@ -35,6 +35,10 @@ When /^I get the product it should throw "([^\"]*)"$/ do |exception|
|
|
35
35
|
lambda { UR::Product.find(@id) }.should raise_error(exception)
|
36
36
|
end
|
37
37
|
|
38
|
+
When /^I search for current programs$/ do
|
39
|
+
@current_programs = UR::Search.current_programs
|
40
|
+
end
|
41
|
+
|
38
42
|
# Then
|
39
43
|
|
40
44
|
Then /^the title should be "(.*)"/ do |title|
|
@@ -64,3 +68,11 @@ Then /^the (.+) product should have the title "([^\"]*)"$/ do |index, title|
|
|
64
68
|
|
65
69
|
@products[count_translations["#{index}"]].title.should == title
|
66
70
|
end
|
71
|
+
|
72
|
+
Then /^the result should contain a list of products$/ do
|
73
|
+
@current_programs.class.should == Array
|
74
|
+
|
75
|
+
types = @current_programs.map(&:class).uniq
|
76
|
+
types.length.should == 1
|
77
|
+
types[0].should == UR::Product
|
78
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -12,7 +12,9 @@ FakeWeb.allow_net_connect = false
|
|
12
12
|
faked_urls = [
|
13
13
|
'http://metadata.ur.se/products/100001.json',
|
14
14
|
'http://metadata.ur.se/products.json?ur_product_ids=100001,150423',
|
15
|
-
'http://assets.ur.se/id/100001/images/1.jpg'
|
15
|
+
'http://assets.ur.se/id/100001/images/1.jpg',
|
16
|
+
'http://services.ur.se/search/select?qt=current-products&rows=10&start=0&publicstreaming=NOW&fq=(search_product_type:programtv%20OR%20search_product_type:programradio)',
|
17
|
+
'http://metadata.ur.se/products.json?ur_product_ids=165422,166790,165412,165070,166257,165368,165367,167372,167373,165146,165008,166807,165463,164971,164976,165152,164975,164974,164973,164972'
|
16
18
|
]
|
17
19
|
|
18
20
|
faked_urls.each do |url|
|
data/lib/ur/metadata_cache.rb
CHANGED
@@ -1,47 +1,48 @@
|
|
1
1
|
require 'uri'
|
2
|
+
require 'rest-client'
|
2
3
|
require 'yajl'
|
3
|
-
require 'yajl/http_stream'
|
4
4
|
|
5
5
|
# Module for Utbildningsradion AB (http://ur.se/)
|
6
6
|
module UR
|
7
|
-
# Responsible for retrieving metadata and
|
7
|
+
# Responsible for retrieving metadata and
|
8
8
|
# populating one or more UR::Product objects
|
9
9
|
class MetadataCache
|
10
10
|
# Setup
|
11
11
|
if !defined?(METADATA_PRODUCT_URL)
|
12
12
|
METADATA_PRODUCT_URL = 'http://metadata.ur.se/products'
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
# Retrieve one or more products
|
16
16
|
def self.find(id)
|
17
17
|
if id.instance_of?(Array)
|
18
18
|
valid_ids = []
|
19
|
-
|
19
|
+
|
20
20
|
id.each do |id|
|
21
21
|
if id.to_s.match(/^1\d{5}$/)
|
22
|
-
valid_ids << id
|
22
|
+
valid_ids << id
|
23
23
|
else
|
24
24
|
raise UR::InvalidProductID
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
url = METADATA_PRODUCT_URL + ".json?ur_product_ids=#{valid_ids.join(',')}"
|
29
29
|
else
|
30
30
|
raise UR::InvalidProductID if !id.to_s.match(/^1\d{5}$/)
|
31
31
|
url = METADATA_PRODUCT_URL + "/#{id}.json"
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
begin
|
35
|
+
url = URI.parse(url).to_s
|
35
36
|
# Get the JSON response from the Metadata Cache
|
36
|
-
response = Yajl::
|
37
|
-
rescue
|
38
|
-
# Raise an invalid response exception if there was
|
37
|
+
response = Yajl::Parser.parse(RestClient.get(url))
|
38
|
+
rescue RestClient::Exception
|
39
|
+
# Raise an invalid response exception if there was
|
39
40
|
# a problem with the HTTP request
|
40
41
|
raise UR::InvalidResponse
|
41
42
|
end
|
42
|
-
|
43
|
+
|
43
44
|
# Return the response as a parsed JSON object
|
44
45
|
response
|
45
46
|
end
|
46
47
|
end
|
47
|
-
end
|
48
|
+
end
|
data/lib/ur/product.rb
CHANGED
data/lib/ur/search.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'rsolr-ext'
|
4
|
+
require 'rest-client'
|
4
5
|
require 'yajl'
|
5
6
|
|
6
7
|
# Module for Utbildningsradion AB (http://ur.se/)
|
@@ -60,10 +61,11 @@ module UR
|
|
60
61
|
|
61
62
|
url += agerange_filter(agerange)
|
62
63
|
|
63
|
-
|
64
|
+
response = RestClient.get(url)
|
65
|
+
json = Yajl::Parser.parse(response)
|
64
66
|
|
65
|
-
if (
|
66
|
-
Product.find(
|
67
|
+
if (json['response']['docs'].count > 0)
|
68
|
+
Product.find(json['response']['docs'].map { |d| d['id'] })
|
67
69
|
else
|
68
70
|
[]
|
69
71
|
end
|
data/lib/ur/streaming.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'rest-client'
|
4
|
+
require 'yajl'
|
4
5
|
|
5
6
|
# Module for Utbildningsradion AB (http://ur.se/)
|
6
7
|
module UR
|
@@ -26,7 +27,7 @@ module UR
|
|
26
27
|
def self.search(ids)
|
27
28
|
return [] if ids.empty?
|
28
29
|
url = STREAMING_URL + '.json?ur_product_ids=' + ids.join(',')
|
29
|
-
Streaming.new(Yajl::
|
30
|
+
Streaming.new(Yajl::Parser.parse(RestClient.get(url)))
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
data/lib/ur/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ur-product
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|
16
|
-
requirement: &
|
16
|
+
requirement: &70260104266600 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.7'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70260104266600
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rsolr
|
27
|
-
requirement: &
|
27
|
+
requirement: &70260104266100 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0.12'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70260104266100
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rsolr-ext
|
38
|
-
requirement: &
|
38
|
+
requirement: &70260104265640 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0.12'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70260104265640
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rest-client
|
49
|
-
requirement: &
|
49
|
+
requirement: &70260104265180 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '1.6'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70260104265180
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: cucumber
|
60
|
-
requirement: &
|
60
|
+
requirement: &70260104264720 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '1.1'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70260104264720
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70260104264260 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '2.7'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70260104264260
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: fakeweb
|
82
|
-
requirement: &
|
82
|
+
requirement: &70260104263800 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '1.3'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70260104263800
|
91
91
|
description: Enables searching and fetching of Utbildningsradion products
|
92
92
|
email: peter@c7.se
|
93
93
|
executables: []
|