vimeo_upload 0.1.0

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
+ SHA1:
3
+ metadata.gz: a1e964663fc228cea9ae9bbdb43bfdfeaf0a03c8
4
+ data.tar.gz: a733552aaef26597c52c2c19cb4195a9ab6aedd8
5
+ SHA512:
6
+ metadata.gz: c2891425219e5bd3cacc10f3285c1c3422213eed3b7dc57d41ab3cfa72e17c05073944a00706682237f8b396daf4a6ae20b03061da49d39169fc4a4b1f454ea6
7
+ data.tar.gz: 4295b99d82167605de74e66cf671a72c39fa0d7933766897745d9e580a223849bdd06babcb1118e42d85c9d58f197970a0c03172f1c3a3f469dacabe64a15f68
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vimeo_upload.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 sajinmp
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,61 @@
1
+ # VimeoUpload
2
+
3
+ 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_upload`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vimeo_upload'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vimeo_upload
22
+
23
+ ## Usage
24
+
25
+ Require the gem
26
+
27
+ ```ruby
28
+ require 'vimeo_upload'
29
+ ```
30
+
31
+ ## Uploading a video
32
+
33
+ ```ruby
34
+ VimeoUpload.upload('absolute_filepath', 'filename', 'api_key')
35
+ ```
36
+
37
+ eg: VimeoUpload.upload("#{Rails.root}/public/uploads/video.webm", 'My Video', ENV['api_key'])
38
+
39
+ ## Changing video title
40
+
41
+ ```ruby
42
+ VimeoUpload.change_title('filename', 'video_id', 'api_key')
43
+ ```
44
+
45
+ eg: VimeoUpload.upload("'My Video', '123456789', ENV['api_key'])")
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sajinmp/vimeo_upload.
56
+
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
61
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vimeo_upload"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
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,114 @@
1
+ require "vimeo_upload/version"
2
+ require "httparty"
3
+
4
+ module VimeoUpload
5
+
6
+ # Upload function
7
+ def self.upload(filepath, filename, api_key)
8
+
9
+ # Upload a video to vimeo
10
+ # I prefer putting api_key as an environment variable. Use figaro gem if needed
11
+ # Call function in the following format
12
+ # VimeoUpload.upload(absolute_filepath, filename, vimeo_key)
13
+ # eg;
14
+ # VimeoUpload.upload("#{Rails.root}/public/uploads/video.webm", 'My Video', ENV['api_key'])
15
+ # Return a video_id that references to the video
16
+
17
+ auth = "bearer #{api_key}"
18
+
19
+ # create ticket
20
+ resp = HTTParty.post "https://api.vimeo.com/me/videos",
21
+ headers: {"Authorization" => auth,
22
+ "Accept" => "application/vnd.vimeo.*+json;version=3.2"},
23
+ body: {type: "streaming"}
24
+
25
+ ticket = JSON.parse(resp.body)
26
+ if resp.body['error']
27
+ raise StandardError, ticket['error']
28
+ end
29
+ target = ticket["upload_link_secure"]
30
+ size = File.size(filepath)
31
+ last_byte = 0
32
+ # create ticket end
33
+
34
+ # upload video
35
+ File.open(filepath, "rb") do |f|
36
+ uri = URI(target)
37
+ while last_byte < size do
38
+ req = Net::HTTP::Put.new("#{uri.path}?#{uri.query}", initheader = {"Authorization" => auth, "Content-Type" => "video/mp4", "Content-Length" => size.to_s})
39
+ req.body = f.read
40
+
41
+ begin
42
+ http=Net::HTTP.new(uri.host, uri.port)
43
+ http.use_ssl=true
44
+ response = http.request(req)
45
+
46
+ rescue Errno::EPIPE
47
+ puts "Error occured"
48
+ end
49
+
50
+ progress_resp = HTTParty.put target, headers: {"Content-Range" => 'bytes */*', "Authorization" => auth}
51
+ last_byte = progress_resp.headers["range"].split("-").last.to_i
52
+ end
53
+ end
54
+ # upload video end
55
+
56
+ # delete ticket (required to view video in vimeo)
57
+ complete_uri=ticket["complete_uri"]
58
+
59
+ uri = URI("https://api.vimeo.com" + complete_uri)
60
+ delete_req = Net::HTTP::Delete.new("#{uri.path}?#{uri.query}", initheader = {"Authorization" => auth})
61
+
62
+ begin
63
+ http=Net::HTTP.new(uri.host, uri.port)
64
+ http.use_ssl=true
65
+ delete_resp = http.request(delete_req)
66
+
67
+ rescue Errno::EPIPE
68
+ puts "Error occured"
69
+ end
70
+
71
+ video_location = delete_resp["location"]
72
+ # delete ticket end
73
+
74
+ video_id = video_location.split('/')[2]
75
+
76
+ # change title
77
+ change_title(filename, video_id, api_key)
78
+
79
+ return video_id
80
+ end
81
+
82
+
83
+ # Change video title
84
+ def self.change_title(filename, video_id, api_key)
85
+
86
+ # Change video title of a video in vimeo
87
+ # I prefer putting api_key as an environment variable. Use figaro gem if needed
88
+ # Call function in the following format
89
+ # VimeoUpload.change_title(filename, video_id, vimeo_key)
90
+ # eg;
91
+ # VimeoUpload.upload("'My Video', '123456789', ENV['api_key'])
92
+ # Returns the video_id
93
+
94
+ auth = "bearer #{api_key}"
95
+
96
+ uri = URI("https://api.vimeo.com/videos/#{video_id}")
97
+
98
+ patch_req = Net::HTTP::Patch.new("#{uri.path}?#{uri.query}", initheader = {"Authorization" => auth, "name" => "Test"})
99
+ patch_req.set_form_data({"name" => filename})
100
+
101
+
102
+ begin
103
+ http=Net::HTTP.new(uri.host, uri.port)
104
+ http.use_ssl=true
105
+ patch_resp = http.request(patch_req)
106
+
107
+ rescue Errno::EPIPE
108
+ puts "Error occured"
109
+ end
110
+
111
+ return video_id
112
+ end
113
+
114
+ end
@@ -0,0 +1,3 @@
1
+ module VimeoUpload
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vimeo_upload/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vimeo_upload"
8
+ spec.version = VimeoUpload::VERSION
9
+ spec.authors = ["Sajin M Prasad"]
10
+ spec.email = ["sajinprasadkm@gmail.com"]
11
+
12
+ spec.summary = %q{Upload a video to vimeo}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.12"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_dependency "httparty", "~> 0.13"
27
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vimeo_upload
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sajin M Prasad
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.13'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.13'
55
+ description:
56
+ email:
57
+ - sajinprasadkm@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/vimeo_upload.rb
70
+ - lib/vimeo_upload/version.rb
71
+ - vimeo_upload.gemspec
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.5.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Upload a video to vimeo
96
+ test_files: []