easy-vimeo 0.3.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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright © 2009 Novelys & Promopixel.
2
+
3
+ Written by Nicolas Blanco.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ h1. EasyVimeo
2
+
3
+ EasyVimeo aims to be a very easy and Ruby wrapper around the Vimeo API.
4
+
5
+ With EasyVimeo, you can upload a video file to the Vimeo website and set its basic properties in a few lines of code.
6
+
7
+ h1. What's new ?
8
+
9
+ 0.3.0 : updates to new Ruby Vimeo API with some cleanup. We don't need curl anymore because the Ruby Vimeo API now uses HTTPClient to upload.
10
+
11
+ h1. Example
12
+
13
+ h2. Send a video in just a few lines of code...
14
+
15
+ <pre>
16
+ <code>
17
+ v = Vimeo::Easy.new :api_key => VIMEO_API_KEY, :secret_key => VIMEO_SECRET_KEY, :auth_token => VIMEO_AUTH_TOKEN
18
+ v.title = "Ma great video"
19
+ v.description = "Great cool video"
20
+ v.tags = "youpi, super, cool"
21
+ v.privacy = :anybody
22
+
23
+ v.file = "/Users/nicolas/test.mov"
24
+ v.save
25
+ </code>
26
+ </pre>
27
+
28
+ h2. Or just get the attributes from an existing video...
29
+
30
+ <pre>
31
+ <code>
32
+ v = Vimeo::Easy.find 2052244, :api_key => VIMEO_API_KEY, :secret_key => VIMEO_SECRET_KEY
33
+ </code>
34
+ </pre>
35
+
36
+ h2. Other interesting methods...
37
+
38
+ <pre>
39
+ <code>
40
+ v.available? # => returns true if the video is currenly available on Vimeo (uploaded & transcoded)
41
+ v.destroy # => destroy the video
42
+ v.reload # => reload the attributes
43
+ </code>
44
+ </pre>
45
+
46
+ h1. TODO
47
+
48
+ Add some error management.
49
+
50
+ And that's all for now ;). Thanks!
51
+
52
+ h1. Copyright
53
+
54
+ Copyright (c) 2009 Novelys & Promopixel. See LICENSE for details.
55
+
56
+ Written by Nicolas Blanco.
@@ -0,0 +1,66 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "easy-vimeo"
8
+ gem.summary = "EasyVimeo is an object wrapper around the Ruby Vimeo API to easily upload videos to Vimeo.com"
9
+ gem.description = "EasyVimeo is an object wrapper around the Ruby Vimeo API to easily upload videos to Vimeo.com"
10
+ gem.email = "slainer68@gmail.com"
11
+ gem.homepage = "http://github.com/slainer68/easy-vimeo"
12
+ gem.authors = ["slainer68"]
13
+
14
+ if gem.respond_to? :specification_version then
15
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
16
+ gem.specification_version = 3
17
+
18
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
19
+ gem.add_runtime_dependency(%q<vimeo>, [">= 1.0.0"])
20
+ gem.add_runtime_dependency(%q<httpclient>, [">= 2.1.5"])
21
+ else
22
+ gem.add_dependency(%q<vimeo>, [">= 1.0.0"])
23
+ gem.add_dependency(%q<httpclient>, [">= 2.1.5"])
24
+ end
25
+ else
26
+ gem.add_dependency(%q<vimeo>, [">= 1.0.0"])
27
+ gem.add_dependency(%q<httpclient>, [">= 2.1.5"])
28
+ end
29
+
30
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
31
+ end
32
+
33
+ rescue LoadError
34
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
35
+ end
36
+
37
+ require 'spec/rake/spectask'
38
+ Spec::Rake::SpecTask.new(:spec) do |spec|
39
+ spec.libs << 'lib' << 'spec'
40
+ spec.spec_files = FileList['spec/**/*_spec.rb']
41
+ end
42
+
43
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
44
+ spec.libs << 'lib' << 'spec'
45
+ spec.pattern = 'spec/**/*_spec.rb'
46
+ spec.rcov = true
47
+ end
48
+
49
+
50
+ task :default => :spec
51
+
52
+ require 'rake/rdoctask'
53
+ Rake::RDocTask.new do |rdoc|
54
+ if File.exist?('VERSION.yml')
55
+ config = YAML.load(File.read('VERSION.yml'))
56
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
57
+ else
58
+ version = ""
59
+ end
60
+
61
+ rdoc.rdoc_dir = 'rdoc'
62
+ rdoc.title = "easy-vimeo #{version}"
63
+ rdoc.rdoc_files.include('README*')
64
+ rdoc.rdoc_files.include('lib/**/*.rb')
65
+ end
66
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{easy-vimeo}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["slainer68"]
12
+ s.date = %q{2009-12-08}
13
+ s.description = %q{EasyVimeo is an object wrapper around the Ruby Vimeo API to easily upload videos to Vimeo.com}
14
+ s.email = %q{slainer68@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.textile",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "easy-vimeo.gemspec",
27
+ "lib/easy-vimeo.rb",
28
+ "spec/easy-vimeo_spec.rb",
29
+ "spec/spec_helper.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/slainer68/easy-vimeo}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{EasyVimeo is an object wrapper around the Ruby Vimeo API to easily upload videos to Vimeo.com}
36
+ s.test_files = [
37
+ "spec/easy-vimeo_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<vimeo>, [">= 1.0.0"])
47
+ s.add_runtime_dependency(%q<httpclient>, [">= 2.1.5"])
48
+ else
49
+ s.add_dependency(%q<vimeo>, [">= 1.0.0"])
50
+ s.add_dependency(%q<httpclient>, [">= 2.1.5"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<vimeo>, [">= 1.0.0"])
54
+ s.add_dependency(%q<httpclient>, [">= 2.1.5"])
55
+ end
56
+ end
@@ -0,0 +1,141 @@
1
+ require "vimeo"
2
+
3
+ module Vimeo
4
+ class Easy
5
+
6
+ UPLOAD_URL = "http://vimeo.com/services/upload"
7
+ PRIVACY_MODES = [:anybody, :contacts, :nobody, :users]
8
+
9
+ private
10
+ attr_writer :thumbnail
11
+
12
+ public
13
+ attr_accessor :vimeo_upload, :api_key, :auth_token, :vimeo_video, :video_id, :description, :title, :file
14
+ attr_reader :privacy, :thumbnail, :tags
15
+
16
+ # This method initializes a new instance.
17
+ # You should pass an options Hash containing :
18
+ # :api_key # The API key of your account
19
+ # :secret_key # The secret key
20
+ # :auth_token # (optional) The authorization token, needed to upload a video
21
+ # :video_id # (optional) The ID of the video, if it is already uploaded
22
+ #
23
+ def initialize(options = {})
24
+ raise "You must pass :api_key and :secret_key at least to initialize the class." unless options[:api_key] && options[:secret_key]
25
+ self.api_key = options[:api_key]
26
+ self.auth_token = options[:auth_token]
27
+ self.video_id = options[:video_id]
28
+ self.vimeo_upload = Vimeo::Advanced::Upload.new(self.api_key, options[:secret_key])
29
+ self.vimeo_video = Vimeo::Advanced::Video.new(self.api_key, options[:secret_key])
30
+ self.privacy = :anybody
31
+ @new_record = true
32
+
33
+ if self.video_id
34
+ self.reload
35
+ end
36
+ end
37
+
38
+ def self.find(video_id, options = {})
39
+ self.new(options.merge(:video_id => video_id))
40
+ end
41
+
42
+ def new_record?
43
+ @new_record
44
+ end
45
+
46
+ def tags=(tags)
47
+ return tags if self.tags && tags.split(',').map(&:strip).sort == self.tags.split(',').map(&:strip).sort # Do not change attributes if the tags are the same
48
+ @tags = @new_tags = tags
49
+ end
50
+
51
+ def privacy=(mode)
52
+ raise "Privacy mode not allowed, should be one of : #{PRIVACY_MODES.join(', ')}." unless PRIVACY_MODES.include?(mode)
53
+ @privacy = mode
54
+ end
55
+
56
+ # This method destroys the Vimeo Video
57
+ #
58
+ def destroy
59
+ check_presence_of :video_id, :auth_token
60
+
61
+ self.vimeo_video.delete(self.auth_token, self.video_id)
62
+ true
63
+ rescue
64
+ false
65
+ end
66
+
67
+ def available?
68
+ !!@availability
69
+ end
70
+
71
+ def reload
72
+ check_presence_of :video_id
73
+
74
+ begin
75
+ video_response = self.vimeo_video.get_info(self.video_id)['video'][0]
76
+ self.title = video_response['title']
77
+ self.description = video_response['description']
78
+ self.privacy = video_response['privacy'].to_sym
79
+ self.thumbnail = (video_response['thumbnails']['thumbnail'].first rescue nil)
80
+ @tags = (video_response['tags']['tag'].join(', ') rescue nil)
81
+ @availability = video_response['is_transcoding'].to_i.zero? && video_response['is_uploading'].to_i.zero?
82
+ @new_record = false
83
+
84
+ true
85
+ rescue
86
+ false
87
+ end
88
+ end
89
+
90
+ def save
91
+ if self.file
92
+ raise "Cannot upload a video file on an existing video! Create a new instance instead." unless new_record?
93
+ post_video!
94
+ end
95
+ check_presence_of :video_id, :auth_token
96
+
97
+ begin
98
+ self.vimeo_video.set_privacy(self.auth_token, self.video_id, self.privacy.to_s)
99
+ self.vimeo_video.set_description(self.auth_token, self.video_id, self.description) if self.description
100
+ self.vimeo_video.set_title(self.auth_token, self.video_id, self.title) if self.title
101
+ if @new_tags
102
+ self.vimeo_video.clear_tags(self.auth_token, self.video_id)
103
+ self.vimeo_video.add_tags(self.auth_token, self.video_id, self.tags)
104
+ @new_tags = nil
105
+ end
106
+ rescue
107
+ return false
108
+ end
109
+
110
+ @new_record = false
111
+ @file = nil
112
+ true
113
+ end
114
+
115
+ private
116
+ def check_presence_of(*attributes)
117
+ raise "You must set #{attributes.join(' and ')} to use this method." unless attributes.all? { |a| self.send(a) != nil }
118
+ end
119
+
120
+ # This method post a new video
121
+ # The parameter is the video filename
122
+ # After uploading, the video_id is set to the id of the new uploaded video
123
+ #
124
+ def post_video!
125
+ raise "You must set auth_token to use this method." unless self.auth_token
126
+ raise "File does not exist (#{self.file})." unless File.exists?(self.file)
127
+
128
+ ticket = self.vimeo_upload.get_ticket(self.auth_token)["ticket"]
129
+ ticket_id = ticket["id"]
130
+
131
+ end_point = ticket["endpoint"]
132
+ json_manifest = self.vimeo_upload.upload(self.auth_token, self.file, ticket_id, end_point)
133
+
134
+ request_confirm = self.vimeo_upload.confirm(self.auth_token, ticket_id, json_manifest)
135
+
136
+ self.video_id = request_confirm["ticket"]["video_id"]
137
+ rescue # FIXME : that's bad to rescue all exceptions, but for now, throw false.
138
+ false
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,114 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ VIDEO_RESPONSE_HASH = { 'video' => [{ 'title' => 'Ma video', 'description' => 'Great description', 'caption' => 'Great caption', 'privacy' => 'nobody', 'thumbnails' => { 'thumbnail' => ['http://first_thumb.jpg'] }, 'tags' => { 'tag' => ['cool', 'great'] }, 'is_transcoding' => '0', 'is_uploading' => '0' }] }
4
+
5
+ describe "EasyVimeo" do
6
+
7
+ def video_init(options = {})
8
+ @api_key = "pipo"
9
+ @secret_key = "molo"
10
+ @video = Vimeo::Easy.new :api_key => @api_key, :secret_key => @secret_key, :auth_token => options[:auth_token]
11
+ end
12
+
13
+ def video_load
14
+ @video.vimeo_video.should_receive(:get_info).and_return(VIDEO_RESPONSE_HASH)
15
+ @video.video_id = 9999999
16
+ @video.reload
17
+ end
18
+
19
+ it "should not initialize without secret_key & api_key" do
20
+ lambda { Vimeo::Easy.new }.should raise_error
21
+ end
22
+
23
+ it "should initialize with secret_key & api_key and set default attributes" do
24
+ video_init
25
+
26
+ @video.api_key.should == @api_key
27
+ @video.privacy.should == :anybody
28
+
29
+ @video.vimeo_upload.should be_a(Vimeo::Advanced::Upload)
30
+ @video.vimeo_video.should be_a(Vimeo::Advanced::Video)
31
+
32
+ @video.should be_new_record
33
+ end
34
+
35
+ it "should not accept bad privacy type" do
36
+ video_init
37
+
38
+ lambda { @video.privacy = :pipo }.should raise_error
39
+ end
40
+
41
+ it "should not reload the video without video_id" do
42
+ video_init
43
+
44
+ lambda { @video.reload }.should raise_error
45
+ end
46
+
47
+ it "should reload the video with video_id" do
48
+ video_init
49
+ video_load
50
+
51
+ @video.title.should == 'Ma video'
52
+ @video.description.should == 'Great description'
53
+ @video.privacy.should == :nobody
54
+ @video.tags.should == 'cool, great'
55
+ @video.thumbnail.should == 'http://first_thumb.jpg'
56
+
57
+ @video.should be_available
58
+ @video.should_not be_new_record
59
+ end
60
+
61
+ it "should not be able to save with a file if video is already uploaded" do
62
+ video_init(:auth_token => "pipo")
63
+ video_load
64
+
65
+ @video.file = '/tmp/pipo'
66
+ lambda { @video.save }.should raise_error
67
+ end
68
+
69
+ it 'should not be able to save a video without auth_token or video_id' do
70
+ video_init
71
+ video_load
72
+
73
+ lambda { @video.save }.should raise_error
74
+
75
+ video_init(:auth_token => "pipo")
76
+ lambda { @video.save }.should raise_error
77
+ end
78
+
79
+ it 'should be able to save a video' do
80
+ video_init(:auth_token => "pipo")
81
+ video_load
82
+
83
+ @video.vimeo_video.should_receive(:set_privacy).and_return(true)
84
+ @video.vimeo_video.should_receive(:set_description).and_return(true)
85
+ @video.vimeo_video.should_receive(:set_title).and_return(true)
86
+
87
+ @video.save.should == true
88
+ end
89
+
90
+ it 'should be able to save a video with a file' do
91
+ video_init(:auth_token => "pipo")
92
+
93
+ @video.file = '/tmp/pipo'
94
+
95
+ File.should_receive(:exists?).with('/tmp/pipo').and_return(true)
96
+ @video.vimeo_upload.should_receive(:get_ticket).and_return({ "ticket" => { "id" => "123456", "endpoint" => "654321" } })
97
+ @video.vimeo_upload.should_receive(:upload).with("pipo", "/tmp/pipo", "123456", "654321").and_return("MD5")
98
+
99
+ @video.vimeo_upload.should_receive(:confirm).with("pipo", "123456", "MD5").and_return({ "ticket" => { "video_id" => "99999" } })
100
+
101
+ @video.vimeo_video.should_receive(:set_privacy).and_return(true)
102
+ @video.vimeo_video.should_not_receive(:set_description)
103
+ @video.vimeo_video.should_not_receive(:set_title)
104
+
105
+ @video.save.should == true
106
+ @video.video_id.should == "99999"
107
+ @video.should_not be_new_record
108
+ end
109
+
110
+ it 'should be able to find a video with a Vimeo ID' do
111
+ Vimeo::Easy.should_receive(:new).with(:toto => "pipo", :video_id => 123456).and_return(true)
112
+ Vimeo::Easy.find(123456, :toto => "pipo")
113
+ end
114
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require "rubygems"
6
+ require 'easy-vimeo'
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy-vimeo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - slainer68
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-08 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: vimeo
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: httpclient
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.5
34
+ version:
35
+ description: EasyVimeo is an object wrapper around the Ruby Vimeo API to easily upload videos to Vimeo.com
36
+ email: slainer68@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.textile
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.textile
49
+ - Rakefile
50
+ - VERSION
51
+ - easy-vimeo.gemspec
52
+ - lib/easy-vimeo.rb
53
+ - spec/easy-vimeo_spec.rb
54
+ - spec/spec_helper.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/slainer68/easy-vimeo
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.3.5
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: EasyVimeo is an object wrapper around the Ruby Vimeo API to easily upload videos to Vimeo.com
83
+ test_files:
84
+ - spec/easy-vimeo_spec.rb
85
+ - spec/spec_helper.rb