brainzz 0.0.1 → 0.0.2

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: 4e8670e6642146a2996078834b04eb24c2b7838b
4
- data.tar.gz: 5f750156db6327e48177550ca261d6b633b6a8fd
3
+ metadata.gz: 5593938f8cecb4660e3c474a61dcbf908a74f0a2
4
+ data.tar.gz: 2db3a9a659c9241a7501870fb212a57f73accfa7
5
5
  SHA512:
6
- metadata.gz: 85c8f53246fcb37d36d64a3ae1872dffef9b84e4ecb1506f6cf966966552e15869814cfd179cafdfbbf278812a746ffaa3a5e662133d81c6f6f8a68b21e01888
7
- data.tar.gz: 2a815bee5f230d98c9820d91c6dbb06639cb974e8f8ceb1f9d5c90a3eff6bdd6a05762e0fa8501e8f259fd3a2e3dfb95cc272e13163798fd22364929702cacc3
6
+ metadata.gz: 2387071a7d82e12d58798ccade04c873531aa77335fc1931c4a61f2ec688c3e30b290567ed02805e0f40ad323adeea368edc64e4eda774a3daa81d6bb7df8111
7
+ data.tar.gz: 5821bb60c0a98d8c8f04319450d4ac282c609800352781518d776cf4415bc6525facb147d2a6014cc57807dad56b792ea4b2992e4af84cf19dc7706f109544d1
data/lib/brainzz.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'date'
2
3
 
3
4
  require 'faraday'
4
5
 
@@ -9,14 +10,17 @@ end
9
10
 
10
11
  require_relative 'brainzz/core'
11
12
 
13
+ require_relative 'brainzz/models/base_model'
12
14
  require_relative 'brainzz/models/video'
13
15
  require_relative 'brainzz/models/playlist_item'
14
16
  require_relative 'brainzz/models/playlist_items_wrapper'
15
17
 
16
18
  require_relative 'brainzz/responses/playlist_items_response'
19
+ require_relative 'brainzz/responses/video_details_response'
17
20
 
18
21
  require_relative 'brainzz/commands/base_command'
19
22
  require_relative 'brainzz/commands/playlist_items_command'
23
+ require_relative 'brainzz/commands/video_details_command'
20
24
 
21
25
  module Brainzz
22
26
  extend Core
@@ -0,0 +1,21 @@
1
+ module Brainzz
2
+ module VideoDetailsCommand
3
+ extend BaseCommand
4
+ extend self
5
+
6
+ def execute(video_ids)
7
+ @video_ids = video_ids
8
+ response = connection.get('videos', params)
9
+ VideoDetailsResponse.new response
10
+ end
11
+
12
+ private
13
+
14
+ def url_params
15
+ {
16
+ 'id' => @video_ids.join(','),
17
+ 'part' => 'snippet',
18
+ }
19
+ end
20
+ end
21
+ end
data/lib/brainzz/core.rb CHANGED
@@ -5,5 +5,9 @@ module Brainzz
5
5
  def playlist_items_for(playlist_id, response = nil)
6
6
  PlaylistItemsCommand.execute playlist_id, response
7
7
  end
8
+
9
+ def video_details_for(video_ids)
10
+ VideoDetailsCommand.execute(video_ids)
11
+ end
8
12
  end
9
13
  end
