httmultiparty 0.3.15 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/httmultiparty.rb +58 -40
- data/lib/httmultiparty/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d51b5bba819375cac324f6aa836a364abb920d8e
|
4
|
+
data.tar.gz: 39ca6dc2aa4af46b7cbb7644608f0eaff75b998f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 358c2e129b448b3fdffa3a8412cfab71d40631dbdc306836d7a847e093ee36c9bf66c24931211a012e3f323960e81e74d22c0ccdeaf5935c3c90651cd48516d4
|
7
|
+
data.tar.gz: d0cb5958a10ceb7ae82ec2e4e08a5a9aaa6958ffb5945fa673c1ff3b3a83d5eb82d374ede5f993bb9625417aa239a47b35a97b0fd913f86e635914d5cdd2a0d0
|
data/lib/httmultiparty.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
gem 'httparty'
|
2
|
-
gem 'multipart-post'
|
3
1
|
require 'tempfile'
|
4
2
|
require 'httparty'
|
5
3
|
require 'net/http/post/multipart'
|
@@ -25,8 +23,9 @@ module HTTMultiParty
|
|
25
23
|
detect_mime_type = options.fetch(:detect_mime_type, false)
|
26
24
|
Proc.new do |params|
|
27
25
|
HTTMultiParty.flatten_params(params).map do |(k,v)|
|
28
|
-
if
|
29
|
-
|
26
|
+
if file_present?(params)
|
27
|
+
v = prepare_value!(v,detect_mime_type)
|
28
|
+
[k, v]
|
30
29
|
else
|
31
30
|
"#{k}=#{v}"
|
32
31
|
end
|
@@ -52,6 +51,11 @@ module HTTMultiParty
|
|
52
51
|
flattened
|
53
52
|
end
|
54
53
|
|
54
|
+
def self.prepare_value!(value, detect_mime_type)
|
55
|
+
return value if does_not_need_conversion?(value)
|
56
|
+
HTTMultiParty.file_to_upload_io(value, detect_mime_type)
|
57
|
+
end
|
58
|
+
|
55
59
|
def self.get(*args)
|
56
60
|
Basement.get(*args)
|
57
61
|
end
|
@@ -78,50 +82,64 @@ module HTTMultiParty
|
|
78
82
|
|
79
83
|
private
|
80
84
|
|
81
|
-
def self.
|
82
|
-
params.
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
file_present?(v)
|
89
|
-
end
|
85
|
+
def self.file_present?(params)
|
86
|
+
if params.is_a? Array
|
87
|
+
file_present_in_array?(params)
|
88
|
+
elsif params.is_a? Hash
|
89
|
+
file_present_in_array?(params.values)
|
90
|
+
else
|
91
|
+
file?(params)
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
93
|
-
def self.
|
95
|
+
def self.file_present_in_array?(ary)
|
96
|
+
ary.any? { |a| file_present?(a) }
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.file?(value)
|
94
100
|
value.respond_to?(:read)
|
95
101
|
end
|
96
102
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
options[:body] ||= options.delete(:query)
|
101
|
-
if hash_contains_files?(options[:body])
|
102
|
-
method = MultipartPost
|
103
|
-
options[:query_string_normalizer] = HTTMultiParty.query_string_normalizer(options)
|
104
|
-
end
|
105
|
-
perform_request method, path, options
|
106
|
-
end
|
107
|
-
|
108
|
-
def put(path, options={})
|
109
|
-
method = Net::HTTP::Put
|
110
|
-
options[:body] ||= options.delete(:query)
|
111
|
-
if hash_contains_files?(options[:body])
|
112
|
-
method = MultipartPut
|
113
|
-
options[:query_string_normalizer] = HTTMultiParty.query_string_normalizer(options)
|
114
|
-
end
|
115
|
-
perform_request method, path, options
|
116
|
-
end
|
103
|
+
def self.not_a_file?(value)
|
104
|
+
!file?(value)
|
105
|
+
end
|
117
106
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
107
|
+
def self.upload_io?(value)
|
108
|
+
value.is_a?(UploadIO)
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.does_not_need_conversion?(value)
|
112
|
+
not_a_file?(value) ||
|
113
|
+
upload_io?(value)
|
114
|
+
end
|
115
|
+
|
116
|
+
module ClassMethods
|
117
|
+
def post(path, options={})
|
118
|
+
method = Net::HTTP::Post
|
119
|
+
options[:body] ||= options.delete(:query)
|
120
|
+
if hash_contains_files?(options[:body])
|
121
|
+
method = MultipartPost
|
122
|
+
options[:query_string_normalizer] = HTTMultiParty.query_string_normalizer(options)
|
123
|
+
end
|
124
|
+
perform_request method, path, options
|
125
|
+
end
|
126
|
+
|
127
|
+
def put(path, options={})
|
128
|
+
method = Net::HTTP::Put
|
129
|
+
options[:body] ||= options.delete(:query)
|
130
|
+
if hash_contains_files?(options[:body])
|
131
|
+
method = MultipartPut
|
132
|
+
options[:query_string_normalizer] = HTTMultiParty.query_string_normalizer(options)
|
123
133
|
end
|
124
|
-
|
134
|
+
perform_request method, path, options
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
def hash_contains_files?(hash)
|
140
|
+
HTTMultiParty.file_present?(hash)
|
141
|
+
end
|
142
|
+
end
|
125
143
|
|
126
144
|
class Basement
|
127
145
|
include HTTMultiParty
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httmultiparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johannes Wagener
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -133,3 +133,4 @@ signing_key:
|
|
133
133
|
specification_version: 4
|
134
134
|
summary: HTTMultiParty is a thin wrapper around HTTParty to provide multipart uploads.
|
135
135
|
test_files: []
|
136
|
+
has_rdoc:
|