yt 0.5.10 → 0.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/HISTORY.md +1 -0
- data/README.md +25 -7
- data/lib/yt/associations/authentications.rb +9 -0
- data/lib/yt/models/authentication.rb +4 -0
- data/lib/yt/models/request.rb +12 -0
- data/lib/yt/version.rb +1 -1
- data/spec/associations/device_auth/authentications_spec.rb +18 -4
- 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: 72f7e8f2bdbc10f6d4ee9e400032c623f9dcaf9c
|
|
4
|
+
data.tar.gz: 3f2eaf3a29cf656f4bf127ad92d4661603effa93
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 66571f1ace7215bc148992f19758a974f1ff46cb832c7c2312e76ed4d2bafa41241fd355e09803b0e520fc8c38e7b4d91d3baab53ba81b421d5130751d0b8aba
|
|
7
|
+
data.tar.gz: 0d5d8ba68f7350f7d9d744d3202e616cb3bc64e322185c729b24de96bce99a6a44c9cc00b7fb843c00da41b400ccb7d505b8aa0511342bebbc63dcca73e44549
|
data/Gemfile.lock
CHANGED
data/HISTORY.md
CHANGED
|
@@ -17,6 +17,7 @@ v0.5 - 2014/05/16
|
|
|
17
17
|
* Retry once YouTube earning queries that return error 400 "Invalid query. Query did not conform to the expectations"
|
|
18
18
|
* Update RSpec to 3.0 (only required in development/testing)
|
|
19
19
|
* New ContentOwner subclass of Account with access to partnered channels
|
|
20
|
+
* Automatically refresh the access token when it expires or becomes invalid
|
|
20
21
|
|
|
21
22
|
v0.4 - 2014/05/09
|
|
22
23
|
--------------------
|
data/README.md
CHANGED
|
@@ -34,7 +34,7 @@ Available resources
|
|
|
34
34
|
Yt::Account
|
|
35
35
|
-----------
|
|
36
36
|
|
|
37
|
-
Use [Yt::Account](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Account) to:
|
|
37
|
+
Use [Yt::Account](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/Account) to:
|
|
38
38
|
|
|
39
39
|
* authenticate as a YouTube account
|
|
40
40
|
* read attributes of the account
|
|
@@ -50,10 +50,28 @@ account.channel #=> #<Yt::Channel @id=...>
|
|
|
50
50
|
|
|
51
51
|
*All the above methods require authentication (see below).*
|
|
52
52
|
|
|
53
|
+
Yt::ContentOwner
|
|
54
|
+
----------------
|
|
55
|
+
|
|
56
|
+
Use [Yt::ContentOwner](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/ContentOwner) to:
|
|
57
|
+
|
|
58
|
+
* authenticate as a YouTube content owner
|
|
59
|
+
* list the channels partnered with a YouTube content owner
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
# A content owner is an account, therefore can be initialized with access token, refresh token or an authorization code
|
|
63
|
+
content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
|
|
64
|
+
|
|
65
|
+
content_owner.partnered_channels.count #=> 12
|
|
66
|
+
content_owner.partnered_channels.first #=> #<Yt::Channel @id=...>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
*All the above methods require authentication (see below).*
|
|
70
|
+
|
|
53
71
|
Yt::Channel
|
|
54
72
|
-----------
|
|
55
73
|
|
|
56
|
-
Use [Yt::Channel](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Channel) to:
|
|
74
|
+
Use [Yt::Channel](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/Channel) to:
|
|
57
75
|
|
|
58
76
|
* read attributes of a channel
|
|
59
77
|
* access the videos of a channel
|
|
@@ -91,7 +109,7 @@ channel.delete_playlists title: 'New playlist' #=> [true]
|
|
|
91
109
|
*The methods above require to be authenticated as a YouTube account (see below).*
|
|
92
110
|
|
|
93
111
|
```ruby
|
|
94
|
-
content_owner = Yt::
|
|
112
|
+
content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
|
|
95
113
|
channel = Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow', auth: content_owner
|
|
96
114
|
|
|
97
115
|
channel.earning 5.days.ago #=> 12.23
|
|
@@ -104,7 +122,7 @@ channel.earnings since: 3.days.ago, until: 2.days.ago #=> {Wed, 28 May 2014 => 1
|
|
|
104
122
|
Yt::Video
|
|
105
123
|
-----------
|
|
106
124
|
|
|
107
|
-
Use [Yt::Video](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Video) to:
|
|
125
|
+
Use [Yt::Video](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/Video) to:
|
|
108
126
|
|
|
109
127
|
* read attributes of a video
|
|
110
128
|
* access the annotations of a video
|
|
@@ -135,7 +153,7 @@ video.like #=> true
|
|
|
135
153
|
Yt::Playlist
|
|
136
154
|
------------
|
|
137
155
|
|
|
138
|
-
Use [Yt::Playlist](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Playlist) to:
|
|
156
|
+
Use [Yt::Playlist](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/Playlist) to:
|
|
139
157
|
|
|
140
158
|
* read attributes of a playlist
|
|
141
159
|
* access the items of a playlist
|
|
@@ -167,7 +185,7 @@ playlist.delete_playlist_items title: 'Fullscreen Creator Platform' #=> [true]
|
|
|
167
185
|
Yt::Annotation
|
|
168
186
|
--------------
|
|
169
187
|
|
|
170
|
-
Use [Yt::Annotation](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Annotation) to:
|
|
188
|
+
Use [Yt::Annotation](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/Annotation) to:
|
|
171
189
|
|
|
172
190
|
* read attributes of an annotation
|
|
173
191
|
|
|
@@ -347,7 +365,7 @@ To install on your system, run
|
|
|
347
365
|
|
|
348
366
|
To use inside a bundled Ruby project, add this line to the Gemfile:
|
|
349
367
|
|
|
350
|
-
gem 'yt', '~> 0.5.
|
|
368
|
+
gem 'yt', '~> 0.5.11'
|
|
351
369
|
|
|
352
370
|
Since the gem follows [Semantic Versioning](http://semver.org),
|
|
353
371
|
indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
|
|
@@ -21,6 +21,15 @@ module Yt
|
|
|
21
21
|
URI::HTTPS.build(host: host, path: path, query: query).to_s
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
# Obtains a new access token.
|
|
25
|
+
# Returns true if the new access token is different from the previous one
|
|
26
|
+
def refresh
|
|
27
|
+
old_access_token = authentication.access_token
|
|
28
|
+
authentication.expire
|
|
29
|
+
new_access_token = authentication.access_token
|
|
30
|
+
old_access_token != new_access_token
|
|
31
|
+
end
|
|
32
|
+
|
|
24
33
|
private
|
|
25
34
|
|
|
26
35
|
def current_authentication
|
data/lib/yt/models/request.rb
CHANGED
|
@@ -28,6 +28,8 @@ module Yt
|
|
|
28
28
|
def run
|
|
29
29
|
if response.is_a? @expected_response
|
|
30
30
|
response.tap{|response| response.body = parse_format response.body}
|
|
31
|
+
elsif run_again_with_refreshed_authentication?
|
|
32
|
+
run
|
|
31
33
|
else
|
|
32
34
|
raise error_for(response), request_error_message
|
|
33
35
|
end
|
|
@@ -35,6 +37,16 @@ module Yt
|
|
|
35
37
|
|
|
36
38
|
private
|
|
37
39
|
|
|
40
|
+
# If a request authorized with an access token returns 401, then the
|
|
41
|
+
# access token might have expired. If a refresh token is also present,
|
|
42
|
+
# try to run the request one more time with a refreshed access token.
|
|
43
|
+
def run_again_with_refreshed_authentication?
|
|
44
|
+
if response.is_a? Net::HTTPUnauthorized
|
|
45
|
+
@response = @http_request = @uri = nil
|
|
46
|
+
@auth.refresh
|
|
47
|
+
end if @auth.respond_to? :refresh
|
|
48
|
+
end
|
|
49
|
+
|
|
38
50
|
def response
|
|
39
51
|
@response ||= Net::HTTP.start(*net_http_options) do |http|
|
|
40
52
|
http.request http_request
|
data/lib/yt/version.rb
CHANGED
|
@@ -50,17 +50,31 @@ describe Yt::Associations::Authentications, :device_app do
|
|
|
50
50
|
|
|
51
51
|
context 'that has expired' do
|
|
52
52
|
let(:expires_at) { 1.day.ago.to_s }
|
|
53
|
-
|
|
53
|
+
|
|
54
|
+
context 'and no valid refresh token' do
|
|
55
|
+
it { expect{account.authentication}.to raise_error Yt::Errors::Unauthorized }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context 'and a valid refresh token' do
|
|
59
|
+
before { attrs[:refresh_token] = ENV['YT_TEST_DEVICE_REFRESH_TOKEN'] }
|
|
60
|
+
it { expect(account.authentication).to be_a Yt::Authentication }
|
|
61
|
+
end
|
|
54
62
|
end
|
|
55
63
|
end
|
|
56
64
|
|
|
57
65
|
context 'that is invalid' do
|
|
58
66
|
let(:access_token) { '--not-a-valid-access-token--' }
|
|
59
67
|
let(:expires_at) { 1.day.from_now }
|
|
60
|
-
it { expect(account.authentication).to be_a Yt::Authentication }
|
|
61
|
-
it { expect{account.channel}.to raise_error Yt::Errors::Unauthorized }
|
|
62
|
-
end
|
|
63
68
|
|
|
69
|
+
context 'and no valid refresh token' do
|
|
70
|
+
it { expect{account.channel}.to raise_error Yt::Errors::Unauthorized }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
context 'and a valid refresh token' do
|
|
74
|
+
before { attrs[:refresh_token] = ENV['YT_TEST_DEVICE_REFRESH_TOKEN'] }
|
|
75
|
+
it { expect{account.channel}.not_to raise_error }
|
|
76
|
+
end
|
|
77
|
+
end
|
|
64
78
|
end
|
|
65
79
|
|
|
66
80
|
context 'given no token or code' do
|