brainzz 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -11
- data/lib/brainzz/commands/analytics_command.rb +8 -4
- data/lib/brainzz/commands/base_command.rb +2 -2
- data/lib/brainzz/commands/view_count_command.rb +8 -6
- data/lib/brainzz/core.rb +2 -3
- data/lib/brainzz/factories.rb +1 -0
- data/lib/brainzz/factories/view_count.rb +14 -0
- data/lib/brainzz/models/view_count.rb +2 -2
- data/lib/brainzz/params/analytics_params.rb +3 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 013ac84a0ce1b60ef37f43240595e6065da359c1
|
4
|
+
data.tar.gz: 7acdc32bb6818441d647a6cbc18acfa3422d9953
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 740e8f0583e9a2ad8dd6c1bd9e13b3004e005d6ce34e34e6758d007bda82d3c2084044fa39a4096f667f402e7572a8fd34beffd3f3ce0092af242dd981f0059d
|
7
|
+
data.tar.gz: df9271f109dd0d24fcd4a9a1ad9ffc8ee719e5c01154379581b751f76eddf2104122d80b8c71dbd5d4793bc178228dae1daaccf5d63092a86bb6d9521beeec08
|
data/README.md
CHANGED
@@ -22,24 +22,15 @@ Run Specs
|
|
22
22
|
### Regenerating VCR Cassettes
|
23
23
|
|
24
24
|
Check `config/dotenv/test.env` for the required keys.
|
25
|
+
The values in this file are required environment variables
|
26
|
+
when consuming this gem.
|
25
27
|
|
26
28
|
Follow the instructions [here][atv-wiki-google-api-key]
|
27
29
|
to find the required values.
|
28
30
|
|
29
|
-
`REFRESH_TOKEN` is only required for testing purposes.
|
30
|
-
Consumers will not need to set this value,
|
31
|
-
as it will be passed in via parameters to methods that require it.
|
32
|
-
|
33
31
|
Place them in `config/dotenv/integration.env`.
|
34
32
|
|
35
33
|
|
36
|
-
Usage
|
37
|
-
-----
|
38
|
-
|
39
|
-
A `BRAINZZ_GOOGLE_API_KEY` environment variable is expected to be set
|
40
|
-
by any application that consumes this gem.
|
41
|
-
|
42
|
-
|
43
34
|
Interface
|
44
35
|
---------
|
45
36
|
|
@@ -3,9 +3,9 @@ module Brainzz
|
|
3
3
|
class << self
|
4
4
|
private
|
5
5
|
|
6
|
-
def headers
|
6
|
+
def headers
|
7
7
|
super.merge({
|
8
|
-
'Authorization' => "Bearer #{access_token
|
8
|
+
'Authorization' => "Bearer #{access_token}",
|
9
9
|
})
|
10
10
|
end
|
11
11
|
|
@@ -13,8 +13,12 @@ module Brainzz
|
|
13
13
|
'https://www.googleapis.com/youtube/analytics/v1'
|
14
14
|
end
|
15
15
|
|
16
|
-
def access_token
|
17
|
-
AccessTokenService.retrieve_token
|
16
|
+
def access_token
|
17
|
+
AccessTokenService.retrieve_token refresh_token
|
18
|
+
end
|
19
|
+
|
20
|
+
def refresh_token
|
21
|
+
ENV['BRAINZZ_REFRESH_TOKEN']
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
@@ -4,7 +4,7 @@ module Brainzz
|
|
4
4
|
private
|
5
5
|
|
6
6
|
def get(parameters)
|
7
|
-
connection.get endpoint, params(parameters), headers
|
7
|
+
connection.get endpoint, params(parameters), headers
|
8
8
|
end
|
9
9
|
|
10
10
|
def connection
|
@@ -15,7 +15,7 @@ module Brainzz
|
|
15
15
|
{}
|
16
16
|
end
|
17
17
|
|
18
|
-
def headers
|
18
|
+
def headers
|
19
19
|
{
|
20
20
|
'Content-Type' => 'application/json',
|
21
21
|
}
|
@@ -1,13 +1,11 @@
|
|
1
1
|
module Brainzz
|
2
2
|
class ViewCountCommand < AnalyticsCommand
|
3
3
|
class << self
|
4
|
-
def execute(
|
4
|
+
def execute(video_id, start_date, end_date)
|
5
5
|
view_count_params = ViewCountParams.new({
|
6
|
-
:channel_id => channel_id,
|
7
6
|
:video_id => video_id,
|
8
7
|
:start_date => start_date,
|
9
|
-
:end_date => end_date
|
10
|
-
:refresh_token => refresh_token
|
8
|
+
:end_date => end_date
|
11
9
|
})
|
12
10
|
|
13
11
|
if view_count_params.valid?
|
@@ -25,8 +23,8 @@ module Brainzz
|
|
25
23
|
|
26
24
|
def params(view_count_params)
|
27
25
|
super.merge({
|
28
|
-
'ids' => "
|
29
|
-
'
|
26
|
+
'ids' => "contentOwner==#{content_owner}",
|
27
|
+
'filters' => "video==#{view_count_params.video_id}",
|
30
28
|
'metrics' => 'views',
|
31
29
|
'dimensions' => 'day,insightTrafficSourceType',
|
32
30
|
'start-date' => view_count_params.start_date,
|
@@ -34,6 +32,10 @@ module Brainzz
|
|
34
32
|
'sort' => 'day',
|
35
33
|
})
|
36
34
|
end
|
35
|
+
|
36
|
+
def content_owner
|
37
|
+
ENV['BRAINZZ_CONTENT_OWNER']
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
data/lib/brainzz/core.rb
CHANGED
@@ -10,9 +10,8 @@ module Brainzz
|
|
10
10
|
VideoDetailsCommand.execute video_ids
|
11
11
|
end
|
12
12
|
|
13
|
-
def views_for(
|
14
|
-
ViewCountCommand.execute
|
15
|
-
channel_id, video_id, start_date, end_date, refresh_token)
|
13
|
+
def views_for(video_id, start_date, end_date)
|
14
|
+
ViewCountCommand.execute video_id, start_date, end_date
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
data/lib/brainzz/factories.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :brainzz_view_count, :class => Brainzz::ViewCount do
|
3
|
+
views { rand(1_000_000) + 1 }
|
4
|
+
day { DateTime.parse((DateTime.now - rand(100)).strftime('%F')) }
|
5
|
+
source { Brainzz::ViewSourceEnum::SOURCES.values.sample }
|
6
|
+
|
7
|
+
Brainzz::ViewSourceEnum::SOURCES.each do |key, value|
|
8
|
+
factory "brainzz_#{key}_view_count".to_sym,
|
9
|
+
:class => Brainzz::ViewCount do
|
10
|
+
source value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Brainzz
|
2
2
|
class ViewCount < BaseModel
|
3
|
-
|
3
|
+
attr_accessor :views, :day, :source
|
4
4
|
|
5
|
-
def initialize(view_count_row)
|
5
|
+
def initialize(view_count_row = [])
|
6
6
|
@views = normalize_views(view_count_row[2])
|
7
7
|
@day = transform_date(view_count_row[0])
|
8
8
|
@source = source_value(view_count_row[1])
|
@@ -1,19 +1,15 @@
|
|
1
1
|
module Brainzz
|
2
2
|
class AnalyticsParams < BaseParams
|
3
|
-
attr_reader :channel_id
|
4
3
|
attr_reader :start_date
|
5
4
|
attr_reader :end_date
|
6
|
-
attr_reader :refresh_token
|
7
5
|
|
8
6
|
def initialize(params)
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@end_date = normalize_date(params[:end_date])
|
12
|
-
@refresh_token = normalize(params[:refresh_token])
|
7
|
+
@start_date = normalize_date(params[:start_date])
|
8
|
+
@end_date = normalize_date(params[:end_date])
|
13
9
|
end
|
14
10
|
|
15
11
|
def valid?
|
16
|
-
!!(
|
12
|
+
!!(start_date && end_date)
|
17
13
|
end
|
18
14
|
end
|
19
15
|
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.4
|
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-03-
|
12
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/brainzz/factories/playlist_items_wrapper.rb
|
191
191
|
- lib/brainzz/factories/sequences.rb
|
192
192
|
- lib/brainzz/factories/video.rb
|
193
|
+
- lib/brainzz/factories/view_count.rb
|
193
194
|
- lib/brainzz/models/base_model.rb
|
194
195
|
- lib/brainzz/models/playlist_item.rb
|
195
196
|
- lib/brainzz/models/playlist_items_wrapper.rb
|