httmultiparty 0.3.10 → 0.3.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +36 -13
- data/lib/httmultiparty.rb +14 -10
- data/lib/httmultiparty/multipartable.rb +1 -1
- data/lib/httmultiparty/version.rb +1 -1
- metadata +99 -96
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ba205ce71b29daa317ddb636c11c36a0faf232c
|
4
|
+
data.tar.gz: de40e080e6a714619fe8360b5ee59f1262f7497c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f7573acf386d59f6c49a4fa9aace247a3d3582feb3511d1eabb90ae7c59897c1df0047909ea4745abfd7f87057e2cc57fc4e85af0a89a41277f27f20c7052511
|
7
|
+
data.tar.gz: ebf1a84986bea0781cfa4239825ce99ab9b0e497d725d2168bf16cc7e9ec16f3978ffbc8a001a22847f0e12a2ee86c1510ea9408c266cc2c682912828d6af66a
|
data/README.md
CHANGED
@@ -1,18 +1,19 @@
|
|
1
|
-
|
2
|
-
<p>HTTMultiParty is a thin wrapper around HTTParty to provide multipart uploads.</p>
|
1
|
+
## Description
|
3
2
|
|
4
|
-
|
5
|
-
<ul>
|
6
|
-
<li>httparty</li>
|
7
|
-
<li>multipart-post</li>
|
8
|
-
</ul>
|
3
|
+
HTTMultiParty is a thin wrapper around HTTParty to provide multipart uploads.
|
9
4
|
|
10
|
-
|
11
|
-
<p>To start just "include HTTMultiParty" instead of "include HTTParty" into your client class.
|
12
|
-
When you pass a query with an instance of a File as a value for a PUT or POST request, the wrapper will
|
13
|
-
use a bit of magic and multipart-post to execute a multipart upload:</p>
|
5
|
+
## Requirements
|
14
6
|
|
15
|
-
|
7
|
+
- httparty
|
8
|
+
- multipart-post
|
9
|
+
- mimemagic
|
10
|
+
|
11
|
+
## Quick Start and Example
|
12
|
+
|
13
|
+
To start just "include HTTMultiParty" instead of "include HTTParty" into
|
14
|
+
your client class. When you pass a query with an instance of a File as a value for a PUT or POST request, the wrapper will use a bit of magic and multipart-post to execute a multipart upload:
|
15
|
+
|
16
|
+
```ruby
|
16
17
|
require 'httmultiparty'
|
17
18
|
class SomeClient
|
18
19
|
include HTTMultiParty
|
@@ -23,6 +24,28 @@ response = SomeClient.post('/', :query => {
|
|
23
24
|
:foo => 'bar',
|
24
25
|
:somefile => File.new('README.md')
|
25
26
|
})
|
26
|
-
|
27
|
+
```
|
27
28
|
|
28
29
|
Aside from that it provides all the usual HTTParty gimmicks.
|
30
|
+
|
31
|
+
## MIME type support
|
32
|
+
|
33
|
+
If you want the library to detect the MIME types of the uploaded files, then
|
34
|
+
you need to enable it by supplying the `:detect_mime_type` option as `true`
|
35
|
+
for POST or PUT requests. Otherwise, they will be uploaded with the default
|
36
|
+
MIME type of `application/octet-stream`. For example:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'httmultiparty'
|
40
|
+
class SomeClient
|
41
|
+
include HTTMultiParty
|
42
|
+
base_uri 'http://localhost:3000'
|
43
|
+
end
|
44
|
+
|
45
|
+
response = SomeClient.post('/', :query => {
|
46
|
+
:foo => 'bar',
|
47
|
+
:somefile => File.new('README.md')
|
48
|
+
}, :detect_mime_type => true)
|
49
|
+
```
|
50
|
+
|
51
|
+
|
data/lib/httmultiparty.rb
CHANGED
@@ -3,31 +3,35 @@ gem 'multipart-post'
|
|
3
3
|
require 'tempfile'
|
4
4
|
require 'httparty'
|
5
5
|
require 'net/http/post/multipart'
|
6
|
+
require 'mimemagic'
|
6
7
|
|
7
8
|
module HTTMultiParty
|
8
9
|
TRANSFORMABLE_TYPES = [File, Tempfile]
|
9
10
|
|
10
|
-
QUERY_STRING_NORMALIZER = Proc.new do |params|
|
11
|
-
HTTMultiParty.flatten_params(params).map do |(k,v)|
|
12
|
-
[k, TRANSFORMABLE_TYPES.include?(v.class) ? HTTMultiParty.file_to_upload_io(v) : v]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
11
|
def self.included(base)
|
17
12
|
base.send :include, HTTParty
|
18
13
|
base.extend ClassMethods
|
19
14
|
end
|
20
15
|
|
21
|
-
def self.file_to_upload_io(file)
|
16
|
+
def self.file_to_upload_io(file, detect_mime_type = false)
|
22
17
|
if file.respond_to? :original_filename
|
23
18
|
filename = file.original_filename
|
24
19
|
else
|
25
20
|
filename = File.split(file.path).last
|
26
21
|
end
|
27
|
-
content_type = 'application/octet-stream'
|
22
|
+
content_type = detect_mime_type ? MimeMagic.by_path(filename) : 'application/octet-stream'
|
28
23
|
UploadIO.new(file, content_type, filename)
|
29
24
|
end
|
30
25
|
|
26
|
+
def self.query_string_normalizer(options = {})
|
27
|
+
detect_mime_type = options.fetch(:detect_mime_type, false)
|
28
|
+
Proc.new do |params|
|
29
|
+
HTTMultiParty.flatten_params(params).map do |(k,v)|
|
30
|
+
[k, TRANSFORMABLE_TYPES.include?(v.class) ? HTTMultiParty.file_to_upload_io(v, detect_mime_type) : v]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
31
35
|
def self.flatten_params(params={}, prefix='')
|
32
36
|
flattened = []
|
33
37
|
params.each do |(k,v)|
|
@@ -76,7 +80,7 @@ module HTTMultiParty
|
|
76
80
|
options[:body] ||= options.delete(:query)
|
77
81
|
if hash_contains_files?(options[:body])
|
78
82
|
method = MultipartPost
|
79
|
-
options[:query_string_normalizer] = HTTMultiParty
|
83
|
+
options[:query_string_normalizer] = HTTMultiParty.query_string_normalizer(options)
|
80
84
|
end
|
81
85
|
perform_request method, path, options
|
82
86
|
end
|
@@ -86,7 +90,7 @@ module HTTMultiParty
|
|
86
90
|
options[:body] ||= options.delete(:query)
|
87
91
|
if hash_contains_files?(options[:body])
|
88
92
|
method = MultipartPut
|
89
|
-
options[:query_string_normalizer] = HTTMultiParty
|
93
|
+
options[:query_string_normalizer] = HTTMultiParty.query_string_normalizer(options)
|
90
94
|
end
|
91
95
|
perform_request method, path, options
|
92
96
|
end
|
@@ -7,7 +7,7 @@ module HTTMultiParty::Multipartable
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def body=(value)
|
10
|
-
@body_parts = value.map {|(k,v)| Parts::Part.new(boundary, k, v)}
|
10
|
+
@body_parts = Array(value).map {|(k,v)| Parts::Part.new(boundary, k, v)}
|
11
11
|
@body_parts << Parts::EpiloguePart.new(boundary)
|
12
12
|
set_headers_for_body
|
13
13
|
end
|
metadata
CHANGED
@@ -1,132 +1,135 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: httmultiparty
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 10
|
10
|
-
version: 0.3.10
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.11
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Johannes Wagener
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
22
14
|
name: httparty
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 5
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 7
|
33
|
-
- 3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
34
19
|
version: 0.7.3
|
35
20
|
type: :runtime
|
36
|
-
|
37
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
38
28
|
name: multipart-post
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
39
35
|
prerelease: false
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mimemagic
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
49
48
|
type: :runtime
|
50
|
-
version_requirements: *id002
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: rspec
|
53
49
|
prerelease: false
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
63
62
|
type: :development
|
64
|
-
version_requirements: *id003
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: fakeweb
|
67
63
|
prerelease: false
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
77
76
|
type: :development
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: fakeweb
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: HTTMultiParty is a thin wrapper around HTTParty to provide multipart
|
98
|
+
uploads.
|
99
|
+
email:
|
81
100
|
- johannes@wagener.cc
|
82
101
|
executables: []
|
83
|
-
|
84
102
|
extensions: []
|
85
|
-
|
86
103
|
extra_rdoc_files: []
|
87
|
-
|
88
|
-
files:
|
104
|
+
files:
|
89
105
|
- lib/httmultiparty/multipart_post.rb
|
90
106
|
- lib/httmultiparty/multipart_put.rb
|
91
107
|
- lib/httmultiparty/multipartable.rb
|
92
108
|
- lib/httmultiparty/version.rb
|
93
109
|
- lib/httmultiparty.rb
|
94
110
|
- README.md
|
95
|
-
has_rdoc: true
|
96
111
|
homepage: http://github.com/jwagener/httmultiparty
|
97
|
-
licenses:
|
98
|
-
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
99
115
|
post_install_message:
|
100
116
|
rdoc_options: []
|
101
|
-
|
102
|
-
require_paths:
|
117
|
+
require_paths:
|
103
118
|
- lib
|
104
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
|
-
requirements:
|
116
|
-
- - ">="
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
hash: 23
|
119
|
-
segments:
|
120
|
-
- 1
|
121
|
-
- 3
|
122
|
-
- 6
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - '>='
|
127
|
+
- !ruby/object:Gem::Version
|
123
128
|
version: 1.3.6
|
124
129
|
requirements: []
|
125
|
-
|
126
130
|
rubyforge_project:
|
127
|
-
rubygems_version:
|
131
|
+
rubygems_version: 2.0.2
|
128
132
|
signing_key:
|
129
|
-
specification_version:
|
133
|
+
specification_version: 4
|
130
134
|
summary: HTTMultiParty is a thin wrapper around HTTParty to provide multipart uploads.
|
131
135
|
test_files: []
|
132
|
-
|