tinder 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +3 -0
- data/Manifest.txt +1 -0
- data/lib/tinder/multipart.rb +64 -0
- data/lib/tinder/version.rb +1 -1
- metadata +2 -1
data/CHANGELOG.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mime/types'
|
3
|
+
require 'net/http'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
module Multipart #:nodoc:
|
7
|
+
# From: http://deftcode.com/code/flickr_upload/multipartpost.rb
|
8
|
+
## Helper class to prepare an HTTP POST request with a file upload
|
9
|
+
## Mostly taken from
|
10
|
+
#http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/113774
|
11
|
+
### WAS:
|
12
|
+
## Anything that's broken and wrong probably the fault of Bill Stilwell
|
13
|
+
##(bill@marginalia.org)
|
14
|
+
### NOW:
|
15
|
+
## Everything wrong is due to keith@oreilly.com
|
16
|
+
|
17
|
+
class Param #:nodoc:
|
18
|
+
attr_accessor :k, :v
|
19
|
+
def initialize(k, v)
|
20
|
+
@k = k
|
21
|
+
@v = v
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_multipart
|
25
|
+
"Content-Disposition: form-data; name=\"#{k}\"\r\n\r\n#{v}\r\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class FileParam #:nodoc:
|
30
|
+
attr_accessor :k, :filename, :content
|
31
|
+
def initialize(k, filename, content)
|
32
|
+
@k = k
|
33
|
+
@filename = filename
|
34
|
+
@content = content
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_multipart
|
38
|
+
"Content-Disposition: form-data; name=\"#{k}\"; filename=\"#{filename}\"\r\n" +
|
39
|
+
"Content-Transfer-Encoding: binary\r\n" +
|
40
|
+
"Content-Type: #{MIME::Types.type_for(@filename)}\r\n\r\n" +
|
41
|
+
@content + "\r\n"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class MultipartPost #:nodoc:
|
46
|
+
BOUNDARY = 'campfire-is-awesome'
|
47
|
+
HEADER = {"Content-type" => "multipart/form-data, boundary=" + BOUNDARY + " "}
|
48
|
+
TIMEOUT_SECONDS = 30
|
49
|
+
|
50
|
+
attr_accessor :params, :query, :headers
|
51
|
+
def initialize(params)
|
52
|
+
@params = params
|
53
|
+
@query = {}
|
54
|
+
self.prepare_query
|
55
|
+
end
|
56
|
+
|
57
|
+
def prepare_query()
|
58
|
+
@query = @params.map do |k,v|
|
59
|
+
param = v.respond_to?(:read) ? FileParam.new(k, v.path, v.read) : Param.new(k, v)
|
60
|
+
"--#{BOUNDARY}\r\n#{param.to_multipart}"
|
61
|
+
end.join("") + "--#{BOUNDARY}--"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/tinder/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tinder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- init.rb
|
71
71
|
- lib/tinder.rb
|
72
72
|
- lib/tinder/campfire.rb
|
73
|
+
- lib/tinder/multipart.rb
|
73
74
|
- lib/tinder/room.rb
|
74
75
|
- lib/tinder/version.rb
|
75
76
|
has_rdoc: true
|