googol 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -23
- data/lib/googol/authenticable.rb +6 -0
- data/lib/googol/requestable.rb +1 -0
- data/lib/googol/version.rb +1 -1
- data/lib/googol/youtube_account.rb +2 -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: 020552842d5bed2faefa55f19aa03c79256f63e5
|
4
|
+
data.tar.gz: 2e6b5289e68ee0a3d3549f6c8befec0130f1821d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dad077e59925dd1265286f7c0abcf6524b5c6830720c92657d11ee59e0c5b33898236af2a84d56cbfad9f2111154984343d8b3b6b1b1712f485546d0983af32
|
7
|
+
data.tar.gz: 863c175bd7987a5dc24067556bf3c1a3238ca64c81cbf3ed6cd06e87478a1ff8ea04e07c9b0659ffcff7afac6dfb7ab648d3414d6dba81083f95a2c1f8df6214
|
data/README.md
CHANGED
@@ -11,10 +11,10 @@ Googol lets you interact with many resources provided by Google API V3.
|
|
11
11
|
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
channel = Googol::YoutubeResource.new url: 'youtube.com/
|
15
|
-
channel.id #=> '
|
16
|
-
channel.title #=> "
|
17
|
-
channel.description #=> "
|
14
|
+
channel = Googol::YoutubeResource.new url: 'youtube.com/fullscreen'
|
15
|
+
channel.id #=> 'UCxO1tY8h1AhOz0T4ENwmpow'
|
16
|
+
channel.title #=> "Fullscreen"
|
17
|
+
channel.description #=> "The first media company for the connected generation."
|
18
18
|
```
|
19
19
|
|
20
20
|
```ruby
|
@@ -31,27 +31,16 @@ account.email #=> 'user@google.com'
|
|
31
31
|
|
32
32
|
```ruby
|
33
33
|
account = Googol::YoutubeAccount.new auth_params
|
34
|
-
account.like! video_id: 'Kd5M17e7Wek' # => adds 'Tongue' to your 'Liked videos'
|
35
|
-
account.subscribe_to! channel_id: 'UC7eaRqtonpyiYw0Pns0Au_g' # => subscribes to R.E.M.’s channel
|
36
|
-
playlist_id = account.find_or_create_playlist_by title: 'Favorite Music Videos'
|
37
|
-
account.add_to! playlist_id: playlist_id, video_id: 'Kd5M17e7Wek' # => adds 'Tongue' to your 'Favorite Music Videos' playlist
|
38
34
|
|
39
|
-
#
|
40
|
-
|
41
|
-
# @param [Hash] target The target of the 'add_to' activity
|
42
|
-
# @option target [String] :video_id The ID of the video to add
|
43
|
-
# @option target [String] :playlist_id The ID of the playlist to add to
|
44
|
-
#
|
45
|
-
# @see https://developers.google.com/youtube/v3/docs/playlistItems/insert
|
46
|
-
#
|
47
|
-
def add_to!(target = {})
|
48
|
-
video_id, playlist_id = fetch! target, :video_id, :playlist_id
|
49
|
-
resource = {videoId: video_id, kind: 'youtube#video'}
|
50
|
-
youtube_request! path: '/playlistItems?part=snippet', json: true,
|
51
|
-
method: :post, snippet: {playlistId: playlist_id, resourceId: resource}
|
52
|
-
end
|
35
|
+
# like the video 'Tongue' by R.E.M.
|
36
|
+
account.like! video_id: 'Kd5M17e7Wek'
|
53
37
|
|
38
|
+
# subscribes to Fullscreen’s channel
|
39
|
+
account.subscribe_to! channel_id: 'UCxO1tY8h1AhOz0T4ENwmpow' # => subscribes to Fullscreen’s channel
|
54
40
|
|
41
|
+
# add the video 'Tongue' to your 'Favorite Music Videos' playlist
|
42
|
+
playlist_id = account.find_or_create_playlist_by title: 'Favorite Music Videos'
|
43
|
+
account.add_to! playlist_id: playlist_id, video_id: 'Kd5M17e7Wek' # => adds 'Tongue' to your 'Favorite Music Videos' playlist
|
55
44
|
```
|
56
45
|
|
57
46
|
The full documentation is available at [rubydoc.info](http://rubydoc.info/github/fullscreeninc/googol/master/frames).
|
@@ -156,7 +145,7 @@ To install on your system, run
|
|
156
145
|
|
157
146
|
To use inside a bundled Ruby project, add this line to the Gemfile:
|
158
147
|
|
159
|
-
gem 'googol', '~> 0.2.
|
148
|
+
gem 'googol', '~> 0.2.1'
|
160
149
|
|
161
150
|
Since the gem follows [Semantic Versioning](http://semver.org),
|
162
151
|
indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
|
data/lib/googol/authenticable.rb
CHANGED
@@ -16,10 +16,16 @@ module Googol
|
|
16
16
|
# @param [Hash] attrs Authentication credentials to access the account
|
17
17
|
# @option attrs [String] :code The OAuth2 authorization code
|
18
18
|
# @option attrs [String] :redirect_url The page to redirect after the OAuth2 page
|
19
|
+
# @option attrs [String] :access_token The authorization token for immediate access
|
19
20
|
# @option attrs [String] :refresh_token The refresh token for offline access
|
21
|
+
#
|
22
|
+
# @note The refresh token never expires but the access token expires after 1 hour.
|
23
|
+
# If the access token has expired, initialize the object again with the
|
24
|
+
# refresh token.
|
20
25
|
def initialize(attrs = {})
|
21
26
|
@code = attrs[:code]
|
22
27
|
@refresh_token = attrs[:refresh_token]
|
28
|
+
@credentials = {access_token: attrs[:access_token]} if attrs[:access_token]
|
23
29
|
@redirect_url = attrs.fetch :redirect_url, 'http://example.com/'
|
24
30
|
end
|
25
31
|
|
data/lib/googol/requestable.rb
CHANGED
data/lib/googol/version.rb
CHANGED
@@ -66,6 +66,8 @@ module Googol
|
|
66
66
|
channel_id = fetch! target, :channel_id
|
67
67
|
youtube_request! path: '/subscriptions?part=snippet', json: true,
|
68
68
|
method: :post, body: {snippet: {resourceId: {channelId: channel_id}}}
|
69
|
+
rescue Googol::RequestError => e
|
70
|
+
raise e unless e.to_s =~ /subscriptionDuplicate/
|
69
71
|
end
|
70
72
|
|
71
73
|
# Return the first playlist of the Youtube account matching the attributes.
|