poms 2.3.0 → 2.6.0

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
- SHA1:
3
- metadata.gz: 85292060b0c5dea4b9f7398aeb16a9d0f6df5190
4
- data.tar.gz: ee21d0dd068514a0ee38d93a2719f9969fb48a28
2
+ SHA256:
3
+ metadata.gz: 46e3a79979a57e2affbc2189de4b437d60df153480000317be82b5e3c54eddb6
4
+ data.tar.gz: bc638af72e54f6a78d9aaa3facc97e33a8e9fbce7a32a6f7ae45dbb45468fc81
5
5
  SHA512:
6
- metadata.gz: 7b7b665ceb080c2f88785c76da9c833232180f2e25f789234f8d37928e636cdee8763229a6ea76fc1d86d10e1edf5407ef6c1da30799d053b5c96bc6a942b175
7
- data.tar.gz: 792cf6b0628b82dbced00ef5b6990219d99fb83a9b45ee15274ae4bc8d24dd410d29fc95cdeec17e0d31ce0c6c2b4963da967280f8d69cbaca747a74fc4e13e8
6
+ metadata.gz: 6444a71292577a4fdf53d1d91e65b01f22c5ebf0a8f39859382e81ecc75933d8a1877099e55e6ad3c2a8abb09bb4f3a707fecab199aab4bfe09a7e57b30b3cad
7
+ data.tar.gz: 1f2c35dfc336b503fa396e81e1a0847bdc240dc0a95e0cc234d541e16e3ee9a52d81fe6bbd8faa80cb618b14475d6b4ba9d8f3785fffcad33d275a385beaeebf
@@ -0,0 +1,15 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.3.4-node-browsers
6
+ environment:
7
+ POMS_KEY: key
8
+ POMS_ORIGIN: origin
9
+ POMS_SECRET: secret
10
+ TZ: "/usr/share/zoneinfo/Europe/Amsterdam"
11
+ steps:
12
+ - checkout
13
+ - run: bundle install
14
+ - run: bundle exec rubocop
15
+ - run: bundle exec rspec
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .ruby-version
19
+ .rbenv-vars
data/.rubocop.yml CHANGED
@@ -30,6 +30,9 @@ Style/AndOr:
30
30
  Style/FrozenStringLiteralComment:
31
31
  Enabled: false
32
32
 
33
+ Style/ModuleFunction:
34
+ Enabled: false
35
+
33
36
  ModuleLength:
34
37
  Exclude:
35
38
  - spec/**/*_spec.rb # specs are only in module for easier access to functions
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Poms Release notes
2
2
 
3
+ ## 2.6.0
4
+
5
+ * Include `Poms::Fields` in the main library file.
6
+
7
+ ## 2.5.1
8
+
9
+ * Actually filter out publications with `owner` `NEBO`.
10
+
11
+ ## 2.5.0
12
+
13
+ * ~Filter out publications with `owner` `NEBO`.~
14
+
15
+ Due to an error this version does not include the mentioned change.
16
+
17
+ ## 2.4.0
18
+
19
+ * Add functions for getting `publish_start` and `publish_stop` from Poms in `Poms::Fields`.
20
+
21
+ ## 2.3.1
22
+
23
+ * Add `Poms::Fields.descendants_of` which returns all descendantOf's of specific type.
24
+
25
+ ## 2.3.0
26
+
27
+ * Make `members` run as a POST request.
28
+
3
29
  ## 2.2.1
4
30
 
5
31
  * Add `Poms::Fields.broadcasts` which returns the associated broadcasters in an Array
data/README.md CHANGED
@@ -84,3 +84,7 @@ Gem | API
84
84
  3. Commit your changes (`git commit -am 'Add some feature'`)
85
85
  4. Push to the branch (`git push origin my-new-feature`)
86
86
  5. Create new Pull Request
