poms 0.0.10 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,11 @@
1
1
  module Poms
2
+ # Module that gets json from a url.
2
3
  module Connect
3
-
4
4
  def get_json(uri)
5
- begin
6
- JSON.parse(open(uri).read)
7
- rescue OpenURI::HTTPError => e
8
- raise e unless e.message.match(/404/)
9
- nil
10
- end
5
+ JSON.parse(open(uri).read)
6
+ rescue OpenURI::HTTPError => e
7
+ raise e unless e.message.match(/404/)
8
+ nil
11
9
  end
12
10
  end
13
11
  end
@@ -1,16 +1,17 @@
1
1
  module Poms
2
+ # Mixin for a class that has ancestors.
2
3
  module HasAncestors
3
4
  module ClassMethods
4
-
5
5
  end
6
6
 
7
7
  module InstanceMethods
8
8
  def series
9
9
  return @series if @series
10
- descendant_series = descendant_of.reject { |obj| obj.class != Poms::Series }
11
- if descendant_of.blank?
12
- []
13
- elsif descendant_series.blank?
10
+ return [] if descendant_of.blank?
11
+ descendant_series = descendant_of.reject do |obj|
12
+ obj.class != Poms::Series
13
+ end
14
+ if descendant_series.blank?
14
15
  descendant_of
15
16
  else
16
17
  descendant_series
@@ -28,9 +29,20 @@ module Poms
28
29
 
29
30
  def ancestor_mids
30
31
  return @ancestor_mids if @ancestor_mids
31
- descendant_of_mids = descendant_of.map(&:mid_ref) rescue []
32
- episode_of_mids = episode_of.map(&:mid_ref) rescue []
33
- @ancestor_mids = (descendant_of_mids + episode_of_mids).flatten.compact.uniq
32
+ @ancestor_mids = (descendant_of_mids +
33
+ episode_of_mids).flatten.compact.uniq
34
+ end
35
+
36
+ def descendant_of_mids
37
+ descendant_of.map(&:mid_ref)
38
+ rescue
39
+ []
40
+ end
41
+
42
+ def episode_of_mids
43
+ episode_of.map(&:mid_ref)
44
+ rescue
45
+ []
34
46
  end
35
47
  end
36
48
 
@@ -1,14 +1,23 @@
1
1
  module Poms
2
+ # Mixin for classes with a title and description.
2
3
  module HasBaseAttributes
3
4
  def title
4
5
  return @title if @title
5
6
  main_title = select_title_by_type 'MAIN'
6
7
  sub_title = select_title_by_type 'SUB'
7
- @titel = (sub_title && sub_title.match(main_title)) ? sub_title : [main_title, sub_title].compact.join(": ")
8
+ if sub_title && sub_title.match(main_title)
9
+ @titel = sub_title
10
+ else
11
+ @titel = [main_title, sub_title].compact.join(': ')
12
+ end
8
13
  end
9
14
 
10
15
  def description
11
- @description ||= descriptions.first.value rescue nil
16
+ @description ||= begin
17
+ descriptions.first.value
18
+ rescue
19
+ nil
20
+ end
12
21
  end
13
22
 
14
23
  private
@@ -0,0 +1,27 @@
1
+ require 'open-uri'
2
+ require 'timeout'
3
+
4
+ module Poms
5
+ # Methods for working with the merged series api from NPO.
6
+ module MergedSeries
7
+ extend self
8
+
9
+ API_URL = 'https://rs-test.poms.omroep.nl/v1/api/media/redirects/'.freeze
10
+
11
+ # Gets the merged serie mids as a hash. Expects a JSON response from
12
+ # the server with a `map` key.
13
+ # Throws a PomsError if the call timeouts, has an HTTP error or JSON parse
14
+ # error.
15
+ #
16
+ # @param api_url the API url to query
17
+ # @return [Hash] a hash with old_mid => new_mid pairs
18
+ def serie_mids(api_url = API_URL)
19
+ Timeout.timeout(3) do
20
+ data = open(api_url).read
21
+ JSON.parse(data).fetch('map')
22
+ end
23
+ rescue OpenURI::HTTPError, JSON::ParserError, Timeout::Error => e
24
+ raise Poms::PomsError, e.message
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module Poms
2
+ # A generic error for things that go wrong inside Poms.
3
+ class PomsError < StandardError
4
+ end
5
+ end
@@ -1,7 +1,7 @@
1
1
  module Poms
