vimeo_ruby 0.1.0 → 0.3.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: d06b7f4e83dc3ddb9c40c420d18a7b707fb273bb9e8491cca92b20ded84c456d
4
- data.tar.gz: bc4fdd727846ed4499a8ac03931de9b190e26e6928be6ae14fbeaf3a6d424aec
3
+ metadata.gz: 1ed0fda96d5d2a68abd3abc83ad39b0687ed9346db340ff49e990d949657977a
4
+ data.tar.gz: 5b1cc75bf6d4955c859ab443ebb167dcd96bb9cd63c1cd7505206180aa1ab0aa
5
5
  SHA512:
6
- metadata.gz: 54271f8b1c668b26158d29ce599397033124fb7cef4030d1e173d1fc0ed0c7ce5b75875501bb7943f663edc222e77d3260ce2f3f291742989533b164ab6c25d4
7
- data.tar.gz: 2acaf5c8ed60d72854106df961ec08a5cab30082f4788c6dcc17e8382a7a33bb153cd75b9e28e20539d82d59b9570bcfb8538a22d36b8ee7db41be0e143b5250
6
+ metadata.gz: 50aa3fb2068c01fcd2ce01d3cf09a33b56a08688f1ef7f8a118f5f2b99679576a65510849f398993fafbd7056954f8ad9f9400ec6c139971909370f787fa139c
7
+ data.tar.gz: 2354449f341d3e996e6488f65aa52e97425ed6bfa2003d011566050ae8f8096fe87b7b448ef7f8d6167e6eb1d0ac4451853d180f1608772b8936844681d5985f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2022-12-28
4
+
5
+ - Initial User and Video classes, with beginning interface to retrieve records from the Vimeo API. Adds a connection class used to hold a collection of a users uploaded videos (VimeoRuby::User::UploadedVideoCollection) accessible by calling `VimeoRuby::User#uploaded_videos`.
6
+
3
7
  ## [0.1.0] - 2022-12-25
4
8
 
5
9
  - Initial release
data/Gemfile.lock ADDED
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vimeo_ruby (0.3.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.8.1)
10
+ public_suffix (>= 2.0.2, < 6.0)
11
+ ast (2.4.2)
12
+ crack (0.4.5)
13
+ rexml
14
+ hashdiff (1.0.1)
15
+ json (2.6.3)
16
+ language_server-protocol (3.17.0.2)
17
+ minitest (5.16.3)
18
+ parallel (1.22.1)
19
+ parser (3.1.3.0)
20
+ ast (~> 2.4.1)
21
+ public_suffix (5.0.1)
22
+ rainbow (3.1.1)
23
+ rake (13.0.6)
24
+ regexp_parser (2.6.1)
25
+ rexml (3.2.5)
26
+ rubocop (1.40.0)
27
+ json (~> 2.3)
28
+ parallel (~> 1.10)
29
+ parser (>= 3.1.2.1)
30
+ rainbow (>= 2.2.2, < 4.0)
31
+ regexp_parser (>= 1.8, < 3.0)
32
+ rexml (>= 3.2.5, < 4.0)
33
+ rubocop-ast (>= 1.23.0, < 2.0)
34
+ ruby-progressbar (~> 1.7)
35
+ unicode-display_width (>= 1.4.0, < 3.0)
36
+ rubocop-ast (1.24.0)
37
+ parser (>= 3.1.1.0)
38
+ rubocop-performance (1.15.1)
39
+ rubocop (>= 1.7.0, < 2.0)
40
+ rubocop-ast (>= 0.4.0)
41
+ ruby-progressbar (1.11.0)
42
+ standard (1.20.0)
43
+ language_server-protocol (~> 3.17.0.2)
44
+ rubocop (= 1.40.0)
45
+ rubocop-performance (= 1.15.1)
46
+ unicode-display_width (2.3.0)
47
+ vcr (6.1.0)
48
+ webmock (3.18.1)
49
+ addressable (>= 2.8.0)
50
+ crack (>= 0.3.2)
51
+ hashdiff (>= 0.4.0, < 2.0.0)
52
+
53
+ PLATFORMS
54
+ x86_64-darwin-21
55
+ x86_64-linux
56
+
57
+ DEPENDENCIES
58
+ minitest (~> 5.0)
59
+ rake (~> 13.0)
60
+ standard (~> 1.3)
61
+ vcr (~> 6.1)
62
+ vimeo_ruby!
63
+ webmock (~> 3.18, >= 3.18.1)
64
+
65
+ BUNDLED WITH
66
+ 2.4.1
data/README.md CHANGED
@@ -1,34 +1,122 @@
1
- # VimeoRuby
1
+ # VimeoRuby 0.2.0
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Welcome to VimeoRuby!
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vimeo_ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ ## Development Philosophy/Mindset
6
6
 
