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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d31efe5a7f4dfc90e786616d1e1780abaaf3d305
4
- data.tar.gz: 306d122d776ab51eea8b9bbf86616ac0b93fabb0
3
+ metadata.gz: f4029a83f6655a6ed4e07fa351388d48a8e208e4
4
+ data.tar.gz: 22f043f05acfb95f5a1f017943b935527af00c6b
5
5
  SHA512:
6
- metadata.gz: 77070886f824e6bfaf67e05f23dcd5379b71959f31515bb0969b5a3c6076af366c2fc0f9e93dc782e3b1fd5638165e1c7f61490403e82175c5a6b2ebadbb88b6
7
- data.tar.gz: f93fc6c4eb0c2b475ff3e1abae3703cd8dbfe5de3ae5806952b0a6fdb47f6e48516f7cadd8992b78a07909858b5a8de9b5a0b4643e7f93f2248b39b926062dae
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' => 'snippet',
24
+ 'part' => video_details_params.parts.join(',')
25
25
  })
26
26
  end
27
27
  end
@@ -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)
@@ -5,6 +5,7 @@ FactoryGirl.define do
5
5
  factory :brainzz_published_video do
6
6
  title { FactoryGirl.generate :brainzz_video_title }
7
7
  published_at { Time.now - 60 * 60 * 24 * rand(1_500) }
8
+ duration { rand(100) }
8
9
  end
9
10
  end
10
11
  end
@@ -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
@@ -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.10
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-23 00:00:00.000000000 Z
13
+ date: 2015-06-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday