httmultiparty 0.3.6 → 0.3.7

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/README.md CHANGED
@@ -13,16 +13,16 @@ When you pass a query with an instance of a File as a value for a PUT or POST re
13
13
  use a bit of magic and multipart-post to execute a multipart upload:</p>
14
14
 
15
15
  <pre>
16
- require 'lib/httmultiparty'
16
+ require 'httmultiparty'
17
17
  class SomeClient
18
18
  include HTTMultiParty
19
19
  base_uri 'http://localhost:3000'
20
20
  end
21
21
 
22
22
  response = SomeClient.post('/', :query => {
23
- :foo => 'bar',
24
- :somefile => File.new('README.md')
25
- })
23
+ :foo => 'bar',
24
+ :somefile => File.new('README.md')
25
+ })
26
26
  </pre>
27
27
 
28
- Aside from that it provides all the usual HTTParty gimmicks.
28
+ Aside from that it provides all the usual HTTParty gimmicks.
@@ -1,12 +1,15 @@
1
1
  gem 'httparty'
2
2
  gem 'multipart-post'
3
+ require 'tempfile'
3
4
  require 'httparty'
4
5
  require 'net/http/post/multipart'
5
6
 
6
7
  module HTTMultiParty
8
+ TRANSFORMABLE_TYPES = [File, Tempfile]
9
+
7
10
  QUERY_STRING_NORMALIZER = Proc.new do |params|
8
11
  HTTMultiParty.flatten_params(params).map do |(k,v)|
9
- [k, v.is_a?(File) ? HTTMultiParty.file_to_upload_io(v) : v]
12
+ [k, TRANSFORMABLE_TYPES.include?(v.class) ? HTTMultiParty.file_to_upload_io(v) : v]
10
13
  end
11
14
  end
12
15
 
@@ -16,7 +19,11 @@ module HTTMultiParty
16
19
  end
17
20
 
18
21
  def self.file_to_upload_io(file)
19
- filename = File.split(file.path).last
22
+ if file.respond_to? :original_filename
23
+ filename = file.original_filename
24
+ else
25
+ filename = File.split(file.path).last
26
+ end
20
27
  content_type = 'application/octet-stream'
21
28
  UploadIO.new(file, content_type, filename)
22
29
  end
@@ -39,6 +46,30 @@ module HTTMultiParty
39
46
  flattened
40
47
  end
41
48
 
49
+ def self.get(*args)
50
+ Basement.get(*args)
51
+ end
52
+
53
+ def self.post(*args)
54
+ Basement.post(*args)
55
+ end
56
+
57
+ def self.put(*args)
58
+ Basement.put(*args)
59
+ end
60
+
61
+ def self.delete(*args)
62
+ Basement.delete(*args)
63
+ end
64
+
65
+ def self.head(*args)
66
+ Basement.head(*args)
67
+ end
68
+
69
+ def self.options(*args)
70
+ Basement.options(*args)
71
+ end
72
+
42
73
  module ClassMethods
43
74
  def post(path, options={})
44
75
  method = Net::HTTP::Post
@@ -63,10 +94,14 @@ module HTTMultiParty
63
94
  private
64
95
  def hash_contains_files?(hash)
65
96
  hash.is_a?(Hash) && HTTMultiParty.flatten_params(hash).select do |(k,v)|
66
- v.is_a?(File) || v.is_a?(UploadIO)
97
+ TRANSFORMABLE_TYPES.include?(v.class) || v.is_a?(UploadIO)
67
98
  end.size > 0
68
99
  end
69
100
  end
101
+
102
+ class Basement
103
+ include HTTMultiParty
104
+ end
70
105
  end
71
106
 
72
107
  require 'httmultiparty/version'
@@ -1,3 +1,3 @@
1
1
  module HTTMultiParty
2
- VERSION = '0.3.6'
2
+ VERSION = '0.3.7'
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: httmultiparty
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.6
5
+ version: 0.3.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Johannes Wagener
@@ -10,8 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-12 00:00:00 -07:00
14
- default_executable:
13
+ date: 2012-04-04 00:00:00 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: httparty
@@ -73,7 +72,6 @@ files:
73
72
  - lib/httmultiparty/version.rb
74
73
  - lib/httmultiparty.rb
75
74
  - README.md
76
- has_rdoc: true
77
75
  homepage: http://github.com/jwagener/httmultiparty
78
76
  licenses: []
79
77
 
@@ -97,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
95
  requirements: []
98
96
 
99
97
  rubyforge_project:
100
- rubygems_version: 1.6.2
98
+ rubygems_version: 1.8.17
101
99
  signing_key:
102
100
  specification_version: 3
103
101
  summary: HTTMultiParty is a thin wrapper around HTTParty to provide multipart uploads.