ooyala-rails 0.2.0 → 0.3.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
2
  SHA1:
3
- metadata.gz: 9f8e931343ce0da4499b5c728b8f6d0510378e31
4
- data.tar.gz: 45a71a9033a153bc9b70d5ee409664142560fb52
3
+ metadata.gz: 726a83b81cb27ce6bd9e2b36986483fae01dd5c6
4
+ data.tar.gz: 7d1d053339cbad000a480b5cc9ed064eee8a698e
5
5
  SHA512:
6
- metadata.gz: 38abef2402ac5014c00b96a2031b7bfc1d06ee0bdc9884caa65968d8d6e8b5acd14eb207846e56dc495b6e6f970d7da47e3437da74ec930ab306102456439e60
7
- data.tar.gz: d74a7a8086013fbd8f10d7898cb3297e35373988e3011729e77e849c0c9d80568bf68104cdfb481f9c7a9803b893259923d448716fcdab914883d35a7ff5aa7f
6
+ metadata.gz: 9176b0d405e1c1a666a6c7f24a01e13383467495e651d8f590a2401f26fd33d406aaa27ffd04ec71a8d0ab8462b941947a88526a0fddc4491232e8480d304c47
7
+ data.tar.gz: d6c5ebac286172c76503558e3d165c680e47cbe49006720870613a2e42bba9da27ccde30850e739756c6d8cb9856f0ecf2028dc61c1d5efccea1f71a55d0f3b0
data/lib/ooyala/rails.rb CHANGED
@@ -1,12 +1,10 @@
1
- require 'ooyala-v2-api'
1
+ require 'ooyala/rails/config'
2
+ require 'ooyala/rails/engine'
2
3
  require 'ooyala/rails/version'
4
+ require 'ooyala/rails/video'
3
5
 
4
6
  module Ooyala
5
7
  module Rails
6
- def self.api
7
- @api ||= Ooyala::API.new(config.api_key, config.secret_key)
8
- end
9
-
10
8
  def self.config
11
9
  @config ||= Config.new
12
10
  end
@@ -16,17 +14,7 @@ module Ooyala
16
14
  end
17
15
 
18
16
  def self.configured?
19
- config.api_key.present?
20
- end
21
-
22
- class Config
23
- attr_accessor :api_key
24
- attr_accessor :player_id
25
- attr_accessor :player_options
26
- attr_accessor :secret_key
27
- end
28
-
29
- class Engine < ::Rails::Engine
17
+ config.configured?
30
18
  end
31
19
  end
32
20
  end
@@ -0,0 +1,14 @@
1
+ module Ooyala
2
+ module Rails
3
+ class Config
4
+ attr_accessor :api_key
5
+ attr_accessor :player_id
6
+ attr_accessor :player_options
7
+ attr_accessor :secret_key
8
+
9
+ def configured?
10
+ api_key.present?
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ module Ooyala
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  module Ooyala
2
2
  module Rails
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -0,0 +1,56 @@
1
+ require 'ooyala-v2-api'
2
+
3
+ module Ooyala
4
+ module Rails
5
+ class Video
6
+ NotFound = Class.new(StandardError)
7
+
8
+ attr_reader :embed_code
9
+ class << self
10
+ delegate :config, to: Ooyala::Rails
11
+ end
12
+ delegate :api, to: :class
13
+
14
+ def initialize(embed_code)
15
+ @embed_code = embed_code
16
+ end
17
+
18
+ def self.api
19
+ @api ||= Ooyala::API.new(config.api_key, config.secret_key)
20
+ end
21
+
22
+ def self.find(embed_code)
23
+ new(embed_code).tap do |video|
24
+ raise NotFound unless video.exists?
25
+ end
26
+ end
27
+
28
+ def duration
29
+ return unless duration_in_seconds
30
+ mins = (duration_in_seconds / 60.0).floor
31
+ secs = duration_in_seconds % 60
32
+ '%s:%s' % [mins, secs]
33
+ end
34
+
35
+ def exists?
36
+ data
37
+ end
38
+
39
+ def preview_image_url
40
+ data['preview_image_url'] if data
41
+ end
42
+
43
+ private
44
+
45
+ def data
46
+ if embed_code.present?
47
+ @data ||= api.get('assets', where: "embed_code = '#{embed_code}'").fetch('items').first
48
+ end
49
+ end
50
+
51
+ def duration_in_seconds
52
+ data['duration'] if data
53
+ end
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooyala-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zubin Henner
@@ -83,7 +83,10 @@ files:
83
83
  - bin/console
84
84
  - bin/setup
85
85
  - lib/ooyala/rails.rb
86
+ - lib/ooyala/rails/config.rb
87
+ - lib/ooyala/rails/engine.rb
86
88
  - lib/ooyala/rails/version.rb
89
+ - lib/ooyala/rails/video.rb
87
90
  - ooyala-rails.gemspec
88
91
  homepage: https://github.com/zubin/ooyala-rails
89
92
  licenses: []