yt 0.0.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +24 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/.yardopts +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +78 -0
- data/HISTORY.md +37 -0
- data/MIT-LICENSE +20 -0
- data/README.md +325 -0
- data/Rakefile +1 -0
- data/TODO.md +11 -0
- data/bin/yt +31 -0
- data/lib/yt.rb +2 -0
- data/lib/yt/actions/delete.rb +27 -0
- data/lib/yt/actions/delete_all.rb +28 -0
- data/lib/yt/actions/insert.rb +29 -0
- data/lib/yt/actions/list.rb +65 -0
- data/lib/yt/actions/update.rb +25 -0
- data/lib/yt/associations.rb +33 -0
- data/lib/yt/associations/annotations.rb +15 -0
- data/lib/yt/associations/channels.rb +20 -0
- data/lib/yt/associations/details_sets.rb +20 -0
- data/lib/yt/associations/playlist_items.rb +26 -0
- data/lib/yt/associations/playlists.rb +22 -0
- data/lib/yt/associations/ratings.rb +39 -0
- data/lib/yt/associations/snippets.rb +20 -0
- data/lib/yt/associations/statuses.rb +14 -0
- data/lib/yt/associations/subscriptions.rb +38 -0
- data/lib/yt/associations/user_infos.rb +21 -0
- data/lib/yt/associations/videos.rb +14 -0
- data/lib/yt/collections/annotations.rb +43 -0
- data/lib/yt/collections/base.rb +13 -0
- data/lib/yt/collections/channels.rb +32 -0
- data/lib/yt/collections/details_sets.rb +32 -0
- data/lib/yt/collections/playlist_items.rb +50 -0
- data/lib/yt/collections/playlists.rb +56 -0
- data/lib/yt/collections/ratings.rb +32 -0
- data/lib/yt/collections/snippets.rb +38 -0
- data/lib/yt/collections/subscriptions.rb +67 -0
- data/lib/yt/collections/user_infos.rb +41 -0
- data/lib/yt/collections/videos.rb +32 -0
- data/lib/yt/config.rb +55 -0
- data/lib/yt/models/account.rb +68 -0
- data/lib/yt/models/annotation.rb +137 -0
- data/lib/yt/models/base.rb +11 -0
- data/lib/yt/models/channel.rb +17 -0
- data/lib/yt/models/configuration.rb +29 -0
- data/lib/yt/models/description.rb +98 -0
- data/lib/yt/models/details_set.rb +31 -0
- data/lib/yt/models/playlist.rb +65 -0
- data/lib/yt/models/playlist_item.rb +42 -0
- data/lib/yt/models/rating.rb +28 -0
- data/lib/yt/models/snippet.rb +48 -0
- data/lib/yt/models/status.rb +26 -0
- data/lib/yt/models/subscription.rb +35 -0
- data/lib/yt/models/user_info.rb +66 -0
- data/lib/yt/models/video.rb +16 -0
- data/lib/yt/utils/request.rb +85 -0
- data/lib/yt/version.rb +3 -0
- data/spec/associations/device_auth/channels_spec.rb +10 -0
- data/spec/associations/device_auth/details_sets_spec.rb +19 -0
- data/spec/associations/device_auth/playlist_items_spec.rb +42 -0
- data/spec/associations/device_auth/playlists_spec.rb +42 -0
- data/spec/associations/device_auth/ratings_spec.rb +30 -0
- data/spec/associations/device_auth/snippets_spec.rb +30 -0
- data/spec/associations/device_auth/subscriptions_spec.rb +27 -0
- data/spec/associations/device_auth/user_infos_spec.rb +10 -0
- data/spec/associations/device_auth/videos_spec.rb +22 -0
- data/spec/associations/no_auth/annotations_spec.rb +15 -0
- data/spec/associations/server_auth/channels_spec.rb +2 -0
- data/spec/associations/server_auth/details_sets_spec.rb +18 -0
- data/spec/associations/server_auth/playlist_items_spec.rb +17 -0
- data/spec/associations/server_auth/playlists_spec.rb +17 -0
- data/spec/associations/server_auth/ratings_spec.rb +2 -0
- data/spec/associations/server_auth/snippets_spec.rb +28 -0
- data/spec/associations/server_auth/subscriptions_spec.rb +2 -0
- data/spec/associations/server_auth/user_infos_spec.rb +2 -0
- data/spec/associations/server_auth/videos_spec.rb +20 -0
- data/spec/collections/annotations_spec.rb +6 -0
- data/spec/collections/channels_spec.rb +6 -0
- data/spec/collections/details_sets_spec.rb +6 -0
- data/spec/collections/playlist_items_spec.rb +23 -0
- data/spec/collections/playlists_spec.rb +26 -0
- data/spec/collections/ratings_spec.rb +6 -0
- data/spec/collections/snippets_spec.rb +6 -0
- data/spec/collections/subscriptions_spec.rb +30 -0
- data/spec/collections/user_infos_spec.rb +6 -0
- data/spec/collections/videos_spec.rb +6 -0
- data/spec/models/annotation_spec.rb +131 -0
- data/spec/models/channel_spec.rb +13 -0
- data/spec/models/description_spec.rb +94 -0
- data/spec/models/details_set_spec.rb +23 -0
- data/spec/models/playlist_item_spec.rb +32 -0
- data/spec/models/playlist_spec.rb +52 -0
- data/spec/models/rating_spec.rb +13 -0
- data/spec/models/snippet_spec.rb +66 -0
- data/spec/models/status_spec.rb +42 -0
- data/spec/models/subscription_spec.rb +37 -0
- data/spec/models/user_info_spec.rb +69 -0
- data/spec/models/video_spec.rb +13 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/device_app.rb +16 -0
- data/spec/support/server_app.rb +10 -0
- data/yt.gemspec +30 -0
- metadata +209 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 267ed97d1f7857b28aa9577a8e5b06f30beb6d49
|
4
|
+
data.tar.gz: 7ebaddc635450434a4087c1bff77c25b5721c1ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5e4615ed9ec50327686a37c2a4f1c8b4cd1646666e841d0d2e1ebaf0aece040fe2da04793642a010d0293996e2c960cd284711e214a76f1d912b2ac8fdd22a4
|
7
|
+
data.tar.gz: d7694945db65f5cf0a5287473c1a18184cdec831fca1714bba6b286fef841acf766134108fb7cc724ad4170d696d82eaf3fa184d0a802aec50c25cf79774163f
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
/db/*.sqlite3-journal
|
13
|
+
|
14
|
+
coverage/
|
15
|
+
|
16
|
+
# Ignore all logfiles and tempfiles.
|
17
|
+
/log/*.log
|
18
|
+
/tmp
|
19
|
+
**/tmp
|
20
|
+
*.gem
|
21
|
+
*.sqlite3
|
22
|
+
|
23
|
+
doc/
|
24
|
+
.yardoc/
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.0.0
|
4
|
+
notifications:
|
5
|
+
email: false
|
6
|
+
env:
|
7
|
+
global:
|
8
|
+
secure: FC19i/qIjqV7dzd8bZS+yc5HC3XbssU/lBn7+pNsfhsXZp2FpZ4u3v2HPCRZPZ7IsCpsLtUraq6rub290dXecEr1gzSwmaMdfvJz8f2lr1YR58BF9xnTwBUinZOcv9auhWHwCzYRQMHyILUa2NvmVqq0QzYbWVa9X1gwejqyoaQ=
|
9
|
+
matrix:
|
10
|
+
secure: EX0FinqK+va3hTUWNVk7HeFIZqwC0OFlmvW7GX+vJ//vs1Bvsqxqbo1bdqwieMVYxcRwt9cOZU8QapPPc4+v7Awo7ASCgNUo4Y7yrIkjfQdY6b2UyPo6yJw7+Mcyj9gej5hD0mBm+E/KCvvirVfDXfWedPy3Z1FovK1sVW9RqPs=
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--no-private
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yt (0.4.0)
|
5
|
+
activesupport
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (4.1.0)
|
11
|
+
i18n (~> 0.6, >= 0.6.9)
|
12
|
+
json (~> 1.7, >= 1.7.7)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
thread_safe (~> 0.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
coderay (1.1.0)
|
17
|
+
coveralls (0.7.0)
|
18
|
+
multi_json (~> 1.3)
|
19
|
+
rest-client
|
20
|
+
simplecov (>= 0.7)
|
21
|
+
term-ansicolor
|
22
|
+
thor
|
23
|
+
diff-lcs (1.2.5)
|
24
|
+
docile (1.1.3)
|
25
|
+
i18n (0.6.9)
|
26
|
+
json (1.8.1)
|
27
|
+
method_source (0.8.2)
|
28
|
+
mime-types (2.2)
|
29
|
+
minitest (5.3.3)
|
30
|
+
multi_json (1.9.2)
|
31
|
+
pry (0.9.12.6)
|
32
|
+
coderay (~> 1.0)
|
33
|
+
method_source (~> 0.8)
|
34
|
+
slop (~> 3.4)
|
35
|
+
pry-nav (0.2.3)
|
36
|
+
pry (~> 0.9.10)
|
37
|
+
pry-remote (0.1.8)
|
38
|
+
pry (~> 0.9)
|
39
|
+
slop (~> 3.0)
|
40
|
+
rake (10.3.1)
|
41
|
+
rest-client (1.6.7)
|
42
|
+
mime-types (>= 1.16)
|
43
|
+
rspec (2.14.1)
|
44
|
+
rspec-core (~> 2.14.0)
|
45
|
+
rspec-expectations (~> 2.14.0)
|
46
|
+
rspec-mocks (~> 2.14.0)
|
47
|
+
rspec-core (2.14.8)
|
48
|
+
rspec-expectations (2.14.5)
|
49
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
50
|
+
rspec-mocks (2.14.6)
|
51
|
+
simplecov (0.8.2)
|
52
|
+
docile (~> 1.1.0)
|
53
|
+
multi_json
|
54
|
+
simplecov-html (~> 0.8.0)
|
55
|
+
simplecov-html (0.8.0)
|
56
|
+
slop (3.5.0)
|
57
|
+
term-ansicolor (1.3.0)
|
58
|
+
tins (~> 1.0)
|
59
|
+
thor (0.19.1)
|
60
|
+
thread_safe (0.3.3)
|
61
|
+
tins (1.1.0)
|
62
|
+
tzinfo (1.1.0)
|
63
|
+
thread_safe (~> 0.1)
|
64
|
+
yard (0.8.7.4)
|
65
|
+
|
66
|
+
PLATFORMS
|
67
|
+
ruby
|
68
|
+
|
69
|
+
DEPENDENCIES
|
70
|
+
bundler (~> 1.3)
|
71
|
+
coveralls
|
72
|
+
pry
|
73
|
+
pry-nav
|
74
|
+
pry-remote
|
75
|
+
rake
|
76
|
+
rspec
|
77
|
+
yard
|
78
|
+
yt!
|
data/HISTORY.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
v0.4.0 - 2014/05/09
|
2
|
+
--------------------
|
3
|
+
|
4
|
+
* Complete rewrite, using ActiveSupport and separating models and collections
|
5
|
+
* New methods to handle annotations, details sets
|
6
|
+
|
7
|
+
v0.3.0 - 2014/04/16
|
8
|
+
--------------------
|
9
|
+
|
10
|
+
* New and improved methods to handle subscriptions, playlists, playlist items
|
11
|
+
* `find_or_create_playlist_by` does not yield a block anymore
|
12
|
+
* `account.subscribe_to!` raises error in case of duplicate subscription, but `account.subscribe_to` does not
|
13
|
+
|
14
|
+
v0.2.1 - 2014/04/10
|
15
|
+
--------------------
|
16
|
+
|
17
|
+
* `account.subscribe_to!` does not raise error in case of duplicate subscription
|
18
|
+
* Accountable objects can be initialized with the OAuth access token if there's no need to get a fresh one with a refresh token
|
19
|
+
|
20
|
+
v0.2.0 - 2014/04/09
|
21
|
+
--------------------
|
22
|
+
|
23
|
+
* Replaced `account.perform!` with `account.like!`, `account.subscribe_to!`
|
24
|
+
* Added `account.add_to!` to add a video to an account’s playlist
|
25
|
+
* Added `account.find_or_create_playlist_by` to find or create an account’s playlist
|
26
|
+
|
27
|
+
v0.1.1 - 2014/04/09
|
28
|
+
--------------------
|
29
|
+
|
30
|
+
* Added support for Ruby 2.0.0
|
31
|
+
|
32
|
+
v0.1.0 - 2014/04/08
|
33
|
+
--------------------
|
34
|
+
|
35
|
+
* Support for authenticated resources: Youtube accounts and Google accounts
|
36
|
+
* Support for public Youtube resources: channels and videos
|
37
|
+
* Available actions for authenticated Youtube accounts: like a video, subscribe to a channel
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 Fullscreen, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,325 @@
|
|
1
|
+
Yt
|
2
|
+
==
|
3
|
+
|
4
|
+
Yt helps you write apps that need to interact with the YouTube API V3.
|
5
|
+
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/yt.svg)](http://badge.fury.io/rb/yt)
|
7
|
+
[![Dependency Status](https://gemnasium.com/fullscreeninc/yt.png)](https://gemnasium.com/fullscreeninc/yt)
|
8
|
+
[![Build Status](https://travis-ci.org/fullscreeninc/yt.png?branch=master)](https://travis-ci.org/fullscreeninc/yt)
|
9
|
+
[![Coverage Status](https://coveralls.io/repos/fullscreeninc/yt/badge.png)](https://coveralls.io/r/fullscreeninc/yt)
|
10
|
+
[![Code Climate](https://codeclimate.com/github/fullscreeninc/yt.png)](https://codeclimate.com/github/fullscreeninc/yt)
|
11
|
+
|
12
|
+
After [registering your app], you can run commands like:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
channel = Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow'
|
16
|
+
channel.title #=> "Fullscreen"
|
17
|
+
channel.description #=> "The first media company for the connected generation."
|
18
|
+
channel.videos.count #=> 12
|
19
|
+
```
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
video = Yt::Video.new id: 'MESycYJytkU'
|
23
|
+
video.title #=> "Fullscreen Creator Platform"
|
24
|
+
video.duration #=> 86
|
25
|
+
video.annotations.count #=> 1
|
26
|
+
```
|
27
|
+
|
28
|
+
The **full documentation** is available at [rubydoc.info](http://rubydoc.info/github/fullscreeninc/yt/master/frames).
|
29
|
+
|
30
|
+
Available resources
|
31
|
+
===================
|
32
|
+
|
33
|
+
Yt::Account
|
34
|
+
-----------
|
35
|
+
|
36
|
+
Use [Yt::Account](link to doc) to:
|
37
|
+
|
38
|
+
* authenticate as a YouTube account
|
39
|
+
* read attributes of the account
|
40
|
+
* access the YouTube channel of the account
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
account = Yt::Account.new
|
44
|
+
|
45
|
+
# An OAuth2 prompt will appear before the following commands
|
46
|
+
account.email #=> .. your e-mail address..
|
47
|
+
account.channel #=> #<Yt::Channel @id=...>
|
48
|
+
```
|
49
|
+
|
50
|
+
*All the above methods require authentication (see below).*
|
51
|
+
|
52
|
+
Yt::Channel
|
53
|
+
-----------
|
54
|
+
|
55
|
+
Use [Yt::Channel](link to doc) to:
|
56
|
+
|
57
|
+
* read attributes of a channel
|
58
|
+
* access the videos of a channel
|
59
|
+
* access the playlists of a channel
|
60
|
+
* subscribe to and unsubscribe from a channel
|
61
|
+
* create and delete playlists from a channel
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
channel = Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow'
|
65
|
+
channel.title #=> "Fullscreen"
|
66
|
+
channel.description.has_link_to_playlist? #=> false
|
67
|
+
|
68
|
+
channel.videos.count #=> 12
|
69
|
+
channel.videos.first #=> #<Yt::Video @id=...>
|
70
|
+
|
71
|
+
channel.playlists.count #=> 2
|
72
|
+
channel.playlists.first #=> #<Yt::Playlist @id=...>
|
73
|
+
|
74
|
+
# An OAuth2 prompt will appear before the following commands
|
75
|
+
channel.subscribed? #=> false
|
76
|
+
channel.subscribe #=> true
|
77
|
+
|
78
|
+
channel.create_playlist title: 'New playlist' #=> true
|
79
|
+
channel.delete_playlists title: 'New playlist' #=> [true]
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
*Subscribing to and unsubscribing from a channel requires authentication (see below).*
|
84
|
+
|
85
|
+
Yt::Video
|
86
|
+
-----------
|
87
|
+
|
88
|
+
Use [Yt::Video](link to doc) to:
|
89
|
+
|
90
|
+
* read attributes of a video
|
91
|
+
* access the annotations of a video
|
92
|
+
* like and dislike a video
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
video = Yt::Video.new id: 'MESycYJytkU'
|
96
|
+
video.title #=> "Fullscreen Creator Platform"
|
97
|
+
video.duration #=> 63
|
98
|
+
video.description.has_link_to_subscribe? #=> false
|
99
|
+
|
100
|
+
video.annotations.count #=> 1
|
101
|
+
video.annotations.first #=> #<Yt::Annotation @id=...>
|
102
|
+
|
103
|
+
# An OAuth2 prompt will appear before the following commands
|
104
|
+
video.liked? #=> false
|
105
|
+
video.like #=> true
|
106
|
+
```
|
107
|
+
|
108
|
+
*Liking and disliking a video requires authentication (see below).*
|
109
|
+
|
110
|
+
Yt::Playlist
|
111
|
+
------------
|
112
|
+
|
113
|
+
Use [Yt::Playlist](link to doc) to:
|
114
|
+
|
115
|
+
* read attributes of a playlist
|
116
|
+
* access the items of a playlist
|
117
|
+
* add one or multiple videos to a playlist
|
118
|
+
* delete items from a playlist
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
playlist = Yt::Playlist.new id: 'PLSWYkYzOrPMRCK6j0UgryI8E0NHhoVdRc'
|
122
|
+
playlist.title #=> "Fullscreen Features"
|
123
|
+
playlist.public? #=> true
|
124
|
+
|
125
|
+
playlist.playlist_items.count #=> 1
|
126
|
+
playlist.playlist_items.first #=> #<Yt::PlaylistItem @id=...>
|
127
|
+
playlist.playlist_items.first.position #=> 0
|
128
|
+
playlist.playlist_items.first.video.title #=> "Fullscreen Creator Platform"
|
129
|
+
playlist.delete_playlist_items title: 'Fullscreen Creator Platform' #=> [true]
|
130
|
+
|
131
|
+
# An OAuth2 prompt will appear before the following commands
|
132
|
+
playlist.add_video 'MESycYJytkU'
|
133
|
+
playlist.add_videos ['MESycYJytkU', 'MESycYJytkU']
|
134
|
+
```
|
135
|
+
|
136
|
+
*Adding videos requires authentication (see below).*
|
137
|
+
|
138
|
+
|
139
|
+
Yt::Annotation
|
140
|
+
--------------
|
141
|
+
|
142
|
+
Use [Yt::Annotation](link to doc) to:
|
143
|
+
|
144
|
+
* read attributes of an annotation
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
video = Yt::Video.new id: 'MESycYJytkU'
|
148
|
+
annotation = video.annotations.first
|
149
|
+
|
150
|
+
annotation.below? 70 #=> false
|
151
|
+
annotation.has_link_to_subscribe? #=> false
|
152
|
+
annotation.has_link_to_playlist? #=> true
|
153
|
+
```
|
154
|
+
|
155
|
+
*Annotations do not require authentication.*
|
156
|
+
|
157
|
+
Registering your app
|
158
|
+
====================
|
159
|
+
|
160
|
+
In order to use Yt you must register your app in the [Google Developers Console](https://console.developers.google.com).
|
161
|
+
Depending on the nature of your app, you should pick one of the following strategies.
|
162
|
+
|
163
|
+
Apps that do not require user interactions
|
164
|
+
------------------------------------------
|
165
|
+
|
166
|
+
If you are building a read-only app that fetches public data from YouTube, then
|
167
|
+
generate a **Public API access** key in the Google Console, then add the following
|
168
|
+
snippet of code to the initializer of your app:
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
Yt.configure do |config|
|
172
|
+
config.scenario = :server_app
|
173
|
+
config.api_key = '123456789012345678901234567890'
|
174
|
+
end
|
175
|
+
```
|
176
|
+
|
177
|
+
replacing the value above with your own key for server application.
|
178
|
+
|
179
|
+
Remember: this kind of app is not allowed to perform any destructive operation,
|
180
|
+
so you won’t be able to like a video, subscribe to a channel or delete a
|
181
|
+
playlist from a specific account. You will only be able to retrieve read-only
|
182
|
+
data.
|
183
|
+
|
184
|
+
Web apps that do require user interactions
|
185
|
+
------------------------------------------
|
186
|
+
|
187
|
+
If you are building a web app that manages YouTube accounts, you need the
|
188
|
+
owner of each account to authorize your app. There are three scenarios:
|
189
|
+
|
190
|
+
Scenario 1. If you already have the account’s **access token**, then you are ready to go.
|
191
|
+
Just pass that access token to the account initializer, such as:
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
account = Yt::Account.new access_token: 'ya29.1.ABCDEFGHIJ'
|
195
|
+
account.email #=> (retrieves the account’s e-mail address)
|
196
|
+
account.playlists.first.add_video 'MESycYJytkU' #=> (adds a video to an account’s playlist)
|
197
|
+
```
|
198
|
+
|
199
|
+
Scenario 2. If you don’t have the account’s access token, but you have the
|
200
|
+
**refresh token**, then it’s almost as easy.
|
201
|
+
Open the [Google Developers Console](https://console.developers.google.com),
|
202
|
+
find the client ID and client secret of the **web application** that you used to obtain the
|
203
|
+
refresh token, then add the following snippet of code to the initializer of your app:
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
Yt.configure do |config|
|
207
|
+
config.client_id = '1234567890.apps.googleusercontent.com
|
208
|
+
config.client_secret = '1234567890'
|
209
|
+
end
|
210
|
+
```
|
211
|
+
|
212
|
+
replacing the values above with the client ID and secret for web application.
|
213
|
+
Then you can manage a YouTube account by passing the refresh token to the
|
214
|
+
account initializer, such as:
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
account = Yt::Account.new refresh_token: '1/1234567890'
|
218
|
+
account.email #=> (retrieves the account’s e-mail address)
|
219
|
+
account.playlists.first.add_video 'MESycYJytkU' #=> (adds a video to an account’s playlist)
|
220
|
+
```
|
221
|
+
|
222
|
+
Scenario 3. If you don’t have the account’s refresh token, then [..TODO..]
|
223
|
+
|
224
|
+
|
225
|
+
Device apps that do require user interactions
|
226
|
+
---------------------------------------------
|
227
|
+
|
228
|
+
These apps are equivalent to web apps. The only difference is the interface
|
229
|
+
that Google uses to ask people to authenticate.
|
230
|
+
|
231
|
+
|
232
|
+
Scenario 1. If you already have the account’s **access token**, then you are ready to go.
|
233
|
+
Just pass that access token to the account initializer, such as:
|
234
|
+
|
235
|
+
```ruby
|
236
|
+
account = Yt::Account.new access_token: 'ya29.1.ABCDEFGHIJ'
|
237
|
+
account.email #=> (retrieves the account’s e-mail address)
|
238
|
+
account.playlists.first.add_video 'MESycYJytkU' #=> (adds a video to an account’s playlist)
|
239
|
+
```
|
240
|
+
|
241
|
+
Scenario 2. If you don’t have the account’s access token, but you have the
|
242
|
+
**refresh token**, then it’s almost as easy.
|
243
|
+
Open the [Google Developers Console](https://console.developers.google.com),
|
244
|
+
find the client ID and client secret of the **native application** that you used to obtain the
|
245
|
+
refresh token, then add the following snippet of code to the initializer of your app:
|
246
|
+
|
247
|
+
```ruby
|
248
|
+
Yt.configure do |config|
|
249
|
+
config.scenario = :device_app
|
250
|
+
config.client_id = '1234567890.apps.googleusercontent.com
|
251
|
+
config.client_secret = '1234567890'
|
252
|
+
end
|
253
|
+
```
|
254
|
+
|
255
|
+
replacing the values above with the client ID and secret for web application.
|
256
|
+
Then you can manage a YouTube account by passing the refresh token to the
|
257
|
+
account initializer, such as:
|
258
|
+
|
259
|
+
```ruby
|
260
|
+
account = Yt::Account.new refresh_token: '1/1234567890'
|
261
|
+
account.email #=> (retrieves the account’s e-mail address)
|
262
|
+
account.playlists.first.add_video 'MESycYJytkU' #=> (adds a video to an account’s playlist)
|
263
|
+
```
|
264
|
+
|
265
|
+
Scenario 3. If you don’t have the account’s refresh token, then [..TODO..]
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
How to install
|
271
|
+
==============
|
272
|
+
|
273
|
+
To install on your system, run
|
274
|
+
|
275
|
+
gem install yt
|
276
|
+
|
277
|
+
To use inside a bundled Ruby project, add this line to the Gemfile:
|
278
|
+
|
279
|
+
gem 'yt', '~> 0.4.0'
|
280
|
+
|
281
|
+
Since the gem follows [Semantic Versioning](http://semver.org),
|
282
|
+
indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
|
283
|
+
guarantees that your project won’t occur in any error when you `bundle update`
|
284
|
+
and a new version of Yt is released.
|
285
|
+
|
286
|
+
Why you should use Yt…
|
287
|
+
-----------------------
|
288
|
+
|
289
|
+
… and not [youtube_it](https://github.com/kylejginavan/youtube_it)?
|
290
|
+
Because youtube_it does not support Google API V3 and the previous version
|
291
|
+
has already been deprecated by Google and will soon be dropped.
|
292
|
+
|
293
|
+
… and not [Google Api Client](https://github.com/google/google-api-ruby-client)?
|
294
|
+
Because Google Api Client is poorly coded, poorly documented and adds many
|
295
|
+
dependencies, bloating the size of your project.
|
296
|
+
|
297
|
+
… and not your own code? Because Yt is fully tested, well documented,
|
298
|
+
has few dependencies and helps you forget about the burden of dealing with
|
299
|
+
Google API!
|
300
|
+
|
301
|
+
How to test
|
302
|
+
===========
|
303
|
+
|
304
|
+
[ TO DO ]
|
305
|
+
|
306
|
+
|
307
|
+
How to contribute
|
308
|
+
=================
|
309
|
+
|
310
|
+
Before you submit a pull request, make sure all the tests are passing and the
|
311
|
+
code is fully test-covered.
|
312
|
+
|
313
|
+
To release an updated version of the gem to Rubygems, run:
|
314
|
+
|
315
|
+
rake release
|
316
|
+
|
317
|
+
Remember to *bump the version* before running the command, and to document
|
318
|
+
your changes in HISTORY.md and README.md if required.
|
319
|
+
|
320
|
+
The yt gem follows [Semantic Versioning](http://semver.org).
|
321
|
+
Any new release that is fully backward-compatible should bump the *patch* version (0.0.x).
|
322
|
+
Any new version that breaks compatibility should bump the *minor* version (0.x.0)
|
323
|
+
|
324
|
+
Don’t hesitate to send code comments, issues or pull requests through GitHub!
|
325
|
+
All feedback is appreciated. A [googol](http://en.wikipedia.org/wiki/Googol) of thanks! :)
|