ur-product 0.9.8 → 0.9.9

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 (2) hide show
  1. data/lib/ur/search.rb +44 -0
  2. metadata +4 -4
data/lib/ur/search.rb CHANGED
@@ -44,6 +44,28 @@ module UR
44
44
  (ok?) ? @solr.response['numFound'].to_i : 0
45
45
  end
46
46
 
47
+ def self.current_programs(per_page = 10, offset = 0, format = false, agerange = false)
48
+ url = "#{SEARCH_SERVICE_URL}/select?qt=current-products" +
49
+ "&rows=#{per_page}&start=#{offset}" +
50
+ "&publicstreaming=NOW" +
51
+ "&fq=(search_product_type:programtv" +
52
+ "%20OR%20search_product_type:programradio)"
53
+
54
+ if ['audio','video'].include? format
55
+ url += "%20AND%20format:#{format}"
56
+ end
57
+
58
+ url += agerange_filter(agerange)
59
+
60
+ programs = Yajl::HttpStream.get(url)
61
+
62
+ if (programs['response']['docs'].count > 0)
63
+ Product.find(programs['response']['docs'].map { |d| d['id'] })
64
+ else
65
+ []
66
+ end
67
+ end
68
+
47
69
  ##
48
70
  # Pagination
49
71
  #
@@ -63,5 +85,27 @@ module UR
63
85
  def next_page
64
86
  (current_page < total_pages) ? @solr.docs.next_page : false
65
87
  end
88
+
89
+ private
90
+ def self.agerange_filter(agerange, prepend = '%20AND%20')
91
+ if ['children', 'youths', 'adults'].include? agerange
92
+ filter = '(typicalagerange:' +
93
+ {
94
+ 'children' => ['preschool', 'primary0-3', 'primary4-6'],
95
+ 'youths' => ['primary7-9', 'secondary'],
96
+ 'adults' => ['schoolvux', 'komvuxgrundvux', 'teachereducation',
97
+ 'popularadulteducation', 'folkhighschool', 'university']
98
+ }[agerange].join('%20OR%20typicalagerange:') + ')'
99
+
100
+ if prepend
101
+ filter = prepend + filter
102
+ end
103
+
104
+ else
105
+ filter = ''
106
+ end
107
+
108
+ filter
109
+ end
66
110
  end
67
111
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ur-product
3
3
  version: !ruby/object:Gem::Version
4
- hash: 43
4
+ hash: 41
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 8
10
- version: 0.9.8
9
+ - 9
10
+ version: 0.9.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Peter Hellberg
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-30 00:00:00 +02:00
18
+ date: 2010-08-13 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency