youtuberb 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 077f18d1405580ce9255dc91b55e8c05a752580a3e1745fa2f86c86ec2209a87
4
- data.tar.gz: 76149a42121aeb7ae410429e83db0aa5f646b4b94cfd0bfa0298be163e217cc1
3
+ metadata.gz: 3f8d3b68ce9d206b19c96ccf31e5707379fcb98a989805f133df36a59c440e65
4
+ data.tar.gz: 0f9ef583ce567c2dcc7da4474cd9575efd54ba967a59c1e1809a7bbc78f07d5c
5
5
  SHA512:
6
- metadata.gz: 86b29dcf4cc5b3d5a2e53a816e2f2831dd37f578afeb0bc60e5686f8a847049b2cf7b76eb3923b6d118afe33d51ec0438be6ab84cce9274e1821ac6ecfc2f043
7
- data.tar.gz: 18fad6518cd63067765c06786627a1645d1909ee64c57d3690b586d2949aad5a84015726160654ace922f37831569845560638677da4ff220936da210bb1627a
6
+ metadata.gz: 6fda64e56e4ac55557fb661a3d35e952bf5f2d415848598598cae30b0a12cd5ce8ed46ee62df1107030c2102039e53544f5d58128b711191ec4556ba539a0b03
7
+ data.tar.gz: 86e6f3c535e6d1e40947237c5dc89f0330edf64ea4fa438dd18075fc91be5ec1cb33b3c58956507f0084e3bae7c7967d0c0e551fbeea96db5f95dcde6b5d5e7f
data/Gemfile.lock CHANGED
@@ -1,39 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- youtuberb (0.1.0)
5
- faraday (~> 1.7)
6
- faraday-multipart (~> 1.0)
7
- faraday_middleware (~> 1.1)
4
+ youtuberb (0.1.3)
5
+ faraday (~> 2.0)
8
6
 
9
7
  GEM
10
8
  remote: https://rubygems.org/
11
9
  specs:
12
10
  dotenv (2.7.6)
13
- faraday (1.8.0)
14
- faraday-em_http (~> 1.0)
15
- faraday-em_synchrony (~> 1.0)
16
- faraday-excon (~> 1.1)
17
- faraday-httpclient (~> 1.0.1)
18
- faraday-net_http (~> 1.0)
19
- faraday-net_http_persistent (~> 1.1)
20
- faraday-patron (~> 1.0)
21
- faraday-rack (~> 1.0)
22
- multipart-post (>= 1.2, < 3)
11
+ faraday (2.2.0)
12
+ faraday-net_http (~> 2.0)
23
13
  ruby2_keywords (>= 0.0.4)
24
- faraday-em_http (1.0.0)
25
- faraday-em_synchrony (1.0.0)
26
- faraday-excon (1.1.0)
27
- faraday-httpclient (1.0.1)
28
- faraday-multipart (1.0.3)
29
- multipart-post (>= 1.2, < 3)
30
- faraday-net_http (1.0.1)
31
- faraday-net_http_persistent (1.2.0)
32
- faraday-patron (1.0.0)
33
- faraday-rack (1.0.0)
34
- faraday_middleware (1.2.0)
35
- faraday (~> 1.0)
36
- multipart-post (2.1.1)
14
+ faraday-net_http (2.0.2)
37
15
  rake (13.0.6)
38
16
  ruby2_keywords (0.0.5)
39
17
 
data/README.md CHANGED
@@ -17,15 +17,39 @@ gem 'youtuberb'
17
17
  ### Set Client Details
18
18
 
19
19
  Firstly you'll need to set an API Key and an Access Token.
20
+ An Access Token will be an OAuth2 token generated after authentication.
20
21
 
21
22
  ```ruby
22
23
  @client = YouTube::Client.new(api_key: "", access_token: "")
23
24
  ```
24
25
 
26
+ ### Channels
27
+
28
+ ```ruby
29
+ # Get the Channel details of the currently authenticated user
30
+ @client.channels.mine
31
+
32
+ # Get a Channel by ID
33
+ @client.channels.retrieve(id: "channel_id")
34
+
35
+ # Get a Channel by username
36
+ @client.channels.retrieve(username: "username")
37
+ ```
38
+
25
39
  ### Videos
26
40
 
27
41
  ```ruby
28
- @client.videos.get_by_id(user_id: 141981764)
42
+ # Get a single video
43
+ @client.videos.list(id: "abc123")
44
+
45
+ # Get multiple videos
46
+ @client.videos.list(id: "abc123,123abc")
47
+
48
+ # Liked videos for the currently authenticated user
49
+ @client.videos.liked
50
+
51
+ # Get a video owned by the current user. This retrieves extra information so will only work on videos owned by the current user.
52
+ @client.videos.retrieve(id: "abc123")
29
53
  ```