7
- ## Installation
7
+ The mindset of this project at this stage of development is to:
8
+ 1. Be simple - Write boring code, resist pulling in additional gems as much as possible, and don't worry about edge cases or handling errors all that much right now.
9
+ 2. Try to be as object-oriented as possible. I'm not an OO expert and you don't have to be either but let's try to improve our OO skills.
10
+ 3. Have fun. Who wants another job? Not me so let's keep it light and make something cool!
8
11
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
12
+ ## Installation
10
13
 
11
14
  Install the gem and add to the application's Gemfile by executing:
12
15
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
16
+ $ bundle add vimeo_ruby
14
17
 
15
18
  If bundler is not being used to manage dependencies, install the gem by executing:
16
19
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
20
+ $ gem install vimeo_ruby
18
21
 
19
22
  ## Usage
20
23
 
21
- TODO: Write usage instructions here
24
+ ### Configure Credentials
25
+
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
+
28
+ `access_token`, `client_identifier`, and `client_secret`
29
+
30
+ Once you have access to these, assign them to the following environment variables accordingly:
31
+
32
+ ```ruby
33
+ VIMEO_ACCESS_TOKEN=<access_token_value>
34
+ VIMEO_CLIENT_IDENTIFIER=<client_identifier_value>
35
+ VIMEO_CLIENT_SECRET=<client_secrete_value
36
+ ```
37
+
38
+ Now you should be ready to continue onward and experiment with this first iteration of the gem interface.
39
+
40
+ Currently there are two main classes the you should use to interface with the Vimeo API through which are `VimeoRuby::User` and `VimeoRuby::Video`.
41
+
42
+ ### Working with the VimeoRuby::User class
43
+
44
+ For example, should you want to find a particular Vimeo user by their `vimeo_id`, you can make the following call:
45
+ ```ruby
46
+ vimeo_user = VimeoRuby::User.get_user(<vimeo_id>) # Makes http request to the Vimeo API
47
+ #=> #<VimeoRuby::User:0x000000011230df50
48
+ ```
49
+
50
+ Alternatively, you can call the `get_user` method on the `VimeoRuby` module itself if you wish for something a bit shorter:
51
+ ```ruby
52
+ vimeo_user = VimeoRuby.get_user(<vimeo_id>) # Makes http request to the Vimeo API
53
+ #=> #<VimeoRuby::User:0x000000011230df50
54
+ ```
55
+
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
+ ```ruby
58
+ vimeo_user.methods.sort - Object.methods
59
+ => [:additional_info,
60
+ :available_for_hire,
61
+ :available_for_hire?,
62
+ :base_uri,
63
+ :bio,
64
+ :can_work_remotely,
65
+ :can_work_remotely?,
66
+ :location,
67
+ :profile_link,
68
+ :uploaded_videos,
69
+ :vimeo_id]
70
+ ```
71
+
72
+ 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
+ ```ruby
74
+ uploaded_video_collection = vimeo_user.uploaded_videos # Makes http request to the Vimeo API
75
+ # => #<VimeoRuby::User::UploadedVideoCollection:0x00000001130e98b8
76
+ ```
77
+
78
+ The `VimeoRuby::User::UploadedVideoCollection` object stores an array of `VimeoRuby::Video` objects which are accessible by calling:
79
+ ```ruby
80
+ uploaded_video_collection.videos # No http request is made to the Vimeo API
81
+ #=> [#<VimeoRuby::Video:0x0000000112fb3228
82
+ # ....,
83
+ # ....,
84
+ # ]
85
+ ```
86
+
87
+ ### Working with the VimeoRuby::Video class
88
+
89
+ To retrieve a particular video from Vimeo you can use the following call:
90
+ ```ruby
91
+ vimeo_video = VimeoRuby::Video.get_video(<vimeo_id>)
92
+ #=> #<VimeoRuby::Video:0x000000022341eg61
93
+ ```
94
+
95
+ Alternatively, you can call the `get_video` method on the `VimeoRuby` module itself if you wish for something a bit shorter:
96
+ ```ruby
97
+ vimeo_video = VimeoRuby.get_video(<vimeo_id>) # Makes http request to the Vimeo API
98
+ #=> #<VimeoRuby::Video:0x0000000223gc4339
99
+ ```
22
100
 