87
+
88
+ ## Releasing
89
+
90
+ Make sure to use [Semantic Versioning](https://semver.org/) when bumping the version. To release tag the master branch with the version and then push to rubygems. `rake release` does this for you.
data/lib/poms.rb CHANGED
@@ -6,6 +6,7 @@ require 'poms/api/request'
6
6
  require 'poms/errors'
7
7
  require 'poms/api/search'
8
8
  require 'poms/configuration'
9
+ require 'poms/fields'
9
10
  require 'json'
10
11
 
11
12
  # Main interface for the POMS gem
data/lib/poms/fields.rb CHANGED
@@ -1,160 +1,13 @@
1
- require 'poms/timestamp'
1
+ require 'poms/fields/details'
2
+ require 'poms/fields/media'
3
+ require 'poms/fields/schedule'
2
4
 
3
5
  module Poms
4
- # This module contains functions to extract things from a Poms hash that may
5
- # be harder to access, or are accessed in multiple places.
6
+ # Collection module that import the various field modules to the higher
7
+ # Poms::Fields level
6
8
  module Fields
7
- module_function
8
-
9
- IMAGE_TYPE_PRIORITY = %w[PROMO_LANDSCAPE PICTURE].freeze
10
-
11
- # Returns the title, main by default
12
- def title(item, type = 'MAIN')
13
- value_of_type(item, 'titles', type)
14
- end
15
-
16
- # Returns the description, main by default
17
- def description(item, type = 'MAIN')
18
- value_of_type(item, 'descriptions', type)
19
- end
20
-
21
- def broadcasters(item)
22
- Array(item['broadcasters']).map do |key_value_pair|
23
- key_value_pair['value']
24
- end
25
- end
26
-
27
- # Returns the images from the hash
28
- def images(item)
29
- item['images'].try(:sort_by) do |i|
30
- image_order_index(i)
31
- end
32
- end
33
-
34
- # Extracts the image id from an image hash
35
- # Expects a hash of just an image from POMS
36
- def image_id(image)
37
- return unless image['imageUri']
38
- image['imageUri'].split(':').last
39
- end
40
-
41
- def image_order_index(image)
42
- IMAGE_TYPE_PRIORITY.index(image['type']) || IMAGE_TYPE_PRIORITY.size
43
- end
44
-
45
- # Returns the id of the first image or nil if there are none.
46
- def first_image_id(item)
47
- return unless images(item)
48
- image_id(images(item).first)
49
- end
50
-
51
- def mid(item)
52
- item['mid']
53
- end
54
-
55
- # Returns an array of odi stream types.
56
- # Note: this code is copied from Broadcast and it is assumed it was working
57
- # there.
58
- def odi_streams(item)
59
- locations = item['locations']
60
- return [] if locations.nil? || locations.empty?
61
- odi_streams = locations.select { |l| l['programUrl'].match(/^odi/) }
62
- streams = odi_streams.map do |l|
63
- l['programUrl'].match(%r{^[\w+]+\:\/\/[\w\.]+\/video\/(\w+)\/\w+})[1]
64
- end
65
- streams.uniq
66
- end
67
-
68
- # Returns the enddate of the publication of an internet vod if present.
69
- def available_until(item)
70
- return if item['predictions'].blank?
71
- internetvod = item['predictions']
72
- .find { |p| p['platform'] == 'INTERNETVOD' }
73
- return unless internetvod
74
- Timestamp.to_datetime(internetvod['publishStop'])
75
- end
76
-
77
- # Returns the index at which it is in the parent. When no
78
- # :member_of keyword is given, it will return the first found
79
- # index. Else, when a parent is found with matching member_of
80
- # midref, it returns that index. Else returns nil.
81
- # @param item The Poms Hash
82
- # @param optional :member_of The midref of parent for which we
83
- # seek the index
84
- def position(item, member_of: nil)
85
- parent(item, midref: member_of).try(:[], 'index')
86
- end
87
-
88
- # Finds a parent the data is "member of". If :midref is given, it
89
- # will look for the parent that matches that mid and return nil if
90
- # not found. Without the :midref it will return the first parent.
91
- # @param item The Poms Hash
92
- # @param optional midref The midref of parent we seek.
93
- def parent(item, midref: nil)
94
- if midref
95
- parents(item).find { |parent| parent['midRef'] == midref }
96
- else
97
- parents(item).first
98
- end
99
- end
100
-
101
- # Returns the parents that the element is member of. Will always
102
- # return an array.
103
- def parents(item)
104
- Array(item['memberOf'])
105
- end
106
-
107
- # Returns the NICAM age rating of the item or ALL if no age rating exists
108
- def age_rating(item)
109
- item.fetch('ageRating', 'ALL')
110
- end
111
-
112
- # Returns an array containing zero or more content ratings of the item
113
- # Possible content ratings are:
114
- # ANGST, DISCRIMINATIE, DRUGS_EN_ALCOHOL, GEWELD, GROF_TAALGEBRUIK and SEKS
115
- def content_ratings(item)
116
- item.fetch('contentRatings', [])
117
- end
118
-
119
- # Returns an array of start and end times for the scheduled events for
120
- # this item. It returns an empty array if no events are found. You can pass
121
- # in a block to filter the events on data that is not returned, like
122
- # channel.
123
- #
124
- # @param item The Poms hash
125
- def schedule_events(item)
126
- events = item.fetch('scheduleEvents', [])
127
- events = yield(events) if block_given?
128
- events.map { |event| hash_event(event) }
129
- end
130
-
131
- # Turns the event into a hash.
132
- def hash_event(event)
133
- {
134
- 'starts_at' => Timestamp.to_datetime(event.fetch('start')),
135
- 'ends_at' => Timestamp.to_datetime(event.fetch('start') +
136
- event.fetch('duration'))
137
- }
138
- end
139
- private_class_method :hash_event
140
-
141
- # Poms has arrays of hashes for some types that have a value and type. This
142
- # is a way to access those simply.
143
- #
144
- # Example:
145
- # item = {'titles' => [{'value' => 'Main title', 'type' => 'MAIN'},
146
- # {'value' => 'Subtitle', 'type' => 'SUB'}] }
147
- # value_of_type(item, 'titles', 'MAIN') => 'Main title'
148
- #
149
- # @param item The Poms hash
150
- # @param key The key of the array we want to look in
151
- # @param type The type to select
152
- def value_of_type(item, key, type)
153
- return unless item && item[key]
154
- res = item[key].find { |value| value['type'] == type }
155
- return unless res
156
- res['value']
157
- end
158
- private_class_method :value_of_type
9
+ extend Poms::Fields::Details
10
+ extend Poms::Fields::Media
11
+ extend Poms::Fields::Schedule
159
12
  end
160
13
  end
@@ -0,0 +1,98 @@
1
+ require 'poms/timestamp'
2
+ module Poms
3
+ module Fields
4
+ # Module to find details from for ex. attributes on poms items.
5
+ module Details
6
+ extend self
7
+
8
+ # Returns the title, main by default
9
+ def title(item, type = 'MAIN')
10
+ value_of_type(item, 'titles', type)
11
+ end
12
+
13
+ # Returns the description, main by default
14
+ def description(item, type = 'MAIN')
15
+ value_of_type(item, 'descriptions', type)
16
+ end
17
+
18
+ # Returns all the descendantOfs of the type given.
19
+ # @param item The Poms Hash
20
+ # @param type The type of descendantOfs we want
21
+ def descendants_of(item, type)
22
+ item['descendantOf'].select { |descendant| descendant['type'] == type }
23
+ end
24
+
25
+ def broadcasters(item)
26
+ Array(item['broadcasters']).map do |key_value_pair|
27
+ key_value_pair['value']
28
+ end
29
+ end
30
+
31
+ def mid(item)
32
+ item['mid']
33
+ end
34
+
35
+ # Returns the index at which it is in the parent. When no
36
+ # :member_of keyword is given, it will return the first found
37
+ # index. Else, when a parent is found with matching member_of
38
+ # midref, it returns that index. Else returns nil.
39
+ # @param item The Poms Hash
40
+ # @param optional :member_of The midref of parent for which we
41
+ # seek the index
42
+ def position(item, member_of: nil)
43
+ parent(item, midref: member_of).try(:[], 'index')
44
+ end
45
+
46
+ # Finds a parent the data is "member of". If :midref is given, it
47
+ # will look for the parent that matches that mid and return nil if
48
+ # not found. Without the :midref it will return the first parent.
49
+ # @param item The Poms Hash
50
+ # @param optional midref The midref of parent we seek.
51
+ def parent(item, midref: nil)
52
+ if midref
53
+ parents(item).find { |parent| parent['midRef'] == midref }
54
+ else
55
+ parents(item).first
56
+ end
57
+ end
58
+
59
+ # Returns the parents that the element is member of. Will always
60
+ # return an array.
61
+ def parents(item)
62
+ Array(item['memberOf'])
63
+ end
64
+
65
+ # Returns the NICAM age rating of the item or ALL if no age rating exists
66
+ def age_rating(item)
67
+ item.fetch('ageRating', 'ALL')
68
+ end
69
+
70
+ # Returns an array containing zero or more content ratings of the item
71
+ # Possible content ratings are:
72
+ # ANGST, DISCRIMINATIE, DRUGS_EN_ALCOHOL, GEWELD, GROF_TAALGEBRUIK and
73
+ # SEKS
74
+ def content_ratings(item)
75
+ item.fetch('contentRatings', [])
76
+ end
77
+
78
+ # Poms has arrays of hashes for some types that have a value and type.
79
+ # This is a way to access those simply.
80
+ #
81
+ # Example:
82
+ # item = {'titles' => [{'value' => 'Main title', 'type' => 'MAIN'},
83
+ # {'value' => 'Subtitle', 'type' => 'SUB'}] }
84
+ # value_of_type(item, 'titles', 'MAIN') => 'Main title'
85
+ #
86
+ # @param item The Poms hash
87
+ # @param key The key of the array we want to look in
88
+ # @param type The type to select
89
+ def value_of_type(item, key, type)
90
+ return unless item && item[key]
91
+ res = item[key].find { |value| value['type'] == type }
92
+ return unless res
93
+ res['value']
94
+ end
95
+ private_class_method :value_of_type
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,34 @@
1
+ module Poms
2
+ module Fields
3
+ # Module to retrieve media related information from poms items.
4
+ module Media
5
+ extend self
6
+
7
+ IMAGE_TYPE_PRIORITY = %w[PROMO_LANDSCAPE PICTURE].freeze
8
+
9
+ # Returns the images from the hash
10
+ def images(item)
11
+ item['images'].try(:sort_by) do |i|
12
+ image_order_index(i)
13
+ end
14
+ end
15
+
16
+ # Extracts the image id from an image hash
17
+ # Expects a hash of just an image from POMS
18
+ def image_id(image)
19
+ return unless image['imageUri']
20
+ image['imageUri'].split(':').last
21
+ end
22
+
23
+ def image_order_index(image)
24
+ IMAGE_TYPE_PRIORITY.index(image['type']) || IMAGE_TYPE_PRIORITY.size
25
+ end
26
+
27
+ # Returns the id of the first image or nil if there are none.
28
+ def first_image_id(item)
29
+ return unless images(item)
30
+ image_id(images(item).first)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,80 @@
1
+ require 'poms/timestamp'
2
+
3
+ module Poms
4
+ module Fields
5
+ # modeule to retrieve scheduling/timtable related information from
6
+ # poms items.
7
+ module Schedule
8
+ extend self
9
+
10
+ # Returns an array of odi stream types.
11
+ # Note: this code is copied from Broadcast
12
+ # and it is assumed it was working there.
13
+ def odi_streams(item)
14
+ locations = item['locations']
15
+ return [] if locations.nil? || locations.empty?
16
+ odi_streams = locations.select { |l| l['programUrl'].match(/^odi/) }
17
+ streams = odi_streams.map do |l|
18
+ l['programUrl'].match(%r{^[\w+]+\:\/\/[\w\.]+\/video\/(\w+)\/\w+})[1]
19
+ end
20
+ streams.uniq
21
+ end
22
+
23
+ # Returns an array of start and end times for the scheduled events for
24
+ # this item. It returns an empty array if no events are found.
25
+ # You can pass in a block to filter the events on data that is not
26
+ # returned, like channel.
27
+ #
28
+ # @param item The Poms hash
29
+ def schedule_events(item)
30
+ events = item.fetch('scheduleEvents', [])
31
+ events = yield(events) if block_given?
32
+ events.map { |event| hash_event(event) }
33
+ end
34
+
35
+ # Returns the first publication from an items location array which has
36
+ # INTERNETVOD and is PUBLISHED and does not have owner NEBO.
37
+ def publication(poms_item)
38
+ return if poms_item.fetch('locations', nil).blank?
39
+ poms_item.fetch('locations', []).find do |item|
40
+ item.fetch('platform', '') == 'INTERNETVOD' &&
41
+ item.fetch('workflow', '') == 'PUBLISHED' &&
42
+ item.fetch('owner', '') != 'NEBO'
43
+ end
44
+ end
45
+
46
+ # Return the publishStop datetime from a publication
47
+ def publish_stop(poms_item)
48
+ published_item = publication(poms_item)
49
+ return unless published_item
50
+ Timestamp.to_datetime(published_item['publishStop'])
51
+ end
52
+
53
+ # Return the publishStart datetime from a publication
54
+ def publish_start(poms_item)
55
+ published_item = publication(poms_item)
56
+ return unless published_item
57
+ Timestamp.to_datetime(published_item['publishStart'])
58
+ end
59
+
60
+ # Returns the enddate of the publication of an internet vod if present.
61
+ def available_until(item)
62
+ return if item['predictions'].blank?
63
+ internetvod = item['predictions']
64
+ .find { |p| p['platform'] == 'INTERNETVOD' }
65
+ return unless internetvod
66
+ Timestamp.to_datetime(internetvod['publishStop'])
67
+ end
68
+
69
+ # Turns the event into a hash.
70
+ def hash_event(event)
71
+ {
72
+ 'starts_at' => Timestamp.to_datetime(event.fetch('start')),
73
+ 'ends_at' => Timestamp.to_datetime(event.fetch('start') +
74
+ event.fetch('duration'))
75
+ }
76
+ end
77
+ private_class_method :hash_event
78
+ end
79
+ end
80
+ end
data/lib/poms/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # The version
2
2
  module Poms
3
- VERSION = '2.3.0'.freeze
3
+ VERSION = '2.6.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poms
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Kruijsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-22 00:00:00.000000000 Z
11
+ date: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -199,6 +199,7 @@ executables: []
199
199
  extensions: []
200
200
  extra_rdoc_files: []
201
201
  files:
202
+ - ".circleci/config.yml"
202
203
  - ".gitignore"
203
204
  - ".rubocop.yml"
204
205
  - ".rubocop_todo.yml"
@@ -210,7 +211,6 @@ files:
210
211
  - Rakefile
211
212
  - bin/rspec
212
213
  - bin/rubocop
213
- - circle.yml
214
214
  - examples/fetch.rb
215
215
  - examples/search.rb
216
216
  - lib/poms.rb
@@ -228,6 +228,9 @@ files:
228
228
  - lib/poms/configuration.rb
229
229
  - lib/poms/errors.rb
230
230
  - lib/poms/fields.rb
231
+ - lib/poms/fields/details.rb
232
+ - lib/poms/fields/media.rb
233
+ - lib/poms/fields/schedule.rb
231
234
  - lib/poms/timestamp.rb
232
235
  - lib/poms/version.rb
233
236
  - poms.gemspec
@@ -250,8 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
253
  - !ruby/object:Gem::Version
251
254
  version: '0'
252
255
  requirements: []
253
- rubyforge_project:
254
- rubygems_version: 2.6.13
256
+ rubygems_version: 3.0.3
255
257
  signing_key:
256
258
  specification_version: 4
257
259
  summary: Interface to POMS CouchDB API
data/circle.yml DELETED
@@ -1,13 +0,0 @@
1
- machine:
2
- ruby:
3
- version: 2.3.4
4
- timezone:
5
- Europe/Amsterdam
6
- environment:
7
- POMS_KEY: key
8
- POMS_ORIGIN: origin
9
- POMS_SECRET: secret
10
- test:
11
- override:
12
- - bundle exec rubocop
13
- - bundle exec rspec