2
+ # POMS wrapper for a single scheduled broadcast.
2
3
  class ScheduleEvent < Poms::Builder::NestedOpenStruct
3
-
4
- def initialize hash
4
+ def initialize(hash)
5
5
  @hash = hash
6
6
  set_start_and_end_times
7
7
  super @hash
@@ -16,11 +16,11 @@ module Poms
16
16
 
17
17
  def set_starts_at
18
18
  @hash[:starts_at] = case @hash[:start]
19
- when String, Integer
20
- Time.at @hash[:start] / 1000
21
- when Time
22
- @hash[:start]
23
- end
19
+ when String, Integer
20
+ Time.at @hash[:start] / 1000
21
+ when Time
22
+ @hash[:start]
23
+ end
24
24
  end
25
25
 
26
26
  def set_ends_at
@@ -30,7 +30,5 @@ module Poms
30
30
  def duration
31
31
  (@hash[:duration].to_i / 1000).seconds
32
32
  end
33
-
34
33
  end
35
34
  end
36
-
@@ -1,13 +1,13 @@
1
1
  require 'poms/has_ancestors'
2
2
 
3
3
  module Poms
4
+ # Poms wrapper for a season of a serie.
4
5
  class Season < Poms::Builder::NestedOpenStruct
5
6
  include Poms::HasBaseAttributes
6
7
  include Poms::HasAncestors
7
8
 
8
9
  def related_group_mids
9
- descendant_of.map &:mid_ref
10
+ descendant_of.map(&:mid_ref)
10
11
  end
11
12
  end
12
13
  end
13
-
@@ -1,12 +1,12 @@
1
1
  require 'poms/has_base_attributes'
2
2
 
3
3
  module Poms
4
+ # POMS wrapper for a TV Serie.
4
5
  class Series < Poms::Builder::NestedOpenStruct
5
6
  include Poms::HasBaseAttributes
6
-
7
+
7
8
  def related_group_mids
8
- Poms.fetch_descendants_for_serie(mid, 'SEASON').map &:mid
9
- end
9
+ Poms.fetch_descendants_for_serie(mid, 'SEASON').map(&:mid)
10
+ end
10
11
  end
11
12
  end
12
-
@@ -1,3 +1,4 @@
1
+ # The version
1
2
  module Poms
2
- VERSION = '0.0.10'
3
+ VERSION = '1.0.0'
3
4
  end
@@ -1,7 +1,7 @@
1
1
  require 'poms/connect'
2
2
 
3
- # Constructs urls for Poms
4
3
  module Poms
4
+ # Views constructs the urls that can be used to access specific views in POMS.
5
5
  module Views
6
6
  include Poms::Connect
7
7
  extend self
@@ -20,7 +20,10 @@ module Poms
20
20
  construct_view_url('by-group', args)
21
21
  end
22
22
 
23
- def broadcasts_by_channel_and_start(channel, start_time = Time.now, end_time = 1.day.ago, limit = 1, descending = true)
23
+ # rubocop:disable Metrics/MethodLength
24
+ def broadcasts_by_channel_and_start(channel, start_time = Time.now,
25
+ end_time = 1.day.ago, limit = 1,
26
+ descending = true)
24
27
  args = {
25
28
  startkey: "[\"#{channel}\", #{to_poms_timestamp(start_time)}]",
26
29
  endkey: "[\"#{channel}\", #{to_poms_timestamp(end_time)}]",
@@ -31,6 +34,7 @@ module Poms
31
34
  }
32
35
  construct_view_url('broadcasts-by-channel-and-start', args)
33
36
  end
37
+ # rubocop:enable Metrics/MethodLength
34
38
 
35
39
  private
36
40
 
@@ -5,28 +5,29 @@ require 'poms/version'
5
5
  require 'rake'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = "poms"
8
+ spec.name = 'poms'
9
9
  spec.version = Poms::VERSION
