mcfearsome-viddler 0.2.5 → 0.2.6
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/Manifest.txt +1 -0
- data/lib/viddler/multipart_params.rb +49 -0
- data/viddler.gemspec +2 -2
- metadata +2 -1
data/Manifest.txt
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'mime/types'
|
|
2
|
+
|
|
3
|
+
class MultipartParams #:nodoc:
|
|
4
|
+
attr_accessor :content_type, :body
|
|
5
|
+
|
|
6
|
+
def initialize(param_hash={})
|
|
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
|
|
29
|
+
when String
|
|
30
|
+
text_to_multipart(name, value)
|
|
31
|
+
when File
|
|
32
|
+
file_to_multipart(name, value)
|
|
33
|
+
end
|
|
34
|
+
end.join('')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def file_to_multipart(key,file)
|
|
38
|
+
filename = File.basename(file.path)
|
|
39
|
+
mime_types = MIME::Types.of(filename)
|
|
40
|
+
mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
|
|
41
|
+
part = %Q[Content-Disposition: form-data; name="#{key}"; filename="#{filename}"\r\n]
|
|
42
|
+
part += "Content-Transfer-Encoding: binary\r\n"
|
|
43
|
+
part += "Content-Type: #{mime_type}\r\n\r\n#{file.read}\r\n"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def text_to_multipart(key,value)
|
|
47
|
+
"Content-Disposition: form-data; name=\"#{key}\"\r\n\r\n#{value.to_s}\r\n"
|
|
48
|
+
end
|
|
49
|
+
end
|
data/viddler.gemspec
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{viddler}
|
|
5
|
-
s.version = "0.2.
|
|
5
|
+
s.version = "0.2.6"
|
|
6
6
|
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
8
|
s.authors = ["Ilya Sabanin"]
|
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
|
10
10
|
s.description = %q{Ruby wrapper around Viddler.com API.}
|
|
11
11
|
s.email = ["ilya.sabanin@gmail.com"]
|
|
12
12
|
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "README.txt", "website/index.txt"]
|
|
13
|
-
s.files = [".gitignore", "History.txt", "License.txt", "Manifest.txt", "README.txt", "Rakefile", "config/hoe.rb", "config/requirements.rb", "lib/ext/array.rb", "lib/ext/hash.rb", "lib/ext/open_struct.rb", "lib/viddler.rb", "lib/viddler/api_spec.rb", "lib/viddler/base.rb", "lib/viddler/comment.rb", "lib/viddler/request.rb", "lib/viddler/user.rb", "lib/viddler/version.rb", "lib/viddler/video.rb", "log/.gitignore", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "test/test_helper.rb", "test/test_viddler.rb", "tmp/.gitignore", "viddler.gemspec", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.html.erb"]
|
|
13
|
+
s.files = [".gitignore", "History.txt", "License.txt", "Manifest.txt", "README.txt", "Rakefile", "config/hoe.rb", "config/requirements.rb", "lib/ext/array.rb", "lib/ext/hash.rb", "lib/ext/open_struct.rb", "lib/viddler.rb", "lib/viddler/api_spec.rb", "lib/viddler/base.rb", "lib/viddler/comment.rb","lib/viddler/multipart_params.rb", "lib/viddler/request.rb", "lib/viddler/user.rb", "lib/viddler/version.rb", "lib/viddler/video.rb", "log/.gitignore", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "test/test_helper.rb", "test/test_viddler.rb", "tmp/.gitignore", "viddler.gemspec", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.html.erb"]
|
|
14
14
|
s.homepage = %q{http://viddler.rubyforge.org}
|
|
15
15
|
s.rdoc_options = ["--main", "README.txt"]
|
|
16
16
|
s.require_paths = ["lib"]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mcfearsome-viddler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ilya Sabanin
|
|
@@ -51,6 +51,7 @@ files:
|
|
|
51
51
|
- lib/viddler/api_spec.rb
|
|
52
52
|
- lib/viddler/base.rb
|
|
53
53
|
- lib/viddler/comment.rb
|
|
54
|
+
- lib/viddler/multipart_params.rb
|
|
54
55
|
- lib/viddler/request.rb
|
|
55
56
|
- lib/viddler/user.rb
|
|
56
57
|
- lib/viddler/version.rb
|