yt 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/Gemfile.lock +7 -7
- data/HISTORY.md +1 -0
- data/README.md +10 -4
- data/lib/yt/collections/authentications.rb +1 -1
- data/lib/yt/collections/reports.rb +10 -8
- data/lib/yt/models/account.rb +4 -0
- data/lib/yt/models/channel.rb +15 -0
- data/lib/yt/models/content_owner.rb +0 -3
- data/lib/yt/version.rb +1 -1
- data/spec/requests/as_account/channel_spec.rb +20 -0
- data/spec/requests/as_content_owner/channel_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d346ffef89d5b5f77243722480b4182d31d23a7f
|
4
|
+
data.tar.gz: 1148ab3e8561f75edba5cf62dad118d0e4fe255d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ab946dc91a6d0089042d33ada2939b0a8c6a2a8221360e3f9cd122c197cdf40835715d3b284b869c344de7af8260eaa305a83b76fddcff8fd29372dee876536
|
7
|
+
data.tar.gz: 1c9cbb659eddc7993dbd3f5c9e8206d2bed99639bfb189bf013565d7b9884773711e45f379f2ac491e3e92e4282a0b2b8b05d1692a6c8d4315d1997e433fcabb
|
data/.travis.yml
CHANGED
@@ -6,11 +6,11 @@ matrix:
|
|
6
6
|
- rvm: 1.9.3
|
7
7
|
gemfile: gemfiles/Gemfile.activesupport-3.x
|
8
8
|
env:
|
9
|
-
- secure:
|
9
|
+
- secure: OsmWyhhYNILEb1lhqxPX+iEfbWzC3dELuxQ7JGP9iN/FhqBtlV51cu+u2cBBdql6Gzuqi4VlMEeJSX0PQUmzOsMb0vHhOJDyp4a32NE+xry8LOT8XdCwni20ZBcUeFxC5hMUVebPuhqBTFjBWbXQKwKSXIdPnNWz31d9kyGIsxk=
|
10
10
|
- rvm: 2.0.0
|
11
11
|
gemfile: gemfiles/Gemfile.activesupport-4.x
|
12
12
|
env:
|
13
|
-
- secure:
|
13
|
+
- secure: FrmFA2BE0FYyuKsf0FEO0EAXY+h048HbD1p3lu5XPo9/lxpAl7wM5m12HsnJQuNY6UlUmZ5bp9f8upCBZpz7cLZK5e/FWLWSvkv3Fts+NVsbAcVtFgvBKOCgTznZi/qgUtqbWBevkM3gyXyylzdB+c4wWjoOO/xSDVR227m8nMA=
|
14
14
|
env:
|
15
15
|
global:
|
16
16
|
- secure: ApPj5c9h6xk+AbHHf4KXL10QnleYCWwcp2+qMFolrS6RWR5vhrnKq1UBo0h59HuvXeOQIgZ/GmocuSEZovS9c1hQP3n0PHSNEnGUNJyn6CS3BiPQSWmC3p2pONo1Xv+hVWfzDoEv80b82GX5P5x/l1BSqhpxLA9geITJprWsoLg=
|
@@ -22,4 +22,4 @@ env:
|
|
22
22
|
- secure: Ejj8tsuwyrRVmCc/R9ubKWCHWhCGpe0Dy6fc1UuPCkcMZyXq9ZC02v2obWsTQQ7epEgsCYZAO4v/gWpuv1b1huGcWdfJzMW7RCoY87cEf9HnAK0lSwGx4+/pYkEMe8y5p149C3vAR8nqczvEavN1fUq/WwPUqp+JyDP7kwFTs2Y=
|
23
23
|
- secure: gE5kAT1R54hmS+W3YYGcUtlD8ZskvTctVR3sr+C5CUjVPdq6Ktx5Q/a6EJyAVVrhxpaCOuk3LG+VkzdQIVFUNRiDPcOulkond4HkSQDoy+IJ/wTXvUS+lIJ1ERUnWega+APrQUjH5s2WayPGZUBqWt/u8Tt9EmSUZfuKZSEXqZk=
|
24
24
|
- secure: ZUx5v/wHW/TENg8NfFINiiMoe2D031ntDTiuIBdf88c/bMClkEtRRgomtK9RBkFonEyGEOkXxUm2SLzRf340V3eIXWQhil7ab1lcYs8X59aVS/NK/GqChH8Nia17gc3OTQ9k6rYvj4Lp60Dh9WG1cijLPd4/OvPmf6qX9uYfJMw=
|
25
|
-
- secure: DumQVO01Y3Ki1skuOYOZzosDb6jS0XyG1O8Agy3mVxXGJzQE+s1z2UFz4gMpsU9o/gmiNMddp7I6+RtbZjo9hN3H7vlRRwEeB7tuUMiDyomSx1FlHcCFfPdTmhxGg8X78SErMWqNC6eReGrCTgBdIq1ho7dIu53qJNxTEFqx7eI=
|
25
|
+
- secure: DumQVO01Y3Ki1skuOYOZzosDb6jS0XyG1O8Agy3mVxXGJzQE+s1z2UFz4gMpsU9o/gmiNMddp7I6+RtbZjo9hN3H7vlRRwEeB7tuUMiDyomSx1FlHcCFfPdTmhxGg8X78SErMWqNC6eReGrCTgBdIq1ho7dIu53qJNxTEFqx7eI=
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
yt (0.7.
|
4
|
+
yt (0.7.5)
|
5
5
|
activesupport
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (4.1.
|
10
|
+
activesupport (4.1.2)
|
11
11
|
i18n (~> 0.6, >= 0.6.9)
|
12
12
|
json (~> 1.7, >= 1.7.7)
|
13
13
|
minitest (~> 5.1)
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
term-ansicolor
|
21
21
|
thor
|
22
22
|
diff-lcs (1.2.5)
|
23
|
-
docile (1.1.
|
23
|
+
docile (1.1.5)
|
24
24
|
i18n (0.6.9)
|
25
25
|
json (1.8.1)
|
26
26
|
mime-types (2.3)
|
@@ -33,14 +33,14 @@ GEM
|
|
33
33
|
rspec-core (~> 3.0.0)
|
34
34
|
rspec-expectations (~> 3.0.0)
|
35
35
|
rspec-mocks (~> 3.0.0)
|
36
|
-
rspec-core (3.0.
|
36
|
+
rspec-core (3.0.2)
|
37
37
|
rspec-support (~> 3.0.0)
|
38
|
-
rspec-expectations (3.0.
|
38
|
+
rspec-expectations (3.0.2)
|
39
39
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
40
|
rspec-support (~> 3.0.0)
|
41
|
-
rspec-mocks (3.0.
|
41
|
+
rspec-mocks (3.0.2)
|
42
42
|
rspec-support (~> 3.0.0)
|
43
|
-
rspec-support (3.0.
|
43
|
+
rspec-support (3.0.2)
|
44
44
|
simplecov (0.8.2)
|
45
45
|
docile (~> 1.1.0)
|
46
46
|
multi_json
|
data/HISTORY.md
CHANGED
@@ -12,6 +12,7 @@ v0.7 - 2014/06/18
|
|
12
12
|
* Sort channel.videos by most recent first
|
13
13
|
* Extract Reports (earnings, views) into module with macro `has_report`
|
14
14
|
* New channel reports: comments, likes, dislikes, shares and impressions
|
15
|
+
* Allow both normal and partnered channels to retrieve reports about views, comments, likes, dislikes, shares
|
15
16
|
|
16
17
|
v0.6 - 2014/06/05
|
17
18
|
-----------------
|
data/README.md
CHANGED
@@ -122,6 +122,12 @@ channel.subscribe #=> true
|
|
122
122
|
|
123
123
|
channel.create_playlist title: 'New playlist' #=> true
|
124
124
|
channel.delete_playlists title: 'New playlist' #=> [true]
|
125
|
+
|
126
|
+
channel.views since: 7.days.ago #=> {Wed, 28 May 2014 => 12.0, Thu, 29 May 2014 => 3.0, …}
|
127
|
+
channel.comments until: 2.days.ago #=> {Wed, 28 May 2014 => 9.0, Thu, 29 May 2014 => 4.0, …}
|
128
|
+
channel.likes from: 8.days.ago #=> {Tue, 27 May 2014 => 7.0, Wed, 28 May 2014 => 0.0, …}
|
129
|
+
channel.dislikes to: 2.days.ago #=> {Tue, 27 May 2014 => 0.0, Wed, 28 May 2014 => 1.0, …}
|
130
|
+
channel.shares since: 7.days.ago, until: 7.days.ago #=> {Wed, 28 May 2014 => 3.0}
|
125
131
|
```
|
126
132
|
|
127
133
|
*The methods above require to be authenticated as a YouTube account (see below).*
|
@@ -133,8 +139,8 @@ channel = Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow', auth: content_owner
|
|
133
139
|
channel.earnings_on 5.days.ago #=> 12.23
|
134
140
|
channel.views since: 7.days.ago #=> {Wed, 28 May 2014 => 12.0, Thu, 29 May 2014 => 3.0, …}
|
135
141
|
channel.comments until: 2.days.ago #=> {Wed, 28 May 2014 => 9.0, Thu, 29 May 2014 => 4.0, …}
|
136
|
-
channel.
|
137
|
-
channel.
|
142
|
+
channel.likes from: 8.days.ago #=> {Tue, 27 May 2014 => 7.0, Wed, 28 May 2014 => 0.0, …}
|
143
|
+
channel.dislikes to: 2.days.ago #=> {Tue, 27 May 2014 => 0.0, Wed, 28 May 2014 => 1.0, …}
|
138
144
|
channel.shares since: 7.days.ago, until: 7.days.ago #=> {Wed, 28 May 2014 => 3.0}
|
139
145
|
channel.impressions_on 5.days.ago #=> 157.0
|
140
146
|
```
|
@@ -394,7 +400,7 @@ with an extra `code` parameter that looks something like `4/Ja60jJ7_Kw0`.
|
|
394
400
|
Just pass the code to the following method to authenticate and initialize the account:
|
395
401
|
|
396
402
|
```ruby
|
397
|
-
account = Yt::Account.new authorization_code: '4/Ja60jJ7_Kw0'
|
403
|
+
account = Yt::Account.new authorization_code: '4/Ja60jJ7_Kw0', redirect_uri: redirect_uri
|
398
404
|
account.email #=> (retrieves the account’s e-mail address)
|
399
405
|
account.videos #=> (lists a video to an account’s playlist)
|
400
406
|
```
|
@@ -433,7 +439,7 @@ To install on your system, run
|
|
433
439
|
|
434
440
|
To use inside a bundled Ruby project, add this line to the Gemfile:
|
435
441
|
|
436
|
-
gem 'yt', '~> 0.7.
|
442
|
+
gem 'yt', '~> 0.7.5'
|
437
443
|
|
438
444
|
Since the gem follows [Semantic Versioning](http://semver.org),
|
439
445
|
indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
|
@@ -20,14 +20,16 @@ module Yt
|
|
20
20
|
def list_params
|
21
21
|
super.tap do |params|
|
22
22
|
params[:path] = '/youtube/analytics/v1/reports'
|
23
|
-
params[:params] =
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
23
|
+
params[:params] = @parent.reports_params.merge reports_params
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def reports_params
|
28
|
+
{}.tap do |params|
|
29
|
+
params['start-date'] = @days_range.begin
|
30
|
+
params['end-date'] = @days_range.end
|
31
|
+
params['metrics'] = @metric
|
32
|
+
params['dimensions'] = :day
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
data/lib/yt/models/account.rb
CHANGED
@@ -24,6 +24,10 @@ module Yt
|
|
24
24
|
# @return [Yt::Collections::Videos] the videos owned by the account.
|
25
25
|
has_many :videos
|
26
26
|
|
27
|
+
# @return [String] name of the CMS account, if the account is partnered.
|
28
|
+
# @return [nil] if the account is not a partnered content owner.
|
29
|
+
attr_reader :owner_name
|
30
|
+
|
27
31
|
# @private
|
28
32
|
# Tells `has_many :videos` that account.videos should return all the
|
29
33
|
# videos *owned by* the account (public, private, unlisted).
|
data/lib/yt/models/channel.rb
CHANGED
@@ -121,6 +121,21 @@ module Yt
|
|
121
121
|
def videos_params
|
122
122
|
{channelId: id}
|
123
123
|
end
|
124
|
+
|
125
|
+
# @private
|
126
|
+
# Tells `has_reports` to retrieve the reports from YouTube Analytics API
|
127
|
+
# either as a Channel or as a Content Owner.
|
128
|
+
# @see https://developers.google.com/youtube/analytics/v1/reports
|
129
|
+
def reports_params
|
130
|
+
{}.tap do |params|
|
131
|
+
if auth.owner_name
|
132
|
+
params['ids'] = "contentOwner==#{auth.owner_name}"
|
133
|
+
params['filters'] = "channel==#{id}"
|
134
|
+
else
|
135
|
+
params['ids'] = "channel==#{id}"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
124
139
|
end
|
125
140
|
end
|
126
141
|
end
|
@@ -11,9 +11,6 @@ module Yt
|
|
11
11
|
# @return [Yt::Collection::PartneredChannels] the channels managed by the CMS account.
|
12
12
|
has_many :partnered_channels
|
13
13
|
|
14
|
-
# @return [String] the name of the CMS account.
|
15
|
-
attr_reader :owner_name
|
16
|
-
|
17
14
|
def initialize(options = {})
|
18
15
|
super options
|
19
16
|
@owner_name = options[:owner_name]
|
data/lib/yt/version.rb
CHANGED
@@ -70,6 +70,26 @@ describe Yt::Channel, :device_app do
|
|
70
70
|
# rather than a more logical 4xx error. Hopefully this will get fixed
|
71
71
|
# and this code (and test) removed.
|
72
72
|
it { expect{channel.subscribe}.to raise_error Yt::Errors::ServerError }
|
73
|
+
|
74
|
+
it 'returns valid reports for channel-related metrics' do
|
75
|
+
# Some reports are only available to Content Owners.
|
76
|
+
# See content ownere test for more details about what the methods return.
|
77
|
+
expect{channel.views}.not_to raise_error
|
78
|
+
expect{channel.comments}.not_to raise_error
|
79
|
+
expect{channel.likes}.not_to raise_error
|
80
|
+
expect{channel.dislikes}.not_to raise_error
|
81
|
+
expect{channel.shares}.not_to raise_error
|
82
|
+
expect{channel.earnings}.to raise_error Yt::Errors::Unauthorized
|
83
|
+
expect{channel.impressions}.to raise_error Yt::Errors::Unauthorized
|
84
|
+
|
85
|
+
expect{channel.views_on 3.days.ago}.not_to raise_error
|
86
|
+
expect{channel.comments_on 3.days.ago}.not_to raise_error
|
87
|
+
expect{channel.likes_on 3.days.ago}.not_to raise_error
|
88
|
+
expect{channel.dislikes_on 3.days.ago}.not_to raise_error
|
89
|
+
expect{channel.shares_on 3.days.ago}.not_to raise_error
|
90
|
+
expect{channel.earnings_on 3.days.ago}.to raise_error Yt::Errors::Unauthorized
|
91
|
+
expect{channel.impressions_on 3.days.ago}.to raise_error Yt::Errors::Unauthorized
|
92
|
+
end
|
73
93
|
end
|
74
94
|
|
75
95
|
context 'given an unknown channel' do
|
@@ -182,6 +182,18 @@ describe Yt::Channel, :partner do
|
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
185
|
+
describe 'shares can be retrieved for a specific day' do
|
186
|
+
context 'in which the channel was partnered' do
|
187
|
+
let(:shares) { channel.shares_on 5.days.ago}
|
188
|
+
it { expect(shares).to be_a Float }
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'in which the channel was not partnered' do
|
192
|
+
let(:shares) { channel.shares_on 20.years.ago}
|
193
|
+
it { expect(shares).to be_nil }
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
185
197
|
describe 'shares can be retrieved for a range of days' do
|
186
198
|
let(:date) { 4.days.ago }
|
187
199
|
|