poms 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e3aa1829a203b60720b24083855ffb8a9f41621
4
- data.tar.gz: 60ddc33138bde526bf72892201877abce90dbc29
3
+ metadata.gz: a3549380a845d97e5c0cd2428afa06b7ccf2e1ef
4
+ data.tar.gz: 93d6400f2a0aaaecbd8a9b8ebf7dc9466be12256
5
5
  SHA512:
6
- metadata.gz: 755e683ca19d2c23d29555426309d3618bfe2b0dcb30651341053c9332b8c61db00e0968dea06a1105ec9bf55b1c85ba71a867eeef1e7c7b29e3edf70480c3cb
7
- data.tar.gz: 8f4e26864b024263e36f830cad01cd56a915c438d979c0ef3304b2d0217661f41d21f0fddb606029eec76ebf70e9b7aadfebb2549d699154d46a93393759bad7
6
+ metadata.gz: 1b2e9bddc91940ea7659b3e4f812bb6870cb5f8eb670ded228be422e972e973f5deef9a35f441c381c16ae0e670c33113edf26020cbb6a397759954db6b44679
7
+ data.tar.gz: 5357169c1f04967e947821c0af4c0c676cf6a513ef87c2e2487b76eae9535556f3f40632317a2e9b74f2ee24f99636bb07ae873a399bff6f52f140920f15ba7d
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- poms (0.0.3)
4
+ poms (0.0.4)
5
5
  activesupport
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (4.1.5)
10
+ activesupport (4.1.6)
11
11
  i18n (~> 0.6, >= 0.6.9)
12
12
  json (~> 1.7, >= 1.7.7)
13
13
  minitest (~> 5.1)
@@ -62,6 +62,7 @@ GEM
62
62
  slop (3.6.0)
63
63
  thor (0.19.1)
64
64
  thread_safe (0.3.4)
65
+ timecop (0.7.1)
65
66
  timers (1.1.0)
66
67
  tzinfo (1.2.2)
67
68
  thread_safe (~> 0.1)
@@ -78,3 +79,4 @@ DEPENDENCIES
78
79
  poms!
79
80
  rake
80
81
  rspec
82
+ timecop
data/lib/poms.rb CHANGED
@@ -64,17 +64,23 @@ module Poms
64
64
  end
65
65
 
66
66
  def fetch_current_broadcast(channel)
67
- uri = [CHANNEL_AND_START_PATH, channel_params(channel, Time.now, 1.day.ago), '&descending=true&limit=1' ].join
68
- hash = get_json(uri)
69
- rows = hash['rows']
70
- Poms::Builder.process_hash(rows.empty? ? {} : rows.first['doc'])
67
+ hash = get_json(channel_and_start_uri(channel, Time.now, 1.day.ago, {limit: 1, descending: true}))
68
+ get_first_broadcast(hash)
69
+ end
70
+
71
+ def fetch_current_broadcast_and_key(channel)
72
+ hash = get_json(channel_and_start_uri(channel, Time.now, 1.day.ago, {limit: 1, descending: true}))
73
+ {key: get_first_key(hash), broadcast: get_first_broadcast(hash)}
71
74
  end
72
75
 
73
76
  def fetch_next_broadcast(channel)
74
- uri = [CHANNEL_AND_START_PATH, channel_params(channel, Time.now, 1.day.from_now), '&limit=1' ].join
75
- hash = get_json(uri)
76
- rows = hash['rows']
77
- Poms::Builder.process_hash(rows.empty? ? {} : rows.first['doc'])
77
+ hash = get_json(channel_and_start_uri(channel, Time.now, 1.day.from_now, {limit: 1}))
78
+ get_first_broadcast(hash)
79
+ end
80
+
81
+ def fetch_next_broadcast_and_key(channel)
82
+ hash = get_json(channel_and_start_uri(channel, Time.now, 1.day.from_now, {limit: 1}))
83
+ {key: get_first_key(hash), broadcast: get_first_broadcast(hash)}
78
84
  end
79
85
 
80
86
  # private
@@ -107,4 +113,21 @@ module Poms
107
113
  end
108
114
  end
109
115
 
116
+ private
117
+
118
+ def channel_and_start_uri(channel, start_time, end_time, options={})
119
+ query_options = options.blank? ? '' : "&#{options.to_query}"
120
+ [CHANNEL_AND_START_PATH, channel_params(channel, start_time, end_time), query_options ].join
121
+ end
122
+
123
+ def get_first_broadcast(hash)
124
+ rows = hash['rows']
125
+ Poms::Builder.process_hash(rows.empty? ? {} : rows.first['doc'])
126
+ end
127
+
128
+ def get_first_key(hash)
129
+ rows = hash['rows']
130
+ rows.empty? ? [] : rows.first['key']
131
+ end
132
+
110
133
  end
