wcc-media-client 0.4.8 → 0.4.13

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: 4d18367e52ec3f09cc84c5959e68a8bbe36c53f2
4
- data.tar.gz: 54abfc8029902f64f480c1260c6c69fd24954a5e
3
+ metadata.gz: c5267da3904b4c03dcd2806653a5416dc8c2be9b
4
+ data.tar.gz: a8ff4629d184ecdcfe7a946df52ab1b4ced3e92b
5
5
  SHA512:
6
- metadata.gz: f519e7ab6c4c3c07989a0656c75f83ad5908bc30874aaad98a0499eda8c3709a7b1660698f14cf8aa8a8861901f5492aebf9ea9db8e6a1cc5216347774c9c038
7
- data.tar.gz: dfa00ce89851417a5e0d52aef98f52e5cf07e51dd284ffa1570956fdd4f14cc4a55996331529c5c648463957ede12c05d2a1e52f288204361cd1affd1b5606ec
6
+ metadata.gz: c5bbf278905e91d9f8937a83ebd9af3a18de8ae7a8b7078675b505d1e76403feddb648316db8f8f8f50cd593f10aec7847bd5ef4988f28b8a1e13b971f184534
7
+ data.tar.gz: 1b857617295dfb1e684ae58f8a7fcd4f7f6616ad785c0b3b810fa7769e7db5e64e1eb24e1bff336fb2b906e004e0110fff437a2314b6f9f5a19b23b98c27a68e
@@ -10,3 +10,6 @@ Style/ClassAndModuleChildren:
10
10
  Style/MultilineBlockChain:
11
11
  Exclude:
12
12
  - 'spec/**/*'
13
+
14
+ Rails/TimeZone:
15
+ Enabled: false
@@ -10,6 +10,15 @@ module WCC
10
10
  @cache_key = "#{self.class.name}/#{key}"
11
11
  end
12
12
 
13
+ def last_modified
14
+ return @last_modified if @last_modified
15
+
16
+ last_modified =
17
+ (headers&.fetch('Last-Modified', nil) if respond_to?(:headers))
18
+ @last_modified = Time.parse(last_modified) if last_modified && /\S/.match(last_modified)
19
+ end
20
+ alias_method :updated_at, :last_modified
21
+
13
22
  def self.hash_cache_key(hash)
14
23
  Digest::SHA1.hexdigest(Marshal.dump(hash))
15
24
  end
@@ -4,6 +4,7 @@ require_relative 'series'
4
4
  require_relative 'speaker'
5
5
  require_relative 'tag'
6
6
  require_relative 'playlist'
7
+ require_relative 'live_stream'
7
8
  require_relative 'client/response'
8
9
 
9
10
  module WCC
@@ -35,7 +36,8 @@ module WCC
35
36
  'series' => WCC::Media::Series,
36
37
  'speakers' => WCC::Media::Speaker,
37
38
  'tags' => WCC::Media::Tag,
38
- 'playlists' => WCC::Media::Playlist
39
+ 'playlists' => WCC::Media::Playlist,
40
+ 'streams' => WCC::Media::LiveStream
39
41
  }.freeze
40
42
  attr_reader(*RESOURCES.keys)
41
43
 
@@ -44,7 +46,8 @@ module WCC
44
46
  def initialize(**options)
45
47
  options = {
46
48
  api_url: 'https://media.watermark.org/api/v1/',
47
- response_class: Response
49
+ response_class: Response,
50
+ adapter: :typhoeus
48
51
  }.merge!(options)
49
52
  super(**options)
50
53
 
@@ -60,7 +63,7 @@ module WCC
60
63
 
61
64
  resp = client.get(
62
65
  "#{model.endpoint}/#{id}",
63
- default_params('target').merge(params)
66
+ default_params('target').merge(params),
64
67
  )
65
68
  resp.assert_ok!
66
69
  model.new(resp.body[model.key], resp.headers.freeze)
@@ -15,7 +15,7 @@ module WCC
15
15
  end
16
16
 
17
17
  def page_items
18
- body['messages'] || body['series'] || body['speakers'] || body['tags']
18
+ body['messages'] || body['series'] || body['speakers'] || body['tags'] || body['streams']
19
19
  end
20
20
 
21
21
  def next_page_query
@@ -59,10 +59,18 @@ class WCC::Media::Engine < ::Rails::Engine
59
59
 
60
60
  initializer 'configure WCC::Media Toots' do
61
61
  ActiveSupport::Notifications.subscribe 'routes_loaded.engine.media.wcc' do
62
- ::Toot.config.callback_url ||= Rails.application.routes.url_helpers.wcc_media_url +
63
- '/callbacks'
64
-
65
- WCC::Media::Engine.register_subscriptions
62
+ ::Toot.config.callback_url ||=
63
+ begin
64
+ Rails.application.routes.url_helpers.wcc_media_url + '/callbacks'
65
+ rescue ArgumentError => ex
66
+ raise unless ex.message =~ /^Missing host to link to/
67
+ end
68
+
69
+ if ::Toot.config.callback_url.nil?
70
+ Rails.logger.error "Toot.config.callback_url not set! Media webhooks will not be subscribed."
71
+ else
72
+ WCC::Media::Engine.register_subscriptions
73
+ end
66
74
  end
67
75
  end