23
101
  ## Development
24
102
 
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.
104
+ 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
+ - `VIMEO_ACCESS_TOKEN`
106
+ - `VIMEO_CLIENT_IDENTIFIER`
107
+ - `VIMEO_CLIENT_SECRET`
108
+
25
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.
26
110
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
111
+ To install this gem onto your local machine, run `bundle exec rake install`.
112
+
113
+ ### Maintainers only
114
+
115
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
116
 
29
117
  ## Contributing
30
118
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vimeo_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/vimeo_ruby/blob/main/CODE_OF_CONDUCT.md).
119
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cjilbert504/vimeo_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/cjilbert504/vimeo_ruby/blob/main/CODE_OF_CONDUCT.md).
32
120
 
33
121
  ## License
34
122
 
@@ -36,4 +124,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
36
124
 
37
125
  ## Code of Conduct
38
126
 
39
- Everyone interacting in the VimeoRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/vimeo_ruby/blob/main/CODE_OF_CONDUCT.md).
127
+ Everyone interacting in the VimeoRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cjilbert504/vimeo_ruby/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,43 @@
1
+ require "json"
2
+ require "net/http"
3
+
4
+ module VimeoRuby
5
+ class Base
6
+ class << self
7
+ def base_uri
8
+ "https://api.vimeo.com"
9
+ end
10
+
11
+ def access_token
12
+ ENV["VIMEO_ACCESS_TOKEN"]
13
+ end
14
+
15
+ def client_identifier
16
+ ENV["VIMEO_CLIENT_IDENTIFIER"]
17
+ end
18
+
19
+ def client_secret
20
+ ENV["VIMEO_CLIENT_SECRET"]
21
+ end
22
+
23
+ def get(uri, query_params: {})
24
+ uri = URI.parse(uri)
25
+ uri.query = URI.encode_www_form(query_params)
26
+
27
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |https|
28
+ request = Net::HTTP::Get.new(uri)
29
+ request.basic_auth(client_identifier, client_secret)
30
+
31
+ response = https.request(request)
32
+ JSON.parse(response.body)
33
+ end
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def extract_vimeo_id_from_uri(vimeo_uri)
40
+ vimeo_uri.match(/\d+/)[0].to_i
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,13 @@
1
+ module VimeoRuby
2
+ class User < Base
3
+ class UploadedVideoCollection
4
+ attr_reader :videos
5
+
6
+ def initialize(videos_array)
7
+ @videos = videos_array.map do |video_data|
8
+ Video.new(attrs: video_data)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ module VimeoRuby
2
+ class User < Base
3
+ attr_reader :vimeo_id, :available_for_hire, :bio, :can_work_remotely, :location, :name, :profile_link, :additional_info
4
+
5
+ def initialize(attrs: {})
6
+ @vimeo_id = extract_vimeo_id_from_uri(attrs.delete("uri"))
7
+ @available_for_hire = attrs.delete("available_for_hire")
8
+ @bio = attrs.delete("bio")
9
+ @can_work_remotely = attrs.delete("can_work_remotely")
10
+ @location = attrs.delete("location")
11
+ @name = attrs.delete("name")
12
+ @profile_link = attrs.delete("link")
13
+ @additional_info = OpenStruct.new(attrs)
14
+ end
15
+
16
+ def self.get_user(user_id)
17
+ user_info = get("#{base_uri}/users/#{user_id}")
18
+ new(attrs: user_info)
19
+ end
20
+
21
+ def base_uri
22
+ self.class.base_uri
23
+ end
24
+
25
+ def uploaded_videos(query_params: {})
26
+ uploaded_videos_response = self.class.get("#{base_uri}/users/#{vimeo_id}/videos", query_params: query_params)
27
+ uploaded_videos = uploaded_videos_response["data"]
28
+ UploadedVideoCollection.new(uploaded_videos)
29
+ end
30
+
31
+ def available_for_hire?
32
+ @available_for_hire
33
+ end
34
+
35
+ def can_work_remotely?
36
+ @can_work_remotely
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VimeoRuby
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -0,0 +1,23 @@
1
+ module VimeoRuby
2
+ class Video < Base
3
+ attr_reader :vimeo_id, :description, :duration, :embed_html, :link, :name, :player_embed_url, :type, :user, :additional_info
4
+
5
+ def initialize(attrs: {})
6
+ @vimeo_id = extract_vimeo_id_from_uri(attrs.delete("uri"))
7
+ @description = attrs.delete("description")
8
+ @duration = attrs.delete("duration")
9
+ @embed_html = attrs.delete("embed").delete("html")
10
+ @link = attrs.delete("link")
11
+ @name = attrs.delete("name")
12
+ @player_embed_url = attrs.delete("player_embed_url")
13
+ @type = attrs.delete("type")
14
+ @user = VimeoRuby::User.new(attrs: attrs.delete("user"))
15
+ @additional_info = OpenStruct.new(attrs)
16
+ end
17
+
18
+ def self.get_video(video_id)
19
+ video_info = get("#{base_uri}/videos/#{video_id}")
20
+ new(attrs: video_info)
21
+ end
22
+ end
23
+ end
data/lib/vimeo_ruby.rb CHANGED
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "net/http"
4
- require_relative "vimeo_ruby/version"
3
+ require "ostruct"
4
+ require "vimeo_ruby/base"
5
+ require "vimeo_ruby/user"
6
+ require "vimeo_ruby/user/uploaded_video_collection"
7
+ require "vimeo_ruby/version"
8
+ require "vimeo_ruby/video"
5
9
 