data/lib/poms/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Poms
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,136 @@
1
+ {
2
+ "total_rows": 654832,
3
+ "offset": 235162,
4
+ "rows": [
5
+ {
6
+ "id": "AT_2023343",
7
+ "key": [
8
+ "NED3",
9
+ 1410966671000
10
+ ],
11
+ "value": null,
12
+ "doc": {
13
+ "_id": "AT_2023343",
14
+ "_rev": "55-d3eee0573e81d0c059eb1127fbc5abeb",
15
+ "objectType": "program",
16
+ "mid": "AT_2023343",
17
+ "creationDate": 1408855689977,
18
+ "lastModified": 1410964631410,
19
+ "sortDate": 1410966671000,
20
+ "urn": "urn:vpro:media:program:44386090",
21
+ "embeddable": true,
22
+ "episodeOf": [
23
+ {
24
+ "midRef": "AT_2011551",
25
+ "urnRef": "urn:vpro:media:group:43525293",
26
+ "type": "SEASON",
27
+ "index": 30,
28
+ "highlighted": false,
29
+ "added": 1408855690158
30
+ }
31
+ ],
32
+ "broadcasters": [
33
+ "AVROTROS"
34
+ ],
35
+ "titles": [
36
+ {
37
+ "value": "Junior Songfestival 2014",
38
+ "owner": "MIS",
39
+ "type": "MAIN"
40
+ },
41
+ {
42
+ "value": "1e Halve Finale LIVE",
43
+ "owner": "WHATS_ON",
44
+ "type": "MAIN"
45
+ },
46
+ {
47
+ "value": "1e Halve Finale LIVE",
48
+ "owner": "MIS",
49
+ "type": "SUB"
50
+ }
51
+ ],
52
+ "descriptions": [
53
+ {
54
+ "value": "In de eerste halve finale van het Junior Songfestival strijden Bobby & Ella, Chelsea, Sem en Suze tegen elkaar. Een professionele vakjury bepaalt samen met de kinderjury en de kijkers thuis wie er door mag naar die allesbeslissende finale. Presentatie is in handen van Jan Smit.",
55
+ "owner": "WHATS_ON",
56
+ "type": "MAIN"
57
+ },
58
+ {
59
+ "value": "In de eerste halve finale strijden Bobby & Ella, Chelsea, Sem en Suze tegen elkaar. Een professionele vakjury bepaalt samen met de kinderjury en de kijkers thuis wie er door mag naar de finale.",
60
+ "owner": "MIS",
61
+ "type": "SHORT"
62
+ },
63
+ {
64
+ "value": "In de eerste halve finale strijden Bobby & Ella, Chelsea, Sem en Suze tegen elkaar.",
65
+ "owner": "MIS",
66
+ "type": "KICKER"
67
+ },
68
+ {
69
+ "value": "In de eerste halve finale van het Junior Songfestival strijden Bobby & Ella, Chelsea, Sem en Suze tegen elkaar. Een professionele vakjury bepaalt samen met de kinderjury en de kijkers thuis wie er door mag naar die allesbeslissende finale.",
70
+ "owner": "MIS",
71
+ "type": "EPISODE"
72
+ }
73
+ ],
74
+ "genres": [
75
+ "Jeugd",
76
+ "Muziek"
77
+ ],
78
+ "countries": [
79
+ "NL"
80
+ ],
81
+ "languages": [
82
+ "NL"
83
+ ],
84
+ "avAttributes": {
85
+ "videoAttributes": {
86
+ "color": "BLACK_AND_WHITE_AND_COLOR",
87
+ "aspectRatio": "16:9"
88
+ },
89
+ "audioAttributes": {
90
+ "numberOfChannels": 2
91
+ }
92
+ },
93
+ "releaseYear": 2014,
94
+ "duration": 3300000,
95
+ "credits": [
96
+ {
97
+ "givenName": "Jan",
98
+ "familyName": "Smit",
99
+ "role": "PRESENTER"
100
+ }
101
+ ],
102
+ "descendantOf": [
103
+ {
104
+ "midRef": "POMS_S_AVRO_096666",
105
+ "urnRef": "urn:vpro:media:group:3731025",
106
+ "type": "SERIES"
107
+ },
108
+ {
109
+ "midRef": "AT_2011551",
110
+ "urnRef": "urn:vpro:media:group:43525293",
111
+ "type": "SEASON"
112
+ }
113
+ ],
114
+ "predictions": [
115
+ {
116
+ "state": "ANNOUNCED",
117
+ "platform": "INTERNETVOD"
118
+ }
119
+ ],
120
+ "scheduleEvents": [
121
+ {
122
+ "start": 1410966671000,
123
+ "duration": 3016000,
124
+ "poProgID": "AT_2023343",
125
+ "channel": "NED3",
126
+ "urnRef": "urn:vpro:media:program:44386090",
127
+ "midRef": "AT_2023343"
128
+ }
129
+ ],
130
+ "workflow": "PUBLISHED",
131
+ "type": "BROADCAST",
132
+ "avType": "VIDEO"
133
+ }
134
+ }
135
+ ]
136
+ }
@@ -1,3 +1,4 @@
1
+ require 'timecop'
1
2
  require 'spec_helper'
2
3
 
3
4
  describe Poms do
@@ -26,7 +27,7 @@ describe Poms do
26
27
  end
27
28
 
28
29
  describe '#fetch_broadcasts_for_serie' do