@@ -0,0 +1,4 @@
1
+ require_relative 'factories/sequences'
2
+ require_relative 'factories/video'
3
+ require_relative 'factories/playlist_item'
4
+ require_relative 'factories/playlist_items_wrapper'
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :brainzz_playlist_item, :class => Brainzz::PlaylistItem do
3
+ id { FactoryGirl.generate :brainzz_playlist_item_id }
4
+ video { FactoryGirl.build :brainzz_video }
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :brainzz_playlist_items_wrapper,
3
+ :class => Brainzz::PlaylistItemsWrapper do
4
+ next_page_token { FactoryGirl.generate :brainzz_next_page_token }
5
+ playlist_items { FactoryGirl.build_list :brainzz_playlist_item, 3 }
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ FactoryGirl.define do
2
+ sequence(:brainzz_fake_string) { ['foo', 'bar', 'baz'].sample }
3
+
4
+ sequence(:brainzz_video_id) { |n| "video-id-#{n}" }
5
+ sequence(:brainzz_video_title) do
6
+ "video-title-#{FactoryGirl.generate(:brainzz_fake_string)}"
7
+ end
8
+
9
+ sequence(:brainzz_playlist_item_id) { |n| "playlist-item-id-#{n}" }
10
+
11
+ sequence(:brainzz_next_page_token) { |n| "page-token-#{n}" }
12
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :brainzz_video, :class => Brainzz::Video do
3
+ id { FactoryGirl.generate :brainzz_video_id }
4
+
5
+ factory :brainzz_published_video do
6
+ title { FactoryGirl.generate :brainzz_video_title }
7
+ published_at { DateTime.now - rand(1_500) }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ module Brainzz
2
+ class BaseModel
3
+ private
4
+
5
+ def transform(value)
6
+ case value
7
+ when String
8
+ value = transform_string(value)
9
+ end
10
+ value
11
+ end
12
+
13
+ def transform_string(value)
14
+ value = value.strip
15
+ value = nil if value == ''
16
+ value
17
+ end
18
+
19
+ def transform_date(value)
20
+ value = transform(value)
21
+ return nil unless value.is_a?(String)
22
+ DateTime.parse(value)
23
+ end
24
+ end
25
+ end
@@ -1,10 +1,31 @@
1
1
  module Brainzz
2
- class Video
3
- attr_accessor :id
2
+ class Video < BaseModel
3
+ attr_accessor :id, :title, :published_at
4
4
 
5
5
  def initialize(hash = {})
6
- hash ||= {}
7
- @id = hash['videoId']
6
+ @hash = hash || {}
7
+
8
+ @id = transform(hash_id)
9
+ @title = transform(hash_title)
10
+ @published_at = transform_date(hash_published_at)
11
+ end
12
+
13
+ private
14
+
15
+ def snippet
16
+ @hash['snippet'] || {}
17
+ end
18
+
19
+ def hash_id
20
+ @hash['videoId'] || @hash['id']
21
+ end
22
+
23
+ def hash_title
24
+ snippet['title']
25
+ end
26
+
27
+ def hash_published_at
28
+ snippet['publishedAt']
8
29
  end
9
30
  end
10
31
  end
@@ -0,0 +1,13 @@
1
+ module Brainzz
2
+ class VideoDetailsResponse < ::Reverb::Response
3
+ def on_success
4
+ self.data = {}
5
+
6
+ items = body['items'] || []
7
+ items.each do |item|
8
+ video = Video.new(item)
9
+ self.data[video.id] = video
10
+ end
11
+ end
12
+ end
13
+ 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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Herrick
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-09 00:00:00.000000000 Z
12
+ date: 2015-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -59,14 +59,14 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '3'
62
+ version: '4'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '3'
69
+ version: '4'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: cane
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -165,11 +165,19 @@ files:
165
165
  - lib/brainzz.rb
166
166
  - lib/brainzz/commands/base_command.rb
167
167
  - lib/brainzz/commands/playlist_items_command.rb
168
+ - lib/brainzz/commands/video_details_command.rb
168
169
  - lib/brainzz/core.rb
170
+ - lib/brainzz/factories.rb
171
+ - lib/brainzz/factories/playlist_item.rb
172
+ - lib/brainzz/factories/playlist_items_wrapper.rb
173
+ - lib/brainzz/factories/sequences.rb
174
+ - lib/brainzz/factories/video.rb
175
+ - lib/brainzz/models/base_model.rb
169
176
  - lib/brainzz/models/playlist_item.rb
170
177
  - lib/brainzz/models/playlist_items_wrapper.rb
171
178
  - lib/brainzz/models/video.rb
172
179
  - lib/brainzz/responses/playlist_items_response.rb
180
+ - lib/brainzz/responses/video_details_response.rb
173
181
  - license/gplv3.md
174
182
  - license/lgplv3.md
175
183
  - license/lgplv3.png