6
10
  module VimeoRuby
7
11
  class Error < StandardError; end
8
12
 
9
- class Vimeo
10
- attr_reader :base_uri
13
+ def self.get_user(vimeo_id)
14
+ User.get_user(vimeo_id)
15
+ end
11
16
 
12
- def initialize
13
- @base_uri = URI("https://api.vimeo.com/tutorial")
14
- end
15
-
16
- def tutorial_request
17
- Net::HTTP.get_response(base_uri, { "Authorization": "bearer #{ENV["VIMEO_ACCESS_TOKEN"]}" })
18
- end
19
- end
17
+ def self.get_video(vimeo_id)
18
+ Video.get_video(vimeo_id)
19
+ end
20
20
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/vimeo_ruby/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "vimeo_ruby"
7
+ spec.version = VimeoRuby::VERSION
8
+ spec.authors = ["Collin Jilbert"]
9
+ spec.email = ["cjilbert504@gmail.com"]
10
+
11
+ spec.summary = "A Ruby gem for interacting with the Vimeo API"
12
+ spec.description = "A Ruby gem for interacting with the Vimeo API"
13
+ spec.homepage = "https://github.com/cjilbert504/vimeo_ruby"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/cjilbert504/vimeo_ruby"
19
+ spec.metadata["changelog_uri"] = "https://github.com/cjilbert504/vimeo_ruby/blob/main/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ spec.add_development_dependency "webmock", "~> 3.18", ">= 3.18.1"
36
+ spec.add_development_dependency "vcr", "~> 6.1"
37
+
38
+ # For more information and examples about making a new gem, check out our
39
+ # guide at: https://bundler.io/guides/creating_gem.html
40
+ end
metadata CHANGED
@@ -1,15 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vimeo_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collin Jilbert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-26 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: webmock
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.18'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.18.1
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.18'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.18.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: vcr
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '6.1'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '6.1'
13
47
  description: A Ruby gem for interacting with the Vimeo API
14
48
  email:
15
49
  - cjilbert504@gmail.com
@@ -21,12 +55,18 @@ files:
21
55
  - CHANGELOG.md
22
56
  - CODE_OF_CONDUCT.md
23
57
  - Gemfile
58
+ - Gemfile.lock
24
59
  - LICENSE.txt
25
60
  - README.md
26
61
  - Rakefile
27
62
  - lib/vimeo_ruby.rb
63
+ - lib/vimeo_ruby/base.rb
64
+ - lib/vimeo_ruby/user.rb
65
+ - lib/vimeo_ruby/user/uploaded_video_collection.rb
28
66
  - lib/vimeo_ruby/version.rb
67
+ - lib/vimeo_ruby/video.rb
29
68
  - sig/vimeo_ruby.rbs
69
+ - vimeo_ruby.gemspec
30
70
  homepage: https://github.com/cjilbert504/vimeo_ruby
31
71
  licenses:
32
72
  - MIT