googol 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cced40105e7959c839fa4349625b98fddb0857b
4
- data.tar.gz: ba65e22653877a3cf0aadc9d4ef81838ea09879e
3
+ metadata.gz: 020552842d5bed2faefa55f19aa03c79256f63e5
4
+ data.tar.gz: 2e6b5289e68ee0a3d3549f6c8befec0130f1821d
5
5
  SHA512:
6
- metadata.gz: 69a0f394c1059aec6a06159f5e042aa7ec1f539a9646c0bbd06ae9b3e2362ffc9f115c10ad1887dcea477b993e069a7c21e007ee29605c0ca760d35f3962652f
7
- data.tar.gz: 2be89f5a97ce5285ed09bf0fcb900879c437f656a8232c495b9ddfc9b073b80adb03630d375fb2f6d4509d1d5b9580cd647f325b1de3df9e210c3fd87ab4a8fd
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/remhq'
15
- channel.id #=> 'UC7eaRqtonpyiYw0Pns0Au_g'
16
- channel.title #=> "remhq"
17
- channel.description #=> "R.E.M.'s Official YouTube Channel"
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
- # Adds a video to a playlist as a Youtube account
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.0'
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*)
@@ -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
 
@@ -1,5 +1,6 @@
1
1
  require 'uri'
2
2
  require 'json'
3
+ require 'net/http'
3
4
 
4
5
  module Googol
5
6
  # A custom class to rescue errors from interacting with Google V3 API
@@ -1,3 +1,3 @@
1
1
  module Googol
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo