httmultiparty 0.3.10 → 0.3.11

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.
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
- <h2>Description</h2>
2
- <p>HTTMultiParty is a thin wrapper around HTTParty to provide multipart uploads.</p>
1
+ ## Description
3
2
 
4
- <h2>Requirements</h2>
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
- <h2>Quick Start and Example</h2>
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
- <pre>
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
- </pre>
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::QUERY_STRING_NORMALIZER
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::QUERY_STRING_NORMALIZER
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
@@ -1,3 +1,3 @@
1
1
  module HTTMultiParty
2
- VERSION = '0.3.10'
2
+ VERSION = '0.3.11'
3
3
  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
- hash: 7
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
- date: 2013-04-10 00:00:00 +02:00
19
- default_executable:
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
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
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
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
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
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
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
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
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
- requirement: &id004 !ruby/object:Gem::Requirement
69
- none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
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
- version_requirements: *id004
79
- description: HTTMultiParty is a thin wrapper around HTTParty to provide multipart uploads.
80
- email:
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
- none: false
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- hash: 3
110
- segments:
111
- - 0
112
- version: "0"
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: 1.6.2
131
+ rubygems_version: 2.0.2
128
132
  signing_key:
129
- specification_version: 3
133
+ specification_version: 4
130
134
  summary: HTTMultiParty is a thin wrapper around HTTParty to provide multipart uploads.
131
135
  test_files: []
132
-