10
- spec.authors = ["Tom Kruijsen", "Stijn Meurkens", "Tijn Schuurmans"]
11
- spec.email = ["tom@brightin.nl", "stijn@brightin.nl", "tijn@brightin.nl"]
12
- spec.description = %q{Interface to POMS CouchDB API}
13
- spec.summary = %q{Interfcae to POMS CouchDB API}
14
- spec.homepage = "https://github.com/brightin/poms"
15
- spec.license = "MIT"
10
+ spec.authors = ['Tom Kruijsen', 'Stijn Meurkens', 'Tijn Schuurmans']
11
+ spec.email = ['tom@brightin.nl', 'stijn@brightin.nl',
12
+ 'tijn@brightin.nl']
13
+ spec.description = 'Interface to POMS CouchDB API'
14
+ spec.summary = 'Interfcae to POMS CouchDB API'
15
+ spec.homepage = 'https://github.com/brightin/poms'
16
+ spec.license = 'MIT'
16
17
 
17
- spec.files = FileList['lib/**/*.rb', '[A-Z]*', 'spec/**/*'].to_a
18
+ spec.files = FileList['lib/**/*.rb', '[A-Z]*', 'spec/**/*'].to_a
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
24
- spec.add_development_dependency "guard"
25
- spec.add_development_dependency "guard-rspec"
26
- spec.add_development_dependency "fakeweb"
27
- spec.add_development_dependency "fabrication"
28
- spec.add_development_dependency "rubocop"
29
- spec.add_development_dependency "timecop"
30
- spec.add_development_dependency "vcr"
31
- spec.add_dependency "activesupport"
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'guard'
26
+ spec.add_development_dependency 'guard-rspec'
27
+ spec.add_development_dependency 'fakeweb'
28
+ spec.add_development_dependency 'fabrication'
29
+ spec.add_development_dependency 'rubocop'
30
+ spec.add_development_dependency 'timecop'
31
+ spec.add_development_dependency 'vcr'
32
+ spec.add_dependency 'activesupport'
32
33
  end
@@ -14,10 +14,13 @@ Fabricator(:poms_broadcast_pippi_langkous, class_name: :"Poms::Broadcast") do
14
14
  end
15
15
  end
16
16
 
17
- Fabricator(:poms_broadcast_multiple_schedule_events, class_name: :"Poms::Broadcast") do
17
+ Fabricator(:poms_broadcast_multiple_schedule_events,
18
+ class_name: :"Poms::Broadcast") do
18
19
  initialize_with do
19
20
  Poms::Builder.process_hash(
20
- JSON.parse File.read('spec/fixtures/poms_broadcast_multiple_schedule_events.json')
21
+ JSON.parse(
22
+ File.read('spec/fixtures/poms_broadcast_multiple_schedule_events.json')
23
+ )
21
24
  )
22
25
  end
23
26
  end
@@ -33,7 +36,9 @@ end
33
36
  Fabricator(:zapp_broadcasts, class_name: :array) do
34
37
  initialize_with do
35
38
  hash = JSON.parse File.read('spec/fixtures/poms_zapp.json')
36
- array = hash['rows'].take(10).map {|item| Poms::Builder.process_hash item['doc']}
39
+ array = hash['rows'].take(10).map do |item|
40
+ Poms::Builder.process_hash item['doc']
41
+ end
37
42
  array
38
43
  end
39
44
  end
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://rs-test.poms.omroep.nl/v1/api/media/redirects/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ accept-encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ accept:
13
+ - "*/*"
14
+ user-agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ date:
22
+ - Tue, 05 Jan 2016 16:49:33 GMT
23
+ server:
24
+ - Apache/2.4.12 (Unix) OpenSSL/1.0.1k
25
+ vary:
26
+ - Accept
27
+ cache-control:
28
+ - public
29
+ etag:
30
+ - '"47646207"'
31
+ last-modified:
32
+ - Tue, 05 Jan 2016 08:47:10 GMT
33
+ content-type:
34
+ - application/json;charset=utf-8
35
+ x-proxyinstancename:
36
+ - poms1a
37
+ set-cookie:
38
+ - balancer://poms8cluster=balancer.poms8aas; path=/;
39
+ transfer-encoding:
40
+ - chunked
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"lastUpdate":"2016-01-05T09:47:10.672+01:00","map":{"POMS_S_EO_097367":"VPWON_1257896"}}'
44
+ http_version: '1.1'
45
+ recorded_at: Tue, 06 Oct 2015 12:00:00 GMT
46
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://rs-test.poms.omroep.nl/v1/api/media/redirects/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ accept-encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ accept:
13
+ - "*/*"
14
+ user-agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ date:
22
+ - Tue, 05 Jan 2016 16:34:17 GMT
23
+ server:
24
+ - Apache/2.4.12 (Unix) OpenSSL/1.0.1k
25
+ vary:
26
+ - Accept
27
+ cache-control:
28
+ - public
29
+ etag:
30
+ - '"47646207"'
31
+ last-modified:
32
+ - Tue, 05 Jan 2016 08:47:10 GMT
33
+ content-type:
34
+ - application/json;charset=utf-8
35
+ x-proxyinstancename:
36
+ - poms1a
37
+ set-cookie:
38
+ - balancer://poms8cluster=balancer.poms8aas; path=/;
39
+ transfer-encoding:
40
+ - chunked
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"lastUpdate":"2016-01-05T09:47:10.672+01:00","map":{"POMS_S_EO_097367":"VPWON_1257896"}}'
44
+ http_version: '1.1'
45
+ recorded_at: Tue, 06 Oct 2015 12:00:00 GMT
46
+ recorded_with: VCR 2.9.3
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Poms do
4
-
5
4
  describe '#fetch_current_broadcast' do
