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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b0778b1b4125407b03db2409943f825a0175ed0
4
- data.tar.gz: a380360a2548603619f847f20cad660367ba70e7
3
+ metadata.gz: 013ac84a0ce1b60ef37f43240595e6065da359c1
4
+ data.tar.gz: 7acdc32bb6818441d647a6cbc18acfa3422d9953
5
5
  SHA512:
6
- metadata.gz: 65e2ecf248cbaf6c936f4e26f3fc71a6e6948776dbf4abcfa747489c46a530a776b0f570ab64fe520f4b89edf122159aee295460f3db14e1786f2a612aac8af6
7
- data.tar.gz: be9d7f05e156220dfa77132b0c688c0daecef19fda6f4abf2298db63f14bed1023ee5fa89f76b34439a23b2a42c00a8c5e1a8ab78182291f56dc60fe01e18b4a
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(parameters)
6
+ def headers
7
7
  super.merge({
8
- 'Authorization' => "Bearer #{access_token(parameters)}",
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(parameters)
17
- AccessTokenService.retrieve_token parameters.refresh_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(parameters)
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(parameters = nil)
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(channel_id, video_id, start_date, end_date, refresh_token)
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' => "channel==#{view_count_params.channel_id}",
29
- 'filter' => "video==#{view_count_params.video_id}",
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
@@ -10,9 +10,8 @@ module Brainzz
10
10
  VideoDetailsCommand.execute video_ids
11
11
  end
12
12
 
13
- def views_for(channel_id, video_id, start_date, end_date, refresh_token)
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
@@ -2,3 +2,4 @@ require_relative 'factories/sequences'
2
2
  require_relative 'factories/video'
3
3
  require_relative 'factories/playlist_item'
4
4
  require_relative 'factories/playlist_items_wrapper'
5
+ require_relative 'factories/view_count'
@@ -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
- attr_reader :views, :day, :source
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
- @channel_id = normalize(params[:channel_id])
10
- @start_date = normalize_date(params[:start_date])
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
- !!(channel_id && start_date && end_date && refresh_token)
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.3
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-23 00:00:00.000000000 Z
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