slainer68-easy-vimeo 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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 slainer68
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,10 @@
1
+ = easy-vimeo
2
+
3
+ EasyVimeo aims to be a very easy and Ruby-like wrapper around Vimeo API.
4
+
5
+ More to come.
6
+
7
+ == Copyright
8
+
9
+ Copyright (c) 2009 Novelys & Promopixel. See LICENSE for details.
10
+ Written by Nicolas Blanco.
data/Rakefile ADDED
@@ -0,0 +1,65 @@
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 = %Q{TODO}
9
+ gem.email = "slainer68@gmail.com"
10
+ gem.homepage = "http://github.com/slainer68/easy-vimeo"
11
+ gem.authors = ["slainer68"]
12
+
13
+ if gem.respond_to? :specification_version then
14
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
15
+ gem.specification_version = 3
16
+
17
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
18
+ gem.add_runtime_dependency(%q<slainer68-vimeo>, [">= 0.2.3"])
19
+ gem.add_runtime_dependency(%q<curb>, [">= 0.3.2"])
20
+ else
21
+ gem.add_dependency(%q<slainer68-vimeo>, [">= 0.2.3"])
22
+ gem.add_dependency(%q<curb>, [">= 0.3.2"])
23
+ end
24
+ else
25
+ gem.add_dependency(%q<slainer68-vimeo>, [">= 0.2.3"])
26
+ gem.add_dependency(%q<curb>, [">= 0.3.2"])
27
+ end
28
+
29
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
30
+ end
31
+
32
+ rescue LoadError
33
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
34
+ end
35
+
36
+ require 'spec/rake/spectask'
37
+ Spec::Rake::SpecTask.new(:spec) do |spec|
38
+ spec.libs << 'lib' << 'spec'
39
+ spec.spec_files = FileList['spec/**/*_spec.rb']
40
+ end
41
+
42
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
43
+ spec.libs << 'lib' << 'spec'
44
+ spec.pattern = 'spec/**/*_spec.rb'
45
+ spec.rcov = true
46
+ end
47
+
48
+
49
+ task :default => :spec
50
+
51
+ require 'rake/rdoctask'
52
+ Rake::RDocTask.new do |rdoc|
53
+ if File.exist?('VERSION.yml')
54
+ config = YAML.load(File.read('VERSION.yml'))
55
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
56
+ else
57
+ version = ""
58
+ end
59
+
60
+ rdoc.rdoc_dir = 'rdoc'
61
+ rdoc.title = "easy-vimeo #{version}"
62
+ rdoc.rdoc_files.include('README*')
63
+ rdoc.rdoc_files.include('lib/**/*.rb')
64
+ end
65
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,53 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{easy-vimeo}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["slainer68"]
9
+ s.date = %q{2009-05-07}
10
+ s.email = %q{slainer68@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "easy-vimeo.gemspec",
23
+ "lib/easy-vimeo.rb",
24
+ "spec/easy-vimeo_spec.rb",
25
+ "spec/spec_helper.rb"
26
+ ]
27
+ s.has_rdoc = true
28
+ s.homepage = %q{http://github.com/slainer68/easy-vimeo}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.2}
32
+ s.summary = %q{TODO}
33
+ s.test_files = [
34
+ "spec/easy-vimeo_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<slainer68-vimeo>, [">= 0.2.3"])
44
+ s.add_runtime_dependency(%q<curb>, [">= 0.3.2"])
45
+ else
46
+ s.add_dependency(%q<slainer68-vimeo>, [">= 0.2.3"])
47
+ s.add_dependency(%q<curb>, [">= 0.3.2"])
48
+ end
49
+ else
50
+ s.add_dependency(%q<slainer68-vimeo>, [">= 0.2.3"])
51
+ s.add_dependency(%q<curb>, [">= 0.3.2"])
52
+ end
53
+ end
data/lib/easy-vimeo.rb ADDED
@@ -0,0 +1,139 @@
1
+ require "vimeo"
2
+ require "curb"
3
+
4
+ module Vimeo
5
+ class Easy
6
+
7
+ UPLOAD_URL = "http://vimeo.com/services/upload"
8
+ PRIVACY_MODES = [:anybody, :contacts, :nobody, :users]
9
+
10
+ private
11
+ attr_writer :thumbnail
12
+
13
+ public
14
+ attr_accessor :vimeo_upload, :api_key, :auth_token, :ticket_id, :vimeo_video, :video_id, :caption, :title, :file
15
+ attr_reader :privacy, :thumbnail, :tags
16
+
17
+ # This method initializes a new instance.
18
+ # You should pass an options Hash containing :
19
+ # :api_key # The API key of your account
20
+ # :secret_key # The secret key
21
+ # :auth_token # (optional) The authorization token, needed to upload a video
22
+ # :video_id # (optional) The ID of the video, if it is already uploaded
23
+ #
24
+ def initialize(options = {})
25
+ raise "You must pass :api_key and :secret_key at least to initialize the class." unless options[:api_key] && options[:secret_key]
26
+ self.api_key = options[:api_key]
27
+ self.auth_token = options[:auth_token]
28
+ self.video_id = options[:video_id]
29
+ self.vimeo_upload = Vimeo::Advanced::Upload.new(self.api_key, options[:secret_key])
30
+ self.vimeo_video = Vimeo::Advanced::Video.new(self.api_key, options[:secret_key])
31
+ self.privacy = :anybody
32
+ @new_record = true
33
+
34
+ if self.video_id
35
+ self.reload
36
+ end
37
+ end
38
+
39
+ def new_record?
40
+ @new_record
41
+ end
42
+
43
+ def tags=(tags)
44
+ 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
45
+ @tags = @new_tags = tags
46
+ end
47
+
48
+ def privacy=(mode)
49
+ raise "Privacy mode not allowed, should be one of : #{PRIVACY_MODES.join(', ')}." unless PRIVACY_MODES.include?(mode)
50
+ @privacy = mode
51
+ end
52
+
53
+ # This method destroys the Vimeo Video
54
+ #
55
+ def destroy
56
+ check_video_and_token
57
+
58
+ self.vimeo_video.delete(self.video_id, self.auth_token)
59
+ true
60
+ rescue
61
+ false
62
+ end
63
+
64
+ def available?
65
+ !!@availability
66
+ end
67
+
68
+ def reload
69
+ check_video_and_token
70
+
71
+ video_response = self.vimeo_video.get_info(self.video_id)['rsp']['video']
72
+ self.title = video_response['title']
73
+ self.caption = video_response['caption']
74
+ self.privacy = video_response['privacy'].to_sym
75
+ self.thumbnail = (video_response['thumbnails']['thumbnail'].first rescue nil)
76
+ @tags = (video_response['tags']['tag'].join(', ') rescue nil)
77
+ @availability = video_response['is_transcoding'].to_i.zero? && video_response['is_uploading'].to_i.zero?
78
+ @new_record = false
79
+
80
+ true
81
+ rescue
82
+ false
83
+ end
84
+
85
+ def save
86
+ if self.file
87
+ raise "Cannot upload a video file on an existing video! Create a new instance instead." unless new_record?
88
+ post_video! if self.file
89
+ end
90
+ check_video_and_token
91
+
92
+ begin
93
+ self.vimeo_video.set_privacy(self.video_id, self.privacy.to_s, self.auth_token)
94
+ self.vimeo_video.set_caption(self.video_id, self.caption, self.auth_token) if self.caption
95
+ self.vimeo_video.set_title(self.video_id, self.title, self.auth_token) if self.title
96
+ if @new_tags
97
+ self.vimeo_video.clear_tags(self.video_id, self.auth_token)
98
+ self.vimeo_video.add_tags(self.video_id, self.tags, self.auth_token)
99
+ @new_tags = nil
100
+ end
101
+ rescue
102
+ return false
103
+ end
104
+
105
+ @new_record = false
106
+ @file = nil
107
+ true
108
+ end
109
+
110
+ private
111
+ def check_video_and_token
112
+ raise "You must set video_id and auth_token to use this method." unless self.video_id && self.auth_token
113
+ end
114
+
115
+
116
+ # This method post a new video
117
+ # The parameter is the video filename
118
+ # After uploading, the video_id is set to the id of the new uploaded video
119
+ #
120
+ def post_video!
121
+ raise "You must set auth_token to use this method." unless self.auth_token
122
+ raise "File does not exist (#{self.file})." unless File.exists?(self.file)
123
+
124
+ self.ticket_id = self.vimeo_upload.get_upload_ticket(self.auth_token)["rsp"]["ticket"]["id"]
125
+
126
+ curl = Curl::Easy.new(UPLOAD_URL)
127
+ curl.multipart_form_post = true
128
+ curl.http_post(Curl::PostField.file('video', self.file),
129
+ Curl::PostField.content('api_key', self.api_key),
130
+ Curl::PostField.content('auth_token', self.auth_token),
131
+ Curl::PostField.content('ticket_id', self.ticket_id),
132
+ Curl::PostField.content('api_sig', self.vimeo_upload.signature_for_file_upload(self.ticket_id, self.auth_token))
133
+ )
134
+ self.video_id = self.vimeo_upload.check_upload_status(self.ticket_id, self.auth_token)["rsp"]["ticket"]["video_id"]
135
+ rescue # FIXME : that's bad to rescue all exceptions, but for now, throw false.
136
+ false
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "EasyVimeo" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'easy-vimeo'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slainer68-easy-vimeo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - slainer68
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-07 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: slainer68-vimeo
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: curb
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.2
34
+ version:
35
+ description:
36
+ email: slainer68@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
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
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.2.0
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: TODO
81
+ test_files:
82
+ - spec/easy-vimeo_spec.rb
83
+ - spec/spec_helper.rb