6
5
  let(:current_broadcast) { Poms.fetch_current_broadcast('NED3') }
7
6
 
@@ -71,5 +70,5 @@ describe Poms do
71
70
  end
72
71
 
73
72
  describe '#upcoming_broadcasts'
74
- describe '#fetch_descendant_mids'
73
+ describe '#fetch_descendant_mids'
75
74
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Poms::Broadcast do
4
-
5
4
  let(:poms_broadcast) { Fabricate(:poms_broadcast) }
6
5
  # pippi langkous is a peculiar case, as it has no series, just a season
7
6
  let(:poms_pippi_langkous) { Fabricate(:poms_broadcast_pippi_langkous) }
@@ -15,18 +14,22 @@ describe Poms::Broadcast do
15
14
  end
16
15
 
17
16
  it 'correctly sets the description' do
18
- description = "Li biedt Barry een baantje aan bij de uitdragerij en vraagt zich meteen af of dat wel zo slim was. Timon en Joep zien de criminele organisatie de Rijland Angels. Timon wil naar hun loods, maar is dat wel een goed idee?"
17
+ description = 'Li biedt Barry een baantje aan bij de uitdragerij en ' \
18
+ 'vraagt zich meteen af of dat wel zo slim was. Timon en Joep zien de ' \
19
+ 'criminele organisatie de Rijland Angels. Timon wil naar hun loods, maar ' \
20
+ 'is dat wel een goed idee?'
19
21
  expect(poms_broadcast.description).to eq(description)
20
22
  end
21
23
 
22
- it 'converts schedule events to Poms::ScheduleEvent' do
24
+ it 'converts schedule events to Poms::ScheduleEvent' do
23
25
  poms_broadcast.schedule_events.each do |e|
24
26
  expect(e.class).to eq(Poms::ScheduleEvent)
25
27
  end
26
28
  end
27
29
 
28
30
  it 'correctly sets available until' do
29
- expect(poms_broadcast.available_until).to eq(Time.at(1435381968).to_datetime)
31
+ expect(poms_broadcast.available_until)
32
+ .to eq(Time.at(1_435_381_968).to_datetime)
30
33
  end
31
34
 
32
35
  it 'sets the serie correctly when a broadcast only has a season, no series' do
@@ -34,11 +37,13 @@ describe Poms::Broadcast do
34
37
  end
35
38
 
36
39
  it 'returns the available streams' do
37
- expect(poms_broadcast.odi_streams).to eq(["adaptive", "h264_sb", "h264_bb", "h264_std", "wvc1_std", "wmv_sb", "wmv_bb"])
40
+ expect(poms_broadcast.odi_streams)
41
+ .to eq(%w(adaptive h264_sb h264_bb h264_std wvc1_std wmv_sb wmv_bb))
38
42
  end
39
43
 
40
44
  it 'return the ancestors of the broadcast' do
41
45
  # I use to_set as the order does not matter
42
- expect(poms_broadcast.ancestor_mids.to_set).to eq(['POMS_S_KRO_059857', 'KRO_1521173'].to_set)
46
+ expect(poms_broadcast.ancestor_mids.to_set)
47
+ .to eq(%w(POMS_S_KRO_059857 KRO_1521173).to_set)
43
48
  end
44
49
  end