30
54
 
31
55
  ### Playlists
@@ -45,6 +69,22 @@ Firstly you'll need to set an API Key and an Access Token.
45
69
  @client.playlists.update(id: "playlist_id", title: "My Playlist", privacy_status: "public")
46
70
  @client.playlists.delete(id: "playlist_id")
47
71
  ```
72
+ ### Playlist Items
73
+
74
+ ```ruby
75
+ # Playlist Items for a Playlist
76
+ @client.playlist_items.list(playlist_id: "playlist_id")
77
+
78
+ @client.playlist_items.retrieve(id: "playlist_item_id")
79
+
80
+ # Add a video to a playlist
81
+ @client.playlist_items.create(playlist_id: "playlist_id", video_id: "video_id")
82
+
83
+ @client.playlist_items.update(id: "playlist_item_id", playlist_id: "playlist_id", video_id: "video_id")
84
+
85
+ @client.playlist_items.delete(id: "playlist_id")
86
+ ```
87
+
48
88
  ## Contributing
49
89
 
50
90
  Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/youtuberb.
@@ -13,8 +13,8 @@ module YouTube
13
13
  @stubs = stubs
14
14
  end
15
15
 
16
- def activities
17
- ActivitiesResource.new(self)
16
+ def channels
17
+ ChannelsResource.new(self)
18
18
  end
19
19
 
20
20
  def videos
@@ -34,21 +34,11 @@ module YouTube
34
34
  conn.request :authorization, :Bearer, access_token
35
35
  conn.request :json
36
36
 
37
- conn.response :dates
38
37
  conn.response :json, content_type: "application/json"
39
38
 
40
39
  conn.adapter adapter, @stubs
41
40
  end
42
41
  end
43
42
 
44
- # Uses Faraday Multipart (lostisland/faraday-multipart)
45
- def connection_upload
46
- @connection ||= Faraday.new("https://www.googleapis.com/upload/youtube/v3/") do |conn|
47
- conn.request :authorization, :Bearer, access_token
48
- conn.request :multipart
49
- conn.response :json, content_type: "application/json"
50
- end
51
- end
52
-
53
43
  end
54
44
  end
@@ -0,0 +1,29 @@
1
+ module YouTube
2
+ class Channel < Object
3
+
4
+ def initialize(options = {})
5
+ super options
6
+
7
+ if options["snippet"]
8
+ self.title = options["snippet"]["title"]
9
+ self.description = options["snippet"]["description"]
10
+ self.published_at = options["snippet"]["publishedAt"]
11
+
12
+ if options["snippet"]["thumbnails"]
13
+ thumb = options["snippet"]["thumbnails"]
14
+ self.thumbnail_default = thumb["default"]["url"] if thumb["default"]
15
+ self.thumbnail_medium = thumb["medium"]["url"] if thumb["medium"]
16
+ self.thumbnail_high = thumb["high"]["url"] if thumb["high"]
17
+ self.thumbnail_standard = thumb["standard"]["url"] if thumb["standard"]
18
+ self.thumbnail_maxres = thumb["maxres"]["url"] if thumb["maxres"]
19
+ end
20
+ end
21
+
22
+ if options["status"]
23
+ self.privacy_status = options["status"]["privacyStatus"]
24
+ self.long_uploads_status = options["status"]["longUploadsStatus"]
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ module YouTube
2
+ class ChannelsResource < Resource
3
+
4
+ PARTS = "id,snippet,status,statistics"
5
+
6
+ # Retrieve the channel of the currently authenticated user
7
+ def mine
8
+ response = get_request "channels", params: {mine: true, part: PARTS}
9
+ return nil if response.body["pageInfo"]["totalResults"] == 0
10
+ Channel.new(response.body["items"][0])
11
+ end
12
+
13
+ # Retrieve a Channel by its ID or Username
14
+ def retrieve(id: nil, username: nil)
15
+ attrs = {}
16
+ attrs[:id] = id if id
17
+ attrs[:forUsername] = username if username
18
+
19
+ response = get_request "channels", params: attrs.merge({part: PARTS})
20
+ return nil if response.body["pageInfo"]["totalResults"] == 0
21
+ Channel.new(response.body["items"][0])
22
+ end
23
+
24
+ end
25
+ end
@@ -24,18 +24,5 @@ module YouTube
24
24
  Video.new(response.body["items"][0])
25
25
  end
26
26
 
27
- # Uploads a video
28
- # Currently just uploads a video
29
- # Needs more testing
30
- # https://developers.google.com/youtube/v3/docs/videos/insert
31
- def upload(file:)
32
- payload = {}
33
- payload[:media] = Faraday::Multipart::FilePart.new(file, "video/*")
34
-
35
- response = client.connection_upload.post "videos", payload
36
-
37
- response.body
38
- end
39
-
40
27
  end
41
28
  end
@@ -1,3 +1,3 @@
1
1
  module YouTube
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/you_tube.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require "faraday"
2
- require "faraday_middleware"
3
- require "faraday/multipart"
4
2
  require "json"
5
3
 
6
4
  require_relative "you_tube/version"
@@ -13,12 +11,12 @@ module YouTube
13
11
  autoload :Resource, "you_tube/resource"
14
12
  autoload :Object, "you_tube/object"
15
13
 
16
- autoload :ActivitiesResource, "you_tube/resources/activities"
14
+ autoload :ChannelsResource, "you_tube/resources/channels"
17
15
  autoload :VideosResource, "you_tube/resources/videos"
18
16
  autoload :PlaylistsResource, "you_tube/resources/playlists"
19
17
  autoload :PlaylistItemsResource, "you_tube/resources/playlist_items"
20
18
 
21
- autoload :Activity, "you_tube/objects/activity"
19
+ autoload :Channel, "you_tube/objects/channel"
22
20
  autoload :Video, "you_tube/objects/video"
23
21
  autoload :Playlist, "you_tube/objects/playlist"
24
22
  autoload :PlaylistItem, "you_tube/objects/playlist_item"
data/youtuberb.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.required_ruby_version = ">= 2.6.0"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
- # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
17
+ spec.metadata["source_code_uri"] = "https://github.com/deanpcmad/youtuberb"
18
18
  # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
@@ -28,7 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
- spec.add_dependency "faraday", "~> 1.7"
32
- spec.add_dependency "faraday_middleware", "~> 1.1"
33
- spec.add_dependency "faraday-multipart", "~> 1.0"
31
+ spec.add_dependency "faraday", "~> 2.0"
34
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youtuberb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Perry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-05 00:00:00.000000000 Z
11
+ date: 2022-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,42 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
27
- - !ruby/object:Gem::Dependency
28
- name: faraday_middleware
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.1'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.1'
41
- - !ruby/object:Gem::Dependency
42
- name: faraday-multipart
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.0'
26
+ version: '2.0'
55
27
  description:
56
28
  email:
57
29
  - dean@deanpcmad.com
@@ -72,12 +44,12 @@ files:
72
44
  - lib/you_tube/collection.rb
73
45
  - lib/you_tube/error.rb
74
46
  - lib/you_tube/object.rb
75
- - lib/you_tube/objects/activity.rb
47
+ - lib/you_tube/objects/channel.rb
76
48
  - lib/you_tube/objects/playlist.rb
77
49
  - lib/you_tube/objects/playlist_item.rb
78
50
  - lib/you_tube/objects/video.rb
79
51
  - lib/you_tube/resource.rb
80
- - lib/you_tube/resources/activities.rb
52
+ - lib/you_tube/resources/channels.rb
81
53
  - lib/you_tube/resources/playlist_items.rb
82
54
  - lib/you_tube/resources/playlists.rb
83
55
  - lib/you_tube/resources/videos.rb
@@ -89,6 +61,7 @@ licenses:
89
61
  - MIT
90
62
  metadata:
91
63
  homepage_uri: https://deanpcmad.com
64
+ source_code_uri: https://github.com/deanpcmad/youtuberb
92
65
  post_install_message:
93
66
  rdoc_options: []
94
67
  require_paths:
@@ -104,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
77
  - !ruby/object:Gem::Version
105
78
  version: '0'
106
79
  requirements: []
107
- rubygems_version: 3.1.6
80
+ rubygems_version: 3.2.22
108
81
  signing_key:
109
82
  specification_version: 4
110
83
  summary: A Ruby library for interacting with the YouTube API
@@ -1,4 +0,0 @@
1
- module YouTube
2
- class Activity < Object
3
- end
4
- end
@@ -1,11 +0,0 @@
1
- module YouTube
2
- class ActivitiesResource < Resource
3
-
4
- def list
5
- response = get_request "activities", params: {home: true}
6
- # response = post_request("games", body: "fields id,name,status,url,created_at,updated_at;")
7
- # Collection.from_response(response, type: Game)
8
- end
9
-
10
- end
11
- end