ur-product 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/features/step_definitions/product_steps.rb +5 -6
- data/features/support/env.rb +7 -3
- data/lib/ur/product.rb +2 -0
- data/lib/ur/search.rb +24 -22
- data/lib/ur/streaming.rb +6 -4
- data/lib/ur/version.rb +3 -1
- data/lib/ur-product.rb +4 -2
- metadata +86 -93
@@ -1,6 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# Cucumber
|
3
|
-
require 'spec/expectations'
|
4
3
|
require 'cucumber/formatter/unicode'
|
5
4
|
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
6
5
|
|
@@ -39,7 +38,7 @@ end
|
|
39
38
|
# Then
|
40
39
|
|
41
40
|
Then /^the title should be "(.*)"/ do |title|
|
42
|
-
@product.title.should == title
|
41
|
+
@product.title.should == title
|
43
42
|
end
|
44
43
|
|
45
44
|
Then /^it should have (.*)/ do |boolean_method|
|
@@ -48,11 +47,11 @@ end
|
|
48
47
|
|
49
48
|
Then /^one (.*) in (.*) should be "(.*)"$/ do |field, method, value|
|
50
49
|
values = []
|
51
|
-
|
52
|
-
@product.send(method).each do |product|
|
50
|
+
|
51
|
+
@product.send(method).each do |product|
|
53
52
|
values << product.send(field)
|
54
53
|
end
|
55
|
-
|
54
|
+
|
56
55
|
values.include?(value).should be(true)
|
57
56
|
end
|
58
57
|
|
@@ -62,6 +61,6 @@ end
|
|
62
61
|
|
63
62
|
Then /^the (.+) product should have the title "([^\"]*)"$/ do |index, title|
|
64
63
|
count_translations = { 'first' => 0, 'second' => 1 }
|
65
|
-
|
64
|
+
|
66
65
|
@products[count_translations["#{index}"]].title.should == title
|
67
66
|
end
|
data/features/support/env.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'rspec/expectations'
|
5
|
+
World(RSpec::Matchers)
|
2
6
|
|
3
7
|
# FakeWeb
|
4
8
|
require 'fakeweb'
|
@@ -6,7 +10,7 @@ require 'fakeweb'
|
|
6
10
|
FakeWeb.allow_net_connect = false
|
7
11
|
|
8
12
|
faked_urls = [
|
9
|
-
'http://metadata.ur.se/products/100001.json',
|
13
|
+
'http://metadata.ur.se/products/100001.json',
|
10
14
|
'http://metadata.ur.se/products.json?ur_product_ids=100001,150423',
|
11
15
|
'http://assets.ur.se/id/100001/images/1.jpg'
|
12
16
|
]
|
@@ -15,4 +19,4 @@ faked_urls.each do |url|
|
|
15
19
|
page = `curl -is #{url}`
|
16
20
|
FakeWeb.register_uri(:get, url, :response => page)
|
17
21
|
FakeWeb.register_uri(:head, url, :response => page)
|
18
|
-
end
|
22
|
+
end
|
data/lib/ur/product.rb
CHANGED
data/lib/ur/search.rb
CHANGED
@@ -1,50 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'rsolr-ext'
|
2
4
|
require 'yajl'
|
3
5
|
|
4
6
|
# Module for Utbildningsradion AB (http://ur.se/)
|
5
|
-
module UR
|
7
|
+
module UR
|
6
8
|
# Search for products and populate from the metadata cache
|
7
9
|
class Search
|
8
10
|
# Setup
|
9
11
|
if !defined?(SEARCH_SERVICE_URL)
|
10
12
|
SEARCH_SERVICE_URL = 'http://services.ur.se/search'
|
11
13
|
end
|
12
|
-
|
14
|
+
|
13
15
|
attr_reader :products, :solr, :facets
|
14
|
-
|
16
|
+
|
15
17
|
def initialize(solr_params)
|
16
18
|
# Prepare the facets
|
17
19
|
@products = []
|
18
20
|
@facets = {}
|
19
21
|
@solr = nil
|
20
|
-
|
21
|
-
begin
|
22
|
+
|
23
|
+
begin
|
22
24
|
solr = RSolr.connect :url => SEARCH_SERVICE_URL
|
23
25
|
response = solr.find solr_params
|
24
|
-
|
26
|
+
|
25
27
|
# Populate the products from the Metadata Cache
|
26
28
|
@products = (response.ok? && response.docs.size > 0) ?
|
27
29
|
Product.find(response.docs.map { |d| d.id }) : []
|
28
|
-
|
30
|
+
|
29
31
|
# Expose the Solr response
|
30
32
|
@solr = response
|
31
33
|
@solr.facets.map { |f| @facets[f.name] = f.items } if @solr.facets.size > 0
|
32
34
|
rescue RSolr::RequestError => e
|
33
35
|
end
|
34
36
|
end
|
35
|
-
|
37
|
+
|
36
38
|
def ok?
|
37
39
|
(!@solr.nil? && @solr && @solr.ok?)
|
38
40
|
end
|
39
|
-
|
41
|
+
|
40
42
|
def per_page
|
41
43
|
(ok?) ? @solr.params['rows'].to_i : 0
|
42
44
|
end
|
43
|
-
|
45
|
+
|
44
46
|
def num_found
|
45
47
|
(ok?) ? @solr.response['numFound'].to_i : 0
|
46
48
|
end
|
47
|
-
|
49
|
+
|
48
50
|
def self.current_programs(per_page = 10, offset = 0, format = false, agerange = false)
|
49
51
|
url = "#{SEARCH_SERVICE_URL}/select?qt=current-products" +
|
50
52
|
"&rows=#{per_page}&start=#{offset}" +
|
@@ -59,39 +61,39 @@ module UR
|
|
59
61
|
url += agerange_filter(agerange)
|
60
62
|
|
61
63
|
programs = Yajl::HttpStream.get(url)
|
62
|
-
|
63
|
-
if (programs['response']['docs'].count > 0)
|
64
|
+
|
65
|
+
if (programs['response']['docs'].count > 0)
|
64
66
|
Product.find(programs['response']['docs'].map { |d| d['id'] })
|
65
67
|
else
|
66
68
|
[]
|
67
69
|
end
|
68
70
|
end
|
69
|
-
|
71
|
+
|
70
72
|
##
|
71
73
|
# Pagination
|
72
74
|
#
|
73
|
-
|
75
|
+
|
74
76
|
def current_page
|
75
77
|
(!@solr.docs.nil?) ? @solr.docs.current_page : 0
|
76
78
|
end
|
77
|
-
|
79
|
+
|
78
80
|
def total_pages
|
79
81
|
(!@solr.docs.nil?) ? @solr.docs.total_pages : 0
|
80
82
|
end
|
81
|
-
|
83
|
+
|
82
84
|
def previous_page
|
83
85
|
(current_page > 1) ? @solr.docs.previous_page : false
|
84
86
|
end
|
85
|
-
|
87
|
+
|
86
88
|
def next_page
|
87
89
|
(current_page < total_pages) ? @solr.docs.next_page : false
|
88
90
|
end
|
89
|
-
|
91
|
+
|
90
92
|
private
|
91
93
|
def self.agerange_filter(agerange, prepend = '%20AND%20')
|
92
94
|
if ['children', 'youths', 'adults'].include? agerange
|
93
|
-
filter = '(typicalagerange:' +
|
94
|
-
{
|
95
|
+
filter = '(typicalagerange:' +
|
96
|
+
{
|
95
97
|
'children' => ['preschool', 'primary0-3', 'primary4-6'],
|
96
98
|
'youths' => ['primary7-9', 'secondary'],
|
97
99
|
'adults' => ['schoolvux', 'komvuxgrundvux', 'teachereducation',
|
@@ -109,4 +111,4 @@ module UR
|
|
109
111
|
filter
|
110
112
|
end
|
111
113
|
end
|
112
|
-
end
|
114
|
+
end
|
data/lib/ur/streaming.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'yajl/http_stream'
|
2
4
|
|
3
5
|
# Module for Utbildningsradion AB (http://ur.se/)
|
@@ -8,11 +10,11 @@ module UR
|
|
8
10
|
if !defined?(STREAMING_URL)
|
9
11
|
STREAMING_URL = 'http://metadata.ur.se/streaming'
|
10
12
|
end
|
11
|
-
|
13
|
+
|
12
14
|
def initialize(data)
|
13
15
|
@data = data
|
14
16
|
end
|
15
|
-
|
17
|
+
|
16
18
|
def [](product)
|
17
19
|
if product.respond_to? :ur_product_id
|
18
20
|
@data[product.ur_product_id.to_s]
|
@@ -20,11 +22,11 @@ module UR
|
|
20
22
|
@data[product.to_s]
|
21
23
|
end
|
22
24
|
end
|
23
|
-
|
25
|
+
|
24
26
|
def self.search(ids)
|
25
27
|
return [] if ids.empty?
|
26
28
|
url = STREAMING_URL + '.json?ur_product_ids=' + ids.join(',')
|
27
29
|
Streaming.new(Yajl::HttpStream.get(url))
|
28
30
|
end
|
29
31
|
end
|
30
|
-
end
|
32
|
+
end
|
data/lib/ur/version.rb
CHANGED
data/lib/ur-product.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require File.dirname(__FILE__) + '/ur/metadata_cache'
|
2
4
|
require File.dirname(__FILE__) + '/ur/product'
|
3
5
|
require File.dirname(__FILE__) + '/ur/product/distribution_event.rb'
|
@@ -10,7 +12,7 @@ require File.dirname(__FILE__) + '/ur/version'
|
|
10
12
|
module UR
|
11
13
|
class InvalidProductID < Exception
|
12
14
|
end
|
13
|
-
|
15
|
+
|
14
16
|
class InvalidResponse < Exception
|
15
17
|
end
|
16
|
-
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,96 +1,99 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ur-product
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 1.0.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Peter Hellberg
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-16 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: yajl-ruby
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70169394839980 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 7
|
33
|
-
- 6
|
34
|
-
version: 0.7.6
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.7'
|
35
22
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: rsolr
|
39
23
|
prerelease: false
|
40
|
-
|
24
|
+
version_requirements: *70169394839980
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rsolr
|
27
|
+
requirement: &70169394839480 !ruby/object:Gem::Requirement
|
41
28
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
- 12
|
49
|
-
- 1
|
50
|
-
version: 0.12.1
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.12'
|
51
33
|
type: :runtime
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: rsolr-ext
|
55
34
|
prerelease: false
|
56
|
-
|
35
|
+
version_requirements: *70169394839480
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rsolr-ext
|
38
|
+
requirement: &70169394839020 !ruby/object:Gem::Requirement
|
57
39
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
segments:
|
63
|
-
- 0
|
64
|
-
- 12
|
65
|
-
- 0
|
66
|
-
version: 0.12.0
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.12'
|
67
44
|
type: :runtime
|
68
|
-
version_requirements: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rest-client
|
71
45
|
prerelease: false
|
72
|
-
|
46
|
+
version_requirements: *70169394839020
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rest-client
|
49
|
+
requirement: &70169394838560 !ruby/object:Gem::Requirement
|
73
50
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
segments:
|
79
|
-
- 1
|
80
|
-
- 4
|
81
|
-
- 2
|
82
|
-
version: 1.4.2
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
83
55
|
type: :runtime
|
84
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70169394838560
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: cucumber
|
60
|
+
requirement: &70169394838100 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '1.1'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70169394838100
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: &70169394837640 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '2.7'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70169394837640
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: fakeweb
|
82
|
+
requirement: &70169394837180 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '1.3'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70169394837180
|
85
91
|
description: Enables searching and fetching of Utbildningsradion products
|
86
92
|
email: peter@c7.se
|
87
93
|
executables: []
|
88
|
-
|
89
94
|
extensions: []
|
90
|
-
|
91
95
|
extra_rdoc_files: []
|
92
|
-
|
93
|
-
files:
|
96
|
+
files:
|
94
97
|
- README.markdown
|
95
98
|
- Rakefile
|
96
99
|
- MIT-LICENSE
|
@@ -106,39 +109,29 @@ files:
|
|
106
109
|
- features/product.feature
|
107
110
|
- features/support/env.rb
|
108
111
|
- features/step_definitions/product_steps.rb
|
109
|
-
has_rdoc: true
|
110
112
|
homepage: http://github.com/c7/ur-product
|
111
|
-
licenses:
|
113
|
+
licenses:
|
112
114
|
- MIT-LICENSE
|
113
115
|
post_install_message:
|
114
116
|
rdoc_options: []
|
115
|
-
|
116
|
-
require_paths:
|
117
|
+
require_paths:
|
117
118
|
- lib
|
118
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
120
|
none: false
|
120
|
-
requirements:
|
121
|
-
- -
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
|
124
|
-
|
125
|
-
- 0
|
126
|
-
version: "0"
|
127
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
126
|
none: false
|
129
|
-
requirements:
|
130
|
-
- -
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
|
133
|
-
segments:
|
134
|
-
- 0
|
135
|
-
version: "0"
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
136
131
|
requirements: []
|
137
|
-
|
138
132
|
rubyforge_project: ur-product
|
139
|
-
rubygems_version: 1.
|
133
|
+
rubygems_version: 1.8.6
|
140
134
|
signing_key:
|
141
135
|
specification_version: 3
|
142
136
|
summary: API wrapper for the Utbildningsradion product services
|
143
137
|
test_files: []
|
144
|
-
|