29
- it 'returns nil when a broadcast does not exits' do
30
+ it 'returns nil when a broadcast does not exist' do
30
31
  FakeWeb.register_uri(:get, "http://docs.poms.omroep.nl/media/_design/media/_view/by-ancestor-and-type?reduce=false&key=[%22BLA%22,%22BROADCAST%22]&include_docs=true", :status => [404, "Not Found"])
31
32
  expect(Poms.fetch_broadcasts_for_serie('BLA')).to eq([])
32
33
  end
@@ -54,4 +55,72 @@ describe Poms do
54
55
  end
55
56
  end
56
57
 
58
+ describe 'fetch broadcasts' do
59
+ let(:response) { File.read 'spec/fixtures/poms_single_broadcast_by_channel.json' }
60
+
61
+ before do
62
+ Timecop.freeze(DateTime.strptime("1410969127",'%s'))
63
+ end
64
+
65
+ after do
66
+ Timecop.return
67
+ end
68
+
69
+ describe '#fetch_current_broadcast' do
70
+ before do
71
+ path = "http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-channel-and-start?startkey=[%22NED3%22,1410969127000]&endkey=[%22NED3%22,1410882727000]&reduce=false&include_docs=true&descending=true&limit=1"
72
+ FakeWeb.register_uri(:get, path, :body => response)
73
+ end
74
+
75
+ it "fetches the current broadcast" do
76
+ expect(Poms::Builder).to receive(:process_hash).exactly(1).times
77
+ Poms.fetch_current_broadcast('NED3')
78
+ end
79
+ end
80
+
81
+ describe '#fetch_current_broadcast_and_key' do
82
+ before do
83
+ path = "http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-channel-and-start?startkey=[%22NED3%22,1410969127000]&endkey=[%22NED3%22,1410882727000]&reduce=false&include_docs=true&descending=true&limit=1"
84
+ FakeWeb.register_uri(:get, path, :body => response)
85
+ end
86
+
87
+ it "fetches the current broadcast" do
88
+ expect(Poms::Builder).to receive(:process_hash).exactly(1).times
89
+ Poms.fetch_current_broadcast_and_key('NED3')
90
+ end
91
+
92
+ it "returns the key" do
93
+ expect(Poms.fetch_current_broadcast_and_key('NED3')[:key]).to eq(["NED3",1410966671000])
94
+ end
95
+ end
96
+
97
+ describe '#fetch_next_broadcast' do
98
+ before do
99
+ path = "http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-channel-and-start?startkey=[%22NED3%22,1410969127000]&endkey=[%22NED3%22,1411055527000]&reduce=false&include_docs=true&limit=1"
100
+ FakeWeb.register_uri(:get, path, :body => response)
101
+ end
102
+
103
+ it "fetches the next broadcast" do
104
+ expect(Poms::Builder).to receive(:process_hash).exactly(1).times
105
+ Poms.fetch_next_broadcast('NED3')
106
+ end
107
+ end
108
+
109
+ describe '#fetch_next_broadcast_and_key' do
110
+ before do
111
+ path = "http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-channel-and-start?startkey=[%22NED3%22,1410969127000]&endkey=[%22NED3%22,1411055527000]&reduce=false&include_docs=true&descending=true&limit=1"
112
+ FakeWeb.register_uri(:get, path, :body => response)
113
+ end
114
+
115
+ it "fetches the current broadcast" do
116
+ expect(Poms::Builder).to receive(:process_hash).exactly(1).times
117
+ Poms.fetch_next_broadcast_and_key('NED3')
118
+ end
119
+
120
+ it "returns the key" do
121
+ expect(Poms.fetch_next_broadcast_and_key('NED3')[:key]).to eq(["NED3",1410966671000])
122
+ end
123
+ end
124
+ end
125
+
57
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Kruijsen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-09-08 00:00:00.000000000 Z
13
+ date: 2014-09-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -110,6 +110,20 @@ dependencies:
110
110
  - - '>='
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: timecop
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
113
127
  - !ruby/object:Gem::Dependency
114
128
  name: activesupport
115
129
  requirement: !ruby/object:Gem::Requirement
@@ -154,6 +168,7 @@ files:
154
168
  - spec/fixtures/poms_broadcast_multiple_schedule_events.json
155
169
  - spec/fixtures/poms_broadcast_pippi.json
156
170
  - spec/fixtures/poms_series.json
171
+ - spec/fixtures/poms_single_broadcast_by_channel.json
157
172
  - spec/fixtures/poms_zapp.json
158
173
  - spec/lib/poms/broadcast_spec.rb
159
174
  - spec/lib/poms/buider_spec.rb
@@ -190,6 +205,7 @@ test_files:
190
205
  - spec/fixtures/poms_broadcast_multiple_schedule_events.json
191
206
  - spec/fixtures/poms_broadcast_pippi.json
192
207
  - spec/fixtures/poms_series.json
208
+ - spec/fixtures/poms_single_broadcast_by_channel.json
193
209
  - spec/fixtures/poms_zapp.json
194
210
  - spec/lib/poms/broadcast_spec.rb
195
211
  - spec/lib/poms/buider_spec.rb