68
76
 
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ class WCC::Media::LiveStream < WCC::Media::Base
4
+ active_record_shim do
5
+ endpoint 'streams'
6
+ key 'stream'
7
+ filters %w[
8
+ ].freeze
9
+ end
10
+
11
+ %w[
12
+ title
13
+ description
14
+ ].each do |att|
15
+ define_method att do
16
+ raw[att]
17
+ end
18
+ end
19
+
20
+ %w[
21
+ current_event
22
+ next_event
23
+ ].each do |att|
24
+ define_method att do
25
+ Event.new(raw[att]) if raw[att]
26
+ end
27
+ end
28
+
29
+ def active?
30
+ current_event.present?
31
+ end
32
+
33
+ class Event < WCC::Media::Base
34
+ %w[
35
+ title
36
+ description
37
+ embed_code
38
+ stream_url
39
+ starts_at
40
+ ends_at
41
+ duration
42
+ ].each do |att|
43
+ define_method att do
44
+ raw[att]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -8,6 +8,7 @@ class WCC::Media::Message < WCC::Media::Base
8
8
  on_or_after_date
9
9
  on_or_before_date
10
10
  tag_id
11
+ playlist_id
11
12
  speaker_id
12
13
  scripture_book_id
13
14
  series_id
@@ -37,6 +38,10 @@ class WCC::Media::Message < WCC::Media::Base
37
38
  (raw['speakers'] || []).map { |val| WCC::Media::Speaker.new(val) }
38
39
  end
39
40
 
41
+ def playlists
42
+ (raw['playlists'] || []).map { |val| WCC::Media::Playlist.new(val) }
43
+ end
44
+
40
45
  def tags
41
46
  (raw['tags'] || []).map { |val| WCC::Media::Tag.new(val) }
42
47
  end
@@ -76,12 +81,21 @@ class WCC::Media::Message < WCC::Media::Base
76
81
  .any? { |k, v| /video/.match(k) && v && !v.empty? }
77
82
  end
78
83
 
84
+ def has_audio? # rubocop:disable Naming/PredicateName
85
+ assets.each_pair
86
+ .any? { |k, v| /^audio/.match(k) && v && !v.empty? }
87
+ end
88
+
79
89
  def to_param
80
90
  "#{id}-#{slug}"
81
91
  end
82
92
 
83
93
  WCC::Media::TagGroup.all.each do |tag_group|
84
- define_method(tag_group.name.downcase) do
94
+ method_name = tag_group.name.downcase.to_sym
95
+ # except :meta (different definition above)
96
+ next if instance_methods.include?(method_name)
97
+
98
+ define_method(method_name) do
85
99
  tags.select { |t| t.tag_group == tag_group }
86
100
  end
87
101
  end
@@ -29,6 +29,7 @@ class WCC::Media::Series < WCC::Media::Base
29
29
 
30
30
  %w[
31
31
  images
32
+ series_type
32
33
  ].each do |att|
33
34
  define_method att do
34
35
  OpenStruct.new(raw[att]) if raw[att]
@@ -1,5 +1,5 @@
1
1
  module WCC
2
2
  module Media
3
- VERSION = '0.4.8'.freeze
3
+ VERSION = '0.4.13'.freeze
4
4
  end
5
5
  end
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'guard-rubocop', '~> 1.3'
36
36
  spec.add_development_dependency 'http', '> 1.0', '< 3.0'
37
37
  spec.add_development_dependency 'httplog', '~> 1.0'
38
+ spec.add_development_dependency 'nio4r', '2.5.2'
38
39
  spec.add_development_dependency 'rails', '~> 5.0'
39
40
  spec.add_development_dependency 'rake', '~> 12.3'
40
41
  spec.add_development_dependency 'responders', '< 3.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcc-media-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watermark Dev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-04 00:00:00.000000000 Z
11
+ date: 2020-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wcc-api
@@ -156,6 +156,20 @@ dependencies:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
158
  version: '1.0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: nio4r
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - '='
164
+ - !ruby/object:Gem::Version
165
+ version: 2.5.2
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - '='
171
+ - !ruby/object:Gem::Version
172
+ version: 2.5.2
159
173
  - !ruby/object:Gem::Dependency
160
174
  name: rails
161
175
  requirement: !ruby/object:Gem::Requirement
@@ -357,6 +371,7 @@ files:
357
371
  - lib/wcc/media/client.rb
358
372
  - lib/wcc/media/client/response.rb
359
373
  - lib/wcc/media/engine.rb
374
+ - lib/wcc/media/live_stream.rb
360
375
  - lib/wcc/media/message.rb
361
376
  - lib/wcc/media/playlist.rb
362
377
  - lib/wcc/media/rails.rb
@@ -371,7 +386,7 @@ homepage: https://github.com/watermarkchurch/media/wcc-media-client
371
386
  licenses:
372
387
  - MIT
373
388
  metadata: {}
374
- post_install_message:
389
+ post_install_message:
375
390
  rdoc_options: []
376
391
  require_paths:
377
392
  - lib
@@ -386,9 +401,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
386
401
  - !ruby/object:Gem::Version
387
402
  version: '0'
388
403
  requirements: []
389
- rubyforge_project:
404
+ rubyforge_project:
390
405
  rubygems_version: 2.5.2
391
- signing_key:
406
+ signing_key:
392
407
  specification_version: 4
393
408
  summary: ''
394
409
  test_files: []