brainzz 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brainzz/commands/video_details_command.rb +3 -3
- data/lib/brainzz/core.rb +2 -2
- data/lib/brainzz/factories/video.rb +1 -0
- data/lib/brainzz/models/base_model.rb +28 -0
- data/lib/brainzz/models/video.rb +10 -1
- data/lib/brainzz/params/video_details_params.rb +10 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4029a83f6655a6ed4e07fa351388d48a8e208e4
|
4
|
+
data.tar.gz: 22f043f05acfb95f5a1f017943b935527af00c6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7f6c8c8f6393af9000337b113769d5dd494896a69d3ed8223eb9d22620790e6b4ec0b3f96ca3bff6b457076e5a09b89e5a8f918945d124b8d9fbee934d68811
|
7
|
+
data.tar.gz: a27e765087a0ecde171d15a31c884ec97689f667e0bedf7f63b73b1d86b118031199f3c517751868a4e927b0ecfcad39ef1207f15bb6a5a9f00afa0364436a9a
|
@@ -3,8 +3,8 @@ module Brainzz
|
|
3
3
|
class << self
|
4
4
|
private
|
5
5
|
|
6
|
-
def on_execute(video_ids)
|
7
|
-
video_details_params = VideoDetailsParams.new(video_ids)
|
6
|
+
def on_execute(video_ids, options={})
|
7
|
+
video_details_params = VideoDetailsParams.new(video_ids, options)
|
8
8
|
|
9
9
|
if video_details_params.valid?
|
10
10
|
response = get(video_details_params)
|
@@ -21,7 +21,7 @@ module Brainzz
|
|
21
21
|
def params(video_details_params)
|
22
22
|
super.merge({
|
23
23
|
'id' => video_details_params.video_ids.join(','),
|
24
|
-
'part' => '
|
24
|
+
'part' => video_details_params.parts.join(',')
|
25
25
|
})
|
26
26
|
end
|
27
27
|
end
|
data/lib/brainzz/core.rb
CHANGED
@@ -6,8 +6,8 @@ module Brainzz
|
|
6
6
|
PlaylistItemsCommand.execute playlist_id, response
|
7
7
|
end
|
8
8
|
|
9
|
-
def video_details_for(video_ids)
|
10
|
-
VideoDetailsCommand.execute video_ids
|
9
|
+
def video_details_for(video_ids, options={})
|
10
|
+
VideoDetailsCommand.execute video_ids, options
|
11
11
|
end
|
12
12
|
|
13
13
|
def views_by_day_for(video_id, start_date, end_date)
|
@@ -21,5 +21,33 @@ module Brainzz
|
|
21
21
|
return nil unless value.is_a?(String)
|
22
22
|
Time.parse value
|
23
23
|
end
|
24
|
+
|
25
|
+
def transform_duration(value)
|
26
|
+
return nil unless value.is_a?(String)
|
27
|
+
match = value.match(iso8601_duration_regex)
|
28
|
+
iso8601_to_seconds(match) if match
|
29
|
+
end
|
30
|
+
|
31
|
+
def iso8601_to_seconds(iso8601)
|
32
|
+
weeks = iso8601[:weeks].to_i
|
33
|
+
days = iso8601[:days].to_i
|
34
|
+
hours = iso8601[:hours].to_i
|
35
|
+
minutes = iso8601[:min].to_i
|
36
|
+
seconds = iso8601[:sec].to_i
|
37
|
+
(((((weeks * 7) + days) * 24 + hours) * 60) + minutes) * 60 + seconds
|
38
|
+
end
|
39
|
+
|
40
|
+
def iso8601_duration_regex
|
41
|
+
/^
|
42
|
+
P
|
43
|
+
(?:|(?<weeks>\d*?)W)
|
44
|
+
(?:|(?<days>\d*?)D)
|
45
|
+
(?:|
|
46
|
+
T
|
47
|
+
(?:|(?<hours>\d*?)H)
|
48
|
+
(?:|(?<min>\d*?)M)
|
49
|
+
(?:|(?<sec>\d*?)S)
|
50
|
+
)$/x
|
51
|
+
end
|
24
52
|
end
|
25
53
|
end
|
data/lib/brainzz/models/video.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Brainzz
|
2
2
|
class Video < BaseModel
|
3
|
-
attr_accessor :id, :title, :published_at
|
3
|
+
attr_accessor :id, :title, :published_at, :duration
|
4
4
|
|
5
5
|
def initialize(hash = {})
|
6
6
|
@hash = hash || {}
|
@@ -8,10 +8,19 @@ module Brainzz
|
|
8
8
|
@id = transform(hash_id)
|
9
9
|
@title = transform(hash_title)
|
10
10
|
@published_at = transform_date(hash_published_at)
|
11
|
+
@duration = transform_duration(hash_duration)
|
11
12
|
end
|
12
13
|
|
13
14
|
private
|
14
15
|
|
16
|
+
def content_details
|
17
|
+
@hash['contentDetails'] || {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def hash_duration
|
21
|
+
content_details['duration']
|
22
|
+
end
|
23
|
+
|
15
24
|
def snippet
|
16
25
|
@hash['snippet'] || {}
|
17
26
|
end
|
@@ -1,13 +1,20 @@
|
|
1
1
|
module Brainzz
|
2
2
|
class VideoDetailsParams
|
3
|
-
attr_reader :video_ids
|
3
|
+
attr_reader :video_ids, :parts
|
4
4
|
|
5
|
-
def initialize(video_ids)
|
5
|
+
def initialize(video_ids, options={})
|
6
6
|
@video_ids = video_ids
|
7
|
+
@parts = options.fetch(:parts, default_video_parts)
|
7
8
|
end
|
8
9
|
|
9
10
|
def valid?
|
10
|
-
!!(@video_ids && !@video_ids.empty?)
|
11
|
+
!!(@video_ids && !@video_ids.empty?) && !!(@parts && !@parts.empty?)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def default_video_parts
|
17
|
+
%w(snippet contentDetails)
|
11
18
|
end
|
12
19
|
end
|
13
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brainzz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Herrick
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-06-
|
13
|
+
date: 2015-06-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|