vimeo_ruby 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +14 -14
- data/lib/vimeo_ruby/base.rb +10 -6
- data/lib/vimeo_ruby/user.rb +11 -8
- data/lib/vimeo_ruby/version.rb +1 -1
- data/lib/vimeo_ruby/video.rb +8 -6
- data/lib/vimeo_ruby.rb +7 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01dae6e1170aa75d17c9762587204a75c4cd6ac9c85ad26f76e9df0e2b065284
|
4
|
+
data.tar.gz: 349e1169f2d8a459b7cfc946d9716cf59890f9a357e05831c65669d8f9e2d52f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af42ee627547634179a17797f019d5b063c4618946ab1c8f3a7f85f8482c02871a85fce0c7e85e3bf16b0cb1ab5bf604768106f124eb4ff72fccb9f8718dfaab
|
7
|
+
data.tar.gz: 2def55ff87705a2692ba4823ab395a4e3582e587bcab827a43517c0ceca96a98ba408df3bc737fe06f4e556666aeb0d31cab8cf865356a9690fd995a8b648732
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
- Extract shared/mutual attributes for `vimeo_id` and `additional_info` from `VimeoRuby::User` and `VimeoRuby::Video` to parent class `VimeoRuby::Base`.
|
4
|
+
- Use consistent style when defining class or module level methods.
|
5
|
+
- Switch to set Authorization header with `access_token` aka `ENV["VIMEO_ACCESS_TOKEN"]` value and use for authorization when accessing public Vimeo API endpoints vs the previous basic_auth strategy.
|
6
|
+
- Change method signature for `VimeoRuby::get_user` method, now takes kwarg of `access_token`. Rename param in `VimeoRuby::get_video` method.
|
7
|
+
- `VimeoRuby::Base` now initializes with access_token
|
8
|
+
- Drop `Base::access_token` method.
|
9
|
+
- Add kwarg for access_token in `Base::get` method.
|
10
|
+
|
3
11
|
## [0.4.3] - 2022-12-29
|
4
12
|
|
5
13
|
- Inject `VimeoRuby::User` class in `VimeoRuby::Video::new` as default arg.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# VimeoRuby 0.
|
1
|
+
# VimeoRuby 0.5.0
|
2
2
|
|
3
3
|
Welcome to VimeoRuby!
|
4
4
|
|
@@ -25,14 +25,12 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
25
25
|
|
26
26
|
First, make sure you have a Vimeo account and have access to the following credentials from your Vimeo [My Apps dashboard](https://developer.vimeo.com/apps):
|
27
27
|
|
28
|
-
`access_token
|
28
|
+
`access_token`
|
29
29
|
|
30
|
-
Once you have
|
30
|
+
Once you have a valid `access_token`, assign it to the following environment variable:
|
31
31
|
|
32
32
|
```ruby
|
33
33
|
VIMEO_ACCESS_TOKEN=<access_token_value>
|
34
|
-
VIMEO_CLIENT_IDENTIFIER=<client_identifier_value>
|
35
|
-
VIMEO_CLIENT_SECRET=<client_secrete_value
|
36
34
|
```
|
37
35
|
|
38
36
|
Now you should be ready to continue onward and experiment with this first iteration of the gem interface.
|
@@ -41,23 +39,26 @@ Currently there are two main classes the you should use to interface with the Vi
|
|
41
39
|
|
42
40
|
### Working with the VimeoRuby::User class
|
43
41
|
|
44
|
-
For example,
|
42
|
+
For example, to get the currently authenticated user:
|
45
43
|
```ruby
|
46
|
-
vimeo_user = VimeoRuby::User.get_user(<
|
44
|
+
vimeo_user = VimeoRuby::User.get_user(access_token: <access_token>) # Makes http request to the Vimeo API
|
47
45
|
#=> #<VimeoRuby::User:0x000000011230df50
|
48
46
|
```
|
47
|
+
Upon successfully retrieving the authenticated user, the users `access_token` will be stored on the `VimeoRuby::User` instance (`vimeo_user` in the above example code) and
|
48
|
+
accessible for future requests via an `attr_reader` like so: `vimeo_user.access_token`
|
49
49
|
|
50
50
|
Alternatively, you can call the `get_user` method on the `VimeoRuby` module itself if you wish for something a bit shorter:
|
51
51
|
```ruby
|
52
|
-
vimeo_user = VimeoRuby.get_user(<
|
52
|
+
vimeo_user = VimeoRuby.get_user(access_token: <access_token>) # Makes http request to the Vimeo API
|
53
53
|
#=> #<VimeoRuby::User:0x000000011230df50
|
54
54
|
```
|
55
55
|
|
56
56
|
With the `VimeoRuby::User` instance that was returned from the successful call we can see what methods are available by running the preceeding and the following code in an irb session with the gem loaded:
|
57
57
|
```ruby
|
58
58
|
vimeo_user.methods.sort - Object.methods
|
59
|
-
=> [:
|
60
|
-
:
|
59
|
+
=> [:access_token,
|
60
|
+
:additional_info,
|
61
|
+
:available_for_hire,
|
61
62
|
:available_for_hire?,
|
62
63
|
:base_uri,
|
63
64
|
:bio,
|
@@ -66,12 +67,13 @@ vimeo_user.methods.sort - Object.methods
|
|
66
67
|
:location,
|
67
68
|
:profile_link,
|
68
69
|
:uploaded_videos,
|
70
|
+
:video_collection,
|
69
71
|
:vimeo_id]
|
70
72
|
```
|
71
73
|
|
72
74
|
We can then take the `vimeo_user` that we currently have stored and retrieve a collection of all of the users uploaded videos with the following:
|
73
75
|
```ruby
|
74
|
-
uploaded_video_collection = vimeo_user.uploaded_videos # Makes http request to the Vimeo API
|
76
|
+
uploaded_video_collection = vimeo_user.uploaded_videos # Makes http request to the Vimeo API only if the `vimeo_user.video_collection` value is nil or if query_params have been supplied.
|
75
77
|
# => #<VimeoRuby::User::UploadedVideoCollection:0x00000001130e98b8
|
76
78
|
```
|
77
79
|
|
@@ -100,11 +102,9 @@ vimeo_video = VimeoRuby.get_video(<vimeo_id>) # Makes http request to the Vimeo
|
|
100
102
|
|
101
103
|
## Development
|
102
104
|
|
103
|
-
At the moment, you will need to create a Vimeo account to obtain your own `access_token
|
105
|
+
At the moment, you will need to create a Vimeo account to obtain your own `access_token` if you wish to work on building out an interface to any of the Vimeo API endpoints.
|
104
106
|
Will be working on a solution to remedy this step in the future but for now, after obtaining these, set the values to the following env vars on your local machine accordingly:
|
105
107
|
- `VIMEO_ACCESS_TOKEN`
|
106
|
-
- `VIMEO_CLIENT_IDENTIFIER`
|
107
|
-
- `VIMEO_CLIENT_SECRET`
|
108
108
|
|
109
109
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
110
110
|
|
data/lib/vimeo_ruby/base.rb
CHANGED
@@ -3,15 +3,19 @@ require "net/http"
|
|
3
3
|
|
4
4
|
module VimeoRuby
|
5
5
|
class Base
|
6
|
+
attr_reader :access_token, :vimeo_id, :additional_info
|
7
|
+
|
8
|
+
def initialize(access_token: nil, vimeo_id: nil, remaining_attrs: {})
|
9
|
+
@access_token = access_token
|
10
|
+
@vimeo_id = extract_vimeo_id_from_uri(vimeo_id)
|
11
|
+
@additional_info = OpenStruct.new(remaining_attrs)
|
12
|
+
end
|
13
|
+
|
6
14
|
class << self
|
7
15
|
def base_uri
|
8
16
|
"https://api.vimeo.com"
|
9
17
|
end
|
10
18
|
|
11
|
-
def access_token
|
12
|
-
ENV["VIMEO_ACCESS_TOKEN"]
|
13
|
-
end
|
14
|
-
|
15
19
|
def client_identifier
|
16
20
|
ENV["VIMEO_CLIENT_IDENTIFIER"]
|
17
21
|
end
|
@@ -20,13 +24,13 @@ module VimeoRuby
|
|
20
24
|
ENV["VIMEO_CLIENT_SECRET"]
|
21
25
|
end
|
22
26
|
|
23
|
-
def get(uri, query_params: {})
|
27
|
+
def get(uri, query_params: {}, access_token: nil)
|
24
28
|
uri = URI.parse(uri)
|
25
29
|
uri.query = URI.encode_www_form(query_params)
|
26
30
|
|
27
31
|
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |https|
|
28
32
|
request = Net::HTTP::Get.new(uri)
|
29
|
-
request
|
33
|
+
request["Authorization"] = "bearer #{access_token}"
|
30
34
|
|
31
35
|
response = https.request(request)
|
32
36
|
JSON.parse(response.body)
|
data/lib/vimeo_ruby/user.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module VimeoRuby
|
2
2
|
class User < Base
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :video_collection, :available_for_hire, :bio, :can_work_remotely, :location, :name, :profile_link
|
4
4
|
|
5
|
-
def initialize(attrs: {})
|
6
|
-
@vimeo_id = extract_vimeo_id_from_uri(attrs.delete("uri"))
|
5
|
+
def initialize(access_token: nil, attrs: {})
|
7
6
|
@available_for_hire = attrs.delete("available_for_hire")
|
8
7
|
@bio = attrs.delete("bio")
|
9
8
|
@can_work_remotely = attrs.delete("can_work_remotely")
|
@@ -11,12 +10,15 @@ module VimeoRuby
|
|
11
10
|
@name = attrs.delete("name")
|
12
11
|
@profile_link = attrs.delete("link")
|
13
12
|
@video_collection = nil
|
14
|
-
|
13
|
+
vimeo_uri_with_id = attrs.delete("uri")
|
14
|
+
super(access_token: access_token, vimeo_id: vimeo_uri_with_id, remaining_attrs: attrs)
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
class << self
|
18
|
+
def get_user(access_token: nil)
|
19
|
+
user_info = get("#{base_uri}/me", access_token: access_token)
|
20
|
+
new(access_token: access_token, attrs: user_info)
|
21
|
+
end
|
20
22
|
end
|
21
23
|
|
22
24
|
def base_uri
|
@@ -42,7 +44,8 @@ module VimeoRuby
|
|
42
44
|
private
|
43
45
|
|
44
46
|
def retrieve_video_collection(query_params)
|
45
|
-
uploaded_videos_response = self.class.get("#{base_uri}/
|
47
|
+
uploaded_videos_response = self.class.get("#{base_uri}/me/videos", query_params: query_params, access_token: access_token)
|
48
|
+
|
46
49
|
uploaded_videos = uploaded_videos_response["data"]
|
47
50
|
UploadedVideoCollection.new(uploaded_videos)
|
48
51
|
end
|
data/lib/vimeo_ruby/version.rb
CHANGED
data/lib/vimeo_ruby/video.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module VimeoRuby
|
2
2
|
class Video < Base
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :description, :duration, :embed_html, :link, :name, :player_embed_url, :type, :user
|
4
4
|
|
5
5
|
def initialize(attrs: {}, user_class: VimeoRuby::User)
|
6
|
-
@vimeo_id = extract_vimeo_id_from_uri(attrs.delete("uri"))
|
7
6
|
@description = attrs.delete("description")
|
8
7
|
@duration = attrs.delete("duration")
|
9
8
|
@embed_html = attrs.delete("embed").delete("html")
|
@@ -12,12 +11,15 @@ module VimeoRuby
|
|
12
11
|
@player_embed_url = attrs.delete("player_embed_url")
|
13
12
|
@type = attrs.delete("type")
|
14
13
|
@user = user_class.new(attrs: attrs.delete("user"))
|
15
|
-
|
14
|
+
vimeo_uri_with_id = attrs.delete("uri")
|
15
|
+
super(vimeo_id: vimeo_uri_with_id, remaining_attrs: attrs)
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
class << self
|
19
|
+
def get_video(video_id)
|
20
|
+
video_info = get("#{base_uri}/videos/#{video_id}")
|
21
|
+
new(attrs: video_info)
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/vimeo_ruby.rb
CHANGED
@@ -10,11 +10,13 @@ require "vimeo_ruby/video"
|
|
10
10
|
module VimeoRuby
|
11
11
|
class Error < StandardError; end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
class << self
|
14
|
+
def get_user(access_token: nil)
|
15
|
+
User.get_user(access_token: access_token)
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
def get_video(video_id)
|
19
|
+
Video.get_video(video_id)
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|