slainer68-easy-vimeo 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2009 slainer68
1
+ Copyright © 2009 Novelys & Promopixel.
2
+
3
+ Written by Nicolas Blanco.
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
data/README.textile ADDED
@@ -0,0 +1,48 @@
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. Example
8
+
9
+ h2. Send a video in just a few lines of code...
10
+
11
+ <pre>
12
+ <code>
13
+ v = Vimeo::Easy.new :api_key => VIMEO_API_KEY, :secret_key => VIMEO_SECRET_KEY, :auth_token => VIMEO_AUTH_TOKEN
14
+ v.title = "Ma great video"
15
+ v.caption = "Great cool video"
16
+ v.tags = "youpi, super, cool"
17
+ v.privacy = :anybody
18
+
19
+ v.file = "/Users/nicolas/test.mov"
20
+ v.save
21
+ </code>
22
+ </pre>
23
+
24
+ h2. Or just get the attributes from an existing video...
25
+
26
+ <pre>
27
+ <code>
28
+ v = Vimeo::Easy.find 2052244, :api_key => VIMEO_API_KEY, :secret_key => VIMEO_SECRET_KEY
29
+ </code>
30
+ </pre>
31
+
32
+ h2. Other interesting methods...
33
+
34
+ <pre>
35
+ <code>
36
+ v.available? # => returns true if the video is currenly available on Vimeo (uploaded & transcoded)
37
+ v.destroy # => destroy the video
38
+ v.reload # => reload the attributes
39
+ </code>
40
+ </pre>
41
+
42
+ And that's all for now ;). Thanks!
43
+
44
+ h1. Copyright
45
+
46
+ Copyright (c) 2009 Novelys & Promopixel. See LICENSE for details.
47
+
48
+ Written by Nicolas Blanco.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/easy-vimeo.gemspec CHANGED
@@ -2,21 +2,21 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{easy-vimeo}
5
- s.version = "0.1.0"
5
+ s.version = "0.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["slainer68"]
9
- s.date = %q{2009-05-07}
9
+ s.date = %q{2009-05-11}
10
10
  s.email = %q{slainer68@gmail.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
13
- "README.rdoc"
13
+ "README.textile"
14
14
  ]
15
15
  s.files = [
16
16
  ".document",
17
17
  ".gitignore",
18
18
  "LICENSE",
19
- "README.rdoc",
19
+ "README.textile",
20
20
  "Rakefile",
21
21
  "VERSION",
22
22
  "easy-vimeo.gemspec",
data/lib/easy-vimeo.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "rubygems"
1
2
  require "vimeo"
2
3
  require "curb"
3
4
 
@@ -36,6 +37,10 @@ module Vimeo
36
37
  end
37
38
  end
38
39
 
40
+ def self.find(video_id, options = {})
41
+ self.new(options.merge(:video_id => video_id))
42
+ end
43
+
39
44
  def new_record?
40
45
  @new_record
41
46
  end
@@ -53,7 +58,7 @@ module Vimeo
53
58
  # This method destroys the Vimeo Video
54
59
  #
55
60
  def destroy
56
- check_video_and_token
61
+ check_presence_of :video_id, :auth_token
57
62
 
58
63
  self.vimeo_video.delete(self.video_id, self.auth_token)
59
64
  true
@@ -66,28 +71,30 @@ module Vimeo
66
71
  end
67
72
 
68
73
  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
74
+ check_presence_of :video_id
75
+
76
+ begin
77
+ video_response = self.vimeo_video.get_info(self.video_id)['rsp']['video']
78
+ self.title = video_response['title']
79
+ self.caption = video_response['caption']
80
+ self.privacy = video_response['privacy'].to_sym
81
+ self.thumbnail = (video_response['thumbnails']['thumbnail'].first rescue nil)
82
+ @tags = (video_response['tags']['tag'].join(', ') rescue nil)
83
+ @availability = video_response['is_transcoding'].to_i.zero? && video_response['is_uploading'].to_i.zero?
84
+ @new_record = false
85
+
86
+ true
87
+ rescue
88
+ false
89
+ end
83
90
  end
84
91
 
85
92
  def save
86
93
  if self.file
87
94
  raise "Cannot upload a video file on an existing video! Create a new instance instead." unless new_record?
88
- post_video! if self.file
95
+ post_video!
89
96
  end
90
- check_video_and_token
97
+ check_presence_of :video_id, :auth_token
91
98
 
92
99
  begin
93
100
  self.vimeo_video.set_privacy(self.video_id, self.privacy.to_s, self.auth_token)
@@ -108,8 +115,8 @@ module Vimeo
108
115
  end
109
116
 
110
117
  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
118
+ def check_presence_of(*attributes)
119
+ raise "You must set #{attributes.join(' and ')} to use this method." unless attributes.all? { |a| self.send(a) != nil }
113
120
  end
114
121
 
115
122
 
@@ -132,8 +139,8 @@ module Vimeo
132
139
  Curl::PostField.content('api_sig', self.vimeo_upload.signature_for_file_upload(self.ticket_id, self.auth_token))
133
140
  )
134
141
  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
142
+ #rescue # FIXME : that's bad to rescue all exceptions, but for now, throw false.
143
+ # false
137
144
  end
138
145
  end
139
146
  end
@@ -1,7 +1,116 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require "ruby-debug"
3
+
4
+ VIDEO_RESPONSE_HASH = { 'rsp' => { 'video' => { 'title' => 'Ma video', 'caption' => 'Great caption', 'privacy' => 'nobody', 'thumbnails' => { 'thumbnail' => ['http://first_thumb.jpg'] }, 'tags' => { 'tag' => ['cool', 'great'] }, 'is_transcoding' => '0', 'is_uploading' => '0' } } }
2
5
 
3
6
  describe "EasyVimeo" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
7
+
8
+ def video_init(options = {})
9
+ @api_key = "pipo"
10
+ @secret_key = "molo"
11
+ @video = Vimeo::Easy.new :api_key => @api_key, :secret_key => @secret_key, :auth_token => options[:auth_token]
12
+ end
13
+
14
+ def video_load
15
+ @video.vimeo_video.should_receive(:get_info).and_return(VIDEO_RESPONSE_HASH)
16
+ @video.video_id = 9999999
17
+ @video.reload
18
+ end
19
+
20
+ it "should not initialize without secret_key & api_key" do
21
+ lambda { Vimeo::Easy.new }.should raise_error
22
+ end
23
+
24
+ it "should initialize with secret_key & api_key and set default attributes" do
25
+ video_init
26
+
27
+ @video.api_key.should == @api_key
28
+ @video.privacy.should == :anybody
29
+
30
+ @video.vimeo_upload.should be_a(Vimeo::Advanced::Upload)
31
+ @video.vimeo_video.should be_a(Vimeo::Advanced::Video)
32
+
33
+ @video.should be_new_record
34
+ end
35
+
36
+ it "should not accept bad privacy type" do
37
+ video_init
38
+
39
+ lambda { @video.privacy = :pipo }.should raise_error
40
+ end
41
+
42
+ it "should not reload the video without video_id" do
43
+ video_init
44
+
45
+ lambda { @video.reload }.should raise_error
46
+ end
47
+
48
+ it "should reload the video with video_id" do
49
+ video_init
50
+ video_load
51
+
52
+ @video.title.should == 'Ma video'
53
+ @video.caption.should == 'Great caption'
54
+ @video.privacy.should == :nobody
55
+ @video.tags.should == 'cool, great'
56
+ @video.thumbnail.should == 'http://first_thumb.jpg'
57
+
58
+ @video.should be_available
59
+ @video.should_not be_new_record
60
+ end
61
+
62
+ it "should not be able to save with a file if video is already uploaded" do
63
+ video_init(:auth_token => "pipo")
64
+ video_load
65
+
66
+ @video.file = '/tmp/pipo'
67
+ lambda { @video.save }.should raise_error
68
+ end
69
+
70
+ it 'should not be able to save a video without auth_token or video_id' do
71
+ video_init
72
+ video_load
73
+
74
+ lambda { @video.save }.should raise_error
75
+
76
+ video_init(:auth_token => "pipo")
77
+ lambda { @video.save }.should raise_error
78
+ end
79
+
80
+ it 'should be able to save a video' do
81
+ video_init(:auth_token => "pipo")
82
+ video_load
83
+
84
+ @video.vimeo_video.should_receive(:set_privacy).and_return(true)
85
+ @video.vimeo_video.should_receive(:set_caption).and_return(true)
86
+ @video.vimeo_video.should_receive(:set_title).and_return(true)
87
+
88
+ @video.save.should == true
89
+ end
90
+
91
+ it 'should be able to save a video with a file' do
92
+ video_init(:auth_token => "pipo")
93
+
94
+ @video.file = '/tmp/pipo'
95
+
96
+ File.should_receive(:exists?).with('/tmp/pipo').and_return(true)
97
+ @video.vimeo_upload.should_receive(:get_upload_ticket).and_return({ "rsp" => { "ticket" => { "id" => "123456" } } })
98
+ @curl = mock("curl")
99
+ Curl::Easy.should_receive(:new).and_return(@curl)
100
+ @curl.should_receive(:'multipart_form_post=')
101
+ @curl.should_receive(:http_post).and_return(true)
102
+ @video.vimeo_upload.should_receive(:check_upload_status).and_return({ "rsp" => { "ticket" => { "video_id" => "123456" } } })
103
+
104
+ @video.vimeo_video.should_receive(:set_privacy).and_return(true)
105
+ @video.vimeo_video.should_not_receive(:set_caption)
106
+ @video.vimeo_video.should_not_receive(:set_title)
107
+
108
+ @video.save.should == true
109
+ @video.should_not be_new_record
110
+ end
111
+
112
+ it 'should be able to find a video with a Vimeo ID' do
113
+ Vimeo::Easy.should_receive(:new).with(:toto => "pipo", :video_id => 123456).and_return(true)
114
+ Vimeo::Easy.find(123456, :toto => "pipo")
6
115
  end
7
116
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slainer68-easy-vimeo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - slainer68
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-07 00:00:00 -07:00
12
+ date: 2009-05-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,12 +40,12 @@ extensions: []
40
40
 
41
41
  extra_rdoc_files:
42
42
  - LICENSE
43
- - README.rdoc
43
+ - README.textile
44
44
  files:
45
45
  - .document
46
46
  - .gitignore
47
47
  - LICENSE
48
- - README.rdoc
48
+ - README.textile
49
49
  - Rakefile
50
50
  - VERSION
51
51
  - easy-vimeo.gemspec
data/README.rdoc DELETED
@@ -1,10 +0,0 @@
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.