vimeorb 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6c78e0691674c67ddd260b6fcd7bfdaa63969b4ac607a407c0e2db0cf2764faf
4
+ data.tar.gz: 0fd974c57a0cb41d2ef89a4a170334d50400942ab8c746a9234c292d73e4f345
5
+ SHA512:
6
+ metadata.gz: '0649be4eaf989d832a1efb509b0a2790493fe2e44b60f736c26ed8ebd7eed61d8d01672e06ece5c124d7bfdffb4e4abdd3b55a0f2fc5ad61577a80632710c295'
7
+ data.tar.gz: 92e3d0c5477479f34a8cf268cfbfd8f846edf964a595411b117f2593039bdcb8788179c0bc8941f4adfce2c3dc9ac352322a56be94e9d404f61d546c9c5bb08f
data/.env.example ADDED
@@ -0,0 +1 @@
1
+ ACCESS_TOKEN=
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in youtuberb.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "dotenv"
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vimeorb (0.1.1)
5
+ faraday (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ dotenv (2.7.6)
11
+ faraday (2.2.0)
12
+ faraday-net_http (~> 2.0)
13
+ ruby2_keywords (>= 0.0.4)
14
+ faraday-net_http (2.0.2)
15
+ rake (13.0.6)
16
+ ruby2_keywords (0.0.5)
17
+
18
+ PLATFORMS
19
+ x86_64-linux
20
+
21
+ DEPENDENCIES
22
+ dotenv
23
+ rake (~> 13.0)
24
+ vimeorb!
25
+
26
+ BUNDLED WITH
27
+ 2.3.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Dean Perry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # VimeoRB
2
+
3
+ **This library is a work in progress**
4
+
5
+ VimeoRB is a Ruby library for interacting with the Vimeo v3.4 API.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vimeorb'
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Set Client Details
18
+
19
+ Firstly you'll need to set an Access Token.
20
+ An Access Token will be an OAuth2 token generated after authentication.
21
+
22
+ ```ruby
23
+ @client = Vimeo::Client.new(access_token: "")
24
+ ```
25
+
26
+ ### Videos
27
+
28
+ ```ruby
29
+ # Retrieve a Video's details
30
+ @client.videos.retrieve(id: "abc123")
31
+
32
+ # Edit a Video
33
+ params = {title: "New Title"}
34
+ @client.videos.edit(id: "abc123", params)
35
+
36
+ # Delete a Video
37
+ @client.videos.delete(id: "abc123")
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/vimeorb.
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/console ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "vimeo"
6
+
7
+ # Load environment variables from .env file
8
+ require 'dotenv/load'
9
+
10
+ # You can add fixtures and/or initialization code here to make experimenting
11
+ # with your gem easier. You can also use a different console, if you like.
12
+
13
+ # (If you use this, don't forget to add pry to your Gemfile!)
14
+ # require "pry"
15
+ # Pry.start
16
+
17
+ @client = Vimeo::Client.new(access_token: ENV["ACCESS_TOKEN"])
18
+
19
+ require "irb"
20
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ module Vimeo
2
+ class Client
3
+ BASE_URL = "https://api.vimeo.com"
4
+
5
+ attr_reader :access_token, :adapter
6
+
7
+ def initialize(access_token:, adapter: Faraday.default_adapter, stubs: nil)
8
+ @access_token = access_token
9
+ @adapter = adapter
10
+
11
+ # Test stubs for requests
12
+ @stubs = stubs
13
+ end
14
+
15
+ def videos
16
+ VideosResource.new(self)
17
+ end
18
+
19
+ def connection
20
+ @connection ||= Faraday.new(BASE_URL) do |conn|
21
+ conn.request :authorization, :Bearer, access_token
22
+ conn.request :json
23
+
24
+ conn.response :json
25
+
26
+ conn.adapter adapter, @stubs
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ module Vimeo
2
+ class Collection
3
+ attr_reader :data, :total, :next_page_token, :prev_page_token
4
+
5
+ def self.from_response(response, type:)
6
+ body = response.body
7
+
8
+ new(
9
+ data: body["items"].map { |attrs| type.new(attrs) },
10
+ total: body["pageInfo"]["totalResults"],
11
+ next_page_token: body["nextPageToken"],
12
+ prev_page_token: body["prevPageToken"],
13
+ # cursor: body.dig("pagination", "cursor")
14
+ )
15
+ end
16
+
17
+ def initialize(data:, total:, next_page_token:, prev_page_token:)
18
+ @data = data
19
+ @total = total
20
+ @next_page_token = next_page_token
21
+ @prev_page_token = prev_page_token
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module Vimeo
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ require "ostruct"
2
+
3
+ module Vimeo
4
+ class Object < OpenStruct
5
+ def initialize(attributes)
6
+ super to_ostruct(attributes)
7
+ end
8
+
9
+ def to_ostruct(obj)
10
+ if obj.is_a?(Hash)
11
+ OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
12
+ elsif obj.is_a?(Array)
13
+ obj.map { |o| to_ostruct(o) }
14
+ else # Assumed to be a primitive value
15
+ obj
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module Vimeo
2
+ class Video < Object
3
+
4
+ def initialize(options = {})
5
+ super options
6
+
7
+ self.id = options["uri"].gsub("/videos/", "")
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,56 @@
1
+ module Vimeo
2
+ class Resource
3
+ attr_reader :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ private
10
+
11
+ def get_request(url, params: {}, headers: {})
12
+ handle_response client.connection.get(url, params, headers)
13
+ end
14
+
15
+ def post_request(url, body:, headers: {})
16
+ handle_response client.connection.post(url, body, headers)
17
+ end
18
+
19
+ def patch_request(url, body:, headers: {})
20
+ handle_response client.connection.patch(url, body, headers)
21
+ end
22
+
23
+ def put_request(url, body:, headers: {})
24
+ handle_response client.connection.put(url, body, headers)
25
+ end
26
+
27
+ def delete_request(url, params: {}, headers: {})
28
+ handle_response client.connection.delete(url, params, headers)
29
+ end
30
+
31
+ def handle_response(response)
32
+ case response.status
33
+ when 400
34
+ raise Error, "Error 400: Your request was malformed. '#{response.body["error"]}'"
35
+ when 401
36
+ raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["error"]["message"]}'"
37
+ when 403
38
+ raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["error"]["message"]}'"
39
+ when 404
40
+ raise Error, "Error 404: No results were found for your request. '#{response.body["error"]["message"]}'"
41
+ when 409
42
+ raise Error, "Error 409: Your request was a conflict. '#{response.body["error"]["message"]}'"
43
+ when 429
44
+ raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["error"]["message"]}'"
45
+ when 500
46
+ raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["error"]["message"]}'"
47
+ when 503
48
+ raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["error"]["message"]}'"
49
+ when 204
50
+ return true
51
+ end
52
+
53
+ response
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,20 @@
1
+ module Vimeo
2
+ class VideosResource < Resource
3
+
4
+ def retrieve(id:)
5
+ response = get_request("videos/#{id}")
6
+ Video.new(response.body)
7
+ end
8
+
9
+ def edit(id:, **params)
10
+ response = patch_request("videos/#{id}", body: params)
11
+ Video.new(response.body)
12
+ end
13
+
14
+ def delete(id:)
15
+ response = delete_request("videos/#{id}")
16
+ return true if response.success
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Vimeo
2
+ VERSION = "0.1.1"
3
+ end
data/lib/vimeo.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "faraday"
2
+ require "json"
3
+
4
+ require_relative "vimeo/version"
5
+
6
+ module Vimeo
7
+
8
+ autoload :Client, "vimeo/client"
9
+ autoload :Collection, "vimeo/collection"
10
+ autoload :Error, "vimeo/error"
11
+ autoload :Resource, "vimeo/resource"
12
+ autoload :Object, "vimeo/object"
13
+
14
+ autoload :VideosResource, "vimeo/resources/videos"
15
+
16
+ autoload :Video, "vimeo/objects/video"
17
+
18
+ end
data/lib/vimeorb.rb ADDED
@@ -0,0 +1 @@
1
+ require "vimeo"
data/vimeorb.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/vimeo/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "vimeorb"
7
+ spec.version = Vimeo::VERSION
8
+ spec.authors = ["Dean Perry"]
9
+ spec.email = ["dean@deanpcmad.com"]
10
+
11
+ spec.summary = "A Ruby library for interacting with the Vimeo API"
12
+ spec.homepage = "https://deanpcmad.com"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/deanpcmad/vimeorb"
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "faraday", "~> 2.0"
32
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vimeorb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dean Perry
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description:
28
+ email:
29
+ - dean@deanpcmad.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".env.example"
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/console
41
+ - bin/setup
42
+ - lib/vimeo.rb
43
+ - lib/vimeo/client.rb
44
+ - lib/vimeo/collection.rb
45
+ - lib/vimeo/error.rb
46
+ - lib/vimeo/object.rb
47
+ - lib/vimeo/objects/video.rb
48
+ - lib/vimeo/resource.rb
49
+ - lib/vimeo/resources/videos.rb
50
+ - lib/vimeo/version.rb
51
+ - lib/vimeorb.rb
52
+ - vimeorb.gemspec
53
+ homepage: https://deanpcmad.com
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ homepage_uri: https://deanpcmad.com
58
+ source_code_uri: https://github.com/deanpcmad/vimeorb
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 2.6.0
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.2.22
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: A Ruby library for interacting with the Vimeo API
78
+ test_files: []