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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7265a5ad4092d1a872cea3823d462b75764e9f85
4
- data.tar.gz: 1c7eec14921066090bf04cf89eda9b1b54e3a4b7
3
+ metadata.gz: d51b5bba819375cac324f6aa836a364abb920d8e
4
+ data.tar.gz: 39ca6dc2aa4af46b7cbb7644608f0eaff75b998f
5
5
  SHA512:
6
- metadata.gz: e298e0321f63f95608f7e99bbe9eebedb034c38ea4c0d81ab346d4b8272a11aedb4c9c36d505437d1a71b7e43658f1006d0968d82defa6832522e12ce58b4645
7
- data.tar.gz: e8b5a16b4cc021bd39f6537a8d25e7a816c8ddee59a142e84486eea6a4e4544d1d0d518f6e3a9b76a598b40695253f7ff447a77c7fa9e3918bdae23fa4d38fa1
6
+ metadata.gz: 358c2e129b448b3fdffa3a8412cfab71d40631dbdc306836d7a847e093ee36c9bf66c24931211a012e3f323960e81e74d22c0ccdeaf5935c3c90651cd48516d4
7
+ data.tar.gz: d0cb5958a10ceb7ae82ec2e4e08a5a9aaa6958ffb5945fa673c1ff3b3a83d5eb82d374ede5f993bb9625417aa239a47b35a97b0fd913f86e635914d5cdd2a0d0
@@ -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 file_present_in_params?(params)
29
- [k, v.respond_to?(:read) ? HTTMultiParty.file_to_upload_io(v, detect_mime_type) : v]
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.file_present_in_params?(params)
82
- params.values.any? do |v|
83
- if v.is_a? Array
84
- v.any? { |vv| file_present?(vv) }
85
- elsif v.is_a? Hash
86
- v.values.any? { |vv| file_present?(vv) }
87
- else
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.file_present?(value)
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
- module ClassMethods
98
- def post(path, options={})
99
- method = Net::HTTP::Post
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
- private
119
- def hash_contains_files?(hash)
120
- hash.is_a?(Hash) && HTTMultiParty.flatten_params(hash).select do |_,v|
121
- HTTMultiParty.file_present?(v)
122
- end.size > 0
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
- end
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
@@ -1,3 +1,3 @@
1
1
  module HTTMultiParty
2
- VERSION = '0.3.15'
2
+ VERSION = '0.3.16'
3
3
  end
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.15
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-07-04 00:00:00.000000000 Z
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: