vimeo_ruby 0.4.2 → 0.5.0

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: 6e322bad016985f2258e442017837049fd62007364cc6338ca4e705f7b573b5d
4
- data.tar.gz: 12fd20df10e0df161bb757931079f9d53aeb8468795a7ffac3f20b7ea4ed2228
3
+ metadata.gz: 01dae6e1170aa75d17c9762587204a75c4cd6ac9c85ad26f76e9df0e2b065284
4
+ data.tar.gz: 349e1169f2d8a459b7cfc946d9716cf59890f9a357e05831c65669d8f9e2d52f
5
5
  SHA512:
6
- metadata.gz: c0b0eb5766fa016c12d1992e3a67e063559ac3b48c53e053d04b8897ecf3f75f79ba693200b29301b032e32e145baeec2f8e15548ab099e63ac5b288818967ef
7
- data.tar.gz: 5f9507375cac59c5c9ccb88f4f40cef547fadee3e680319652585a62a247df7966e54c1750380d7a92b9c7215ea3ca53948c97428ef645707c8fbfccaf2c35c0
6
+ metadata.gz: af42ee627547634179a17797f019d5b063c4618946ab1c8f3a7f85f8482c02871a85fce0c7e85e3bf16b0cb1ab5bf604768106f124eb4ff72fccb9f8718dfaab
7
+ data.tar.gz: 2def55ff87705a2692ba4823ab395a4e3582e587bcab827a43517c0ceca96a98ba408df3bc737fe06f4e556666aeb0d31cab8cf865356a9690fd995a8b648732
data/CHANGELOG.md CHANGED
@@ -1,12 +1,24 @@
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
+
11
+ ## [0.4.3] - 2022-12-29
12
+
13
+ - Inject `VimeoRuby::User` class in `VimeoRuby::Video::new` as default arg.
14
+
3
15
  ## [0.4.2] - 2022-12-29
4
16
 
5
- - Refactor `VimeoRuby::User#uploaded_videos` method
17
+ - Refactor `VimeoRuby::User#uploaded_videos` method.
6
18
 
7
19
  ## [0.4.1] - 2022-12-29
8
20
 
9
- - Fix erroneous minor version release (yanked 0.4.0)
21
+ - Fix erroneous minor version release (yanked 0.4.0).
10
22
 
11
23
  ## [0.4.0] - 2022-12-29
12
24
 
@@ -22,4 +34,4 @@
22
34
 
23
35
  ## [0.1.0] - 2022-12-25
24
36
 
25
- - Initial release
37
+ - Initial release.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vimeo_ruby (0.4.2)
4
+ vimeo_ruby (0.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # VimeoRuby 0.4.2
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`, `client_identifier`, and `client_secret`
28
+ `access_token`
29
29
 
30
- Once you have access to these, assign them to the following environment variables accordingly:
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, should you want to find a particular Vimeo user by their `vimeo_id`, you can make the following call:
42
+ For example, to get the currently authenticated user:
45
43
  ```ruby
46
- vimeo_user = VimeoRuby::User.get_user(<vimeo_id>) # Makes http request to the Vimeo API
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(<vimeo_id>) # Makes http request to the Vimeo API
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
- => [:additional_info,
60
- :available_for_hire,
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`, `client_identifier`, and `client_secret` if you wish to work on building out an interface to any of the Vimeo API endpoints.
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
 
@@ -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.basic_auth(client_identifier, client_secret)
33
+ request["Authorization"] = "bearer #{access_token}"
30
34
 
31
35
  response = https.request(request)
32
36
  JSON.parse(response.body)
@@ -1,9 +1,8 @@
1
1
  module VimeoRuby
2
2
  class User < Base
3
- attr_reader :vimeo_id, :video_collection, :available_for_hire, :bio, :can_work_remotely, :location, :name, :profile_link, :additional_info
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
- @additional_info = OpenStruct.new(attrs)
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
- def self.get_user(user_id)
18
- user_info = get("#{base_uri}/users/#{user_id}")
19
- new(attrs: user_info)
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}/users/#{vimeo_id}/videos", query_params: query_params)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VimeoRuby
4
- VERSION = "0.4.2"
4
+ VERSION = "0.5.0"
5
5
  end
@@ -1,9 +1,8 @@
1
1
  module VimeoRuby
2
2
  class Video < Base
3
- attr_reader :vimeo_id, :description, :duration, :embed_html, :link, :name, :player_embed_url, :type, :user, :additional_info
3
+ attr_reader :description, :duration, :embed_html, :link, :name, :player_embed_url, :type, :user
4
4
 
5
- def initialize(attrs: {})
6
- @vimeo_id = extract_vimeo_id_from_uri(attrs.delete("uri"))
5
+ def initialize(attrs: {}, user_class: VimeoRuby::User)
7
6
  @description = attrs.delete("description")
8
7
  @duration = attrs.delete("duration")
9
8
  @embed_html = attrs.delete("embed").delete("html")
@@ -11,13 +10,16 @@ module VimeoRuby
11
10
  @name = attrs.delete("name")
12
11
  @player_embed_url = attrs.delete("player_embed_url")
13
12
  @type = attrs.delete("type")
14
- @user = VimeoRuby::User.new(attrs: attrs.delete("user"))
15
- @additional_info = OpenStruct.new(attrs)
13
+ @user = user_class.new(attrs: attrs.delete("user"))
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
- def self.get_video(video_id)
19
- video_info = get("#{base_uri}/videos/#{video_id}")
20
- new(attrs: video_info)
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
- def self.get_user(vimeo_id)
14
- User.get_user(vimeo_id)
15
- end
13
+ class << self
14
+ def get_user(access_token: nil)
15
+ User.get_user(access_token: access_token)
16
+ end
16
17
 
17
- def self.get_video(vimeo_id)
18
- Video.get_video(vimeo_id)
18
+ def get_video(video_id)
19
+ Video.get_video(video_id)
20
+ end
19
21
  end
20
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vimeo_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collin Jilbert