viddler 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,9 +1,13 @@
1
+ == 0.2.1 2008-04-19
2
+
3
+ * 1 bug fix:
4
+ * Fixing compatibility of <tt>viddler.videos.upload</tt> method with Rails
5
+
1
6
  == 0.2.0 2008-04-18
2
7
 
3
8
  * 1 major enhancement:
4
9
  * Implemented <tt>videos.getRecordToken</tt> method
5
10
 
6
-
7
11
  == 0.1.0 2008-04-17
8
12
 
9
13
  * 1 major enhancement:
data/Manifest.txt CHANGED
@@ -5,6 +5,7 @@ README.txt
5
5
  Rakefile
6
6
  config/hoe.rb
7
7
  config/requirements.rb
8
+ lib/ext/array.rb
8
9
  lib/ext/hash.rb
9
10
  lib/ext/open_struct.rb
10
11
  lib/viddler.rb
data/lib/ext/array.rb ADDED
@@ -0,0 +1,18 @@
1
+ class Array #:nodoc:
2
+
3
+ # Extraceted from Ruby Facets:
4
+ # Converts a two-element associative array into a hash.
5
+ def to_h(arrayed=nil)
6
+ h = {}
7
+ if arrayed
8
+ each{ |k,*v| h[k] = v }
9
+ else
10
+ ary = []
11
+ each do |a|
12
+ Array===a ? ary.concat(a) : ary << a
13
+ end
14
+ h = Hash[*ary]
15
+ end
16
+ h
17
+ end
18
+ end
data/lib/ext/hash.rb CHANGED
@@ -7,4 +7,22 @@ class Hash #:nodoc:
7
7
  true
8
8
  end
9
9
 
10
+ # Extracted from Ruby Facets:
11
+ # Operator for remove hash paris. If another hash is given the pairs are only removed if both key and value are equal. If an array is given then matching keys are removed.
12
+ def -(other)
13
+ h = self.dup
14
+ if other.respond_to?(:to_ary)
15
+ other.to_ary.each do |k|
16
+ h.delete(k)
17
+ end
18
+ else
19
+ other.each do |k,v|
20
+ if h.key?(k)
21
+ h.delete(k) if v == h[k]
22
+ end
23
+ end
24
+ end
25
+ h
26
+ end
27
+
10
28
  end
data/lib/viddler.rb CHANGED
@@ -7,6 +7,7 @@ require 'ostruct'
7
7
 
8
8
  require 'ext/open_struct'
9
9
  require 'ext/hash'
10
+ require 'ext/array'
10
11
  require 'viddler/api_spec'
11
12
  require 'viddler/base'
12
13
  require 'viddler/multipart_params'
@@ -4,20 +4,36 @@ class MultipartParams #:nodoc:
4
4
  attr_accessor :content_type, :body
5
5
 
6
6
  def initialize(param_hash={})
7
- boundary_token = [Array.new(8) {rand(256)}].join
8
- self.content_type = "multipart/form-data; boundary=#{boundary_token}"
9
- boundary_marker = "--#{boundary_token}\r\n"
10
- self.body = param_hash.map { |param_name, param_value|
11
- boundary_marker + case param_value
7
+ @boundary_token = generate_boundary_token
8
+ self.content_type = "multipart/form-data; boundary=#{@boundary_token}"
9
+ self.body = pack_params(param_hash)
10
+ end
11
+
12
+ protected
13
+
14
+ def generate_boundary_token
15
+ [Array.new(8) {rand(256)}].join
16
+ end
17
+
18
+ def pack_params(hash)
19
+ marker = "--#{@boundary_token}\r\n"
20
+ files_params = hash.find_all{|k,v| v.is_a?(File)}.to_h
21
+ text_params = hash - files_params
22
+
23
+ pack_hash(text_params, marker) + marker + pack_hash(files_params, marker) + "--#{@boundary_token}--\r\n"
24
+ end
25
+
26
+ def pack_hash(hash, marker)
27
+ hash.map do |name, value|
28
+ marker + case value
12
29
  when String
13
- text_to_multipart(param_name, param_value)
30
+ text_to_multipart(name, value)
14
31
  when File
15
- file_to_multipart(param_name, param_value)
32
+ file_to_multipart(name, value)
16
33
  end
17
- }.join('') + "--#{boundary_token}--\r\n"
34
+ end.join('')
18
35
  end
19
-
20
- protected
36
+
21
37
  def file_to_multipart(key,file)
22
38
  filename = File.basename(file.path)
23
39
  mime_types = MIME::Types.of(filename)
@@ -2,7 +2,7 @@ module Viddler #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/test/test_viddler.rb CHANGED
@@ -17,7 +17,7 @@ class ViddlerTest < Test::Unit::TestCase
17
17
  API_KEY = nil
18
18
  LOGIN = nil
19
19
  PASSWORD = nil
20
- TEST_VIDEO_FILE_PATH = '/path/to/video'
20
+ TEST_VIDEO_FILE_PATH = '/Users/ilya/Desktop/file.mov'
21
21
 
22
22
  def setup
23
23
  raise KeyRequired unless API_KEY
@@ -39,7 +39,7 @@ class ViddlerTest < Test::Unit::TestCase
39
39
  def test_should_upload_video
40
40
  credentials_required
41
41
  file = File.open(TEST_VIDEO_FILE_PATH)
42
- video = @viddler.upload_video(:file => file, :title => 'Testing', :description => 'Bla', :tags => 'one, two, three')
42
+ video = @viddler.upload_video(:file => file, :title => 'Testing', :description => 'Bla', :tags => 'one, two, three', :make_public => '0')
43
43
  end
44
44
 
45
45
  def test_should_find_profile
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>viddler</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/viddler"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/viddler" class="numbers">0.2.0</a>
36
+ <a href="http://rubyforge.org/projects/viddler" class="numbers">0.2.1</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;viddler&#8217;</h1>
39
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viddler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Sabanin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-18 00:00:00 +08:00
12
+ date: 2008-04-19 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -34,6 +34,7 @@ files:
34
34
  - Rakefile
35
35
  - config/hoe.rb
36
36
  - config/requirements.rb
37
+ - lib/ext/array.rb
37
38
  - lib/ext/hash.rb
38
39
  - lib/ext/open_struct.rb
39
40
  - lib/viddler.rb