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 +4 -4
- data/lib/brainzz.rb +4 -0
- data/lib/brainzz/commands/video_details_command.rb +21 -0
- data/lib/brainzz/core.rb +4 -0
- data/lib/brainzz/factories.rb +4 -0
- data/lib/brainzz/factories/playlist_item.rb +6 -0
- data/lib/brainzz/factories/playlist_items_wrapper.rb +7 -0
- data/lib/brainzz/factories/sequences.rb +12 -0
- data/lib/brainzz/factories/video.rb +10 -0
- data/lib/brainzz/models/base_model.rb +25 -0
- data/lib/brainzz/models/video.rb +25 -4
- data/lib/brainzz/responses/video_details_response.rb +13 -0
- metadata +12 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5593938f8cecb4660e3c474a61dcbf908a74f0a2
|
4
|
+
data.tar.gz: 2db3a9a659c9241a7501870fb212a57f73accfa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
@@ -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
|
data/lib/brainzz/models/video.rb
CHANGED
@@ -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
|
-
|
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
|
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.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-
|
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: '
|
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: '
|
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
|