httmultiparty 0.3.14 → 0.3.15

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: 16afaa58ffab652e8ce6ab718d2f82085cc82aee
4
- data.tar.gz: 75bd0c5c38ae5d776cf5d4497585035365bb15df
3
+ metadata.gz: 7265a5ad4092d1a872cea3823d462b75764e9f85
4
+ data.tar.gz: 1c7eec14921066090bf04cf89eda9b1b54e3a4b7
5
5
  SHA512:
6
- metadata.gz: 5058bff9591159ffdfa722b72874c3ae4fb9904088f43121819af0395cc70746d68cd80616cf6e0c1ab97782832ca2cfbc59b4b98a161df9f792f090f8f88d61
7
- data.tar.gz: 4c3401cacf0ae2a10fcc147fa2ac082a4fb7094f479d3b865ebee8c400e08c4d8157030053fbede184e610028468adbceac601c1b9584c8aa2d5560864b9df75
6
+ metadata.gz: e298e0321f63f95608f7e99bbe9eebedb034c38ea4c0d81ab346d4b8272a11aedb4c9c36d505437d1a71b7e43658f1006d0968d82defa6832522e12ce58b4645
7
+ data.tar.gz: e8b5a16b4cc021bd39f6537a8d25e7a816c8ddee59a142e84486eea6a4e4544d1d0d518f6e3a9b76a598b40695253f7ff447a77c7fa9e3918bdae23fa4d38fa1
data/README.md CHANGED
@@ -1,3 +1,9 @@
1
+ [![Build Status](https://travis-ci.org/jwagener/httmultiparty.svg?branch=v0.3.14)](https://travis-ci.org/jwagener/httmultiparty)
2
+
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/httmultiparty.svg)](http://badge.fury.io/rb/httmultiparty)
5
+
6
+
1
7
  ## Description
2
8
 
3
9
  HTTMultiParty is a thin wrapper around HTTParty to provide multipart uploads.
@@ -10,8 +16,10 @@ HTTMultiParty is a thin wrapper around HTTParty to provide multipart uploads.
10
16
 
11
17
  ## Quick Start and Example
12
18
 
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:
19
+ To start just `include HTTMultiParty` instead of `include HTTParty` into
20
+ your client class. When you pass a query with an instance of a File as
21
+ a value for a PUT or POST request, the wrapper will use a bit of magic
22
+ and multipart-post to execute a multipart upload:
15
23
 
16
24
  ```ruby
17
25
  require 'httmultiparty'
@@ -47,5 +55,11 @@ response = SomeClient.post('/', :query => {
47
55
  :somefile => File.new('README.md')
48
56
  }, :detect_mime_type => true)
49
57
  ```
58
+ ## File class support
50
59
 
51
-
60
+ Instead of using `File` class, you can use any class that responds to
61
+ a `read` method as a file object. If you are using Rails, you can use
62
+ `ActionDispatch::Http::UploadedFile` object directly as it responds to
63
+ `read` method. The `read` method should act similar to the `IO#read`
64
+ method. To set the filename your file class can optionally respond to
65
+ the `original_filename` method, which should return a `String`.
@@ -6,8 +6,6 @@ require 'net/http/post/multipart'
6
6
  require 'mimemagic'
7
7
 
8
8
  module HTTMultiParty
9
- TRANSFORMABLE_TYPES = [File, Tempfile]
10
-
11
9
  def self.included(base)
12
10
  base.send :include, HTTParty
13
11
  base.extend ClassMethods
@@ -28,7 +26,7 @@ module HTTMultiParty
28
26
  Proc.new do |params|
29
27
  HTTMultiParty.flatten_params(params).map do |(k,v)|
30
28
  if file_present_in_params?(params)
31
- [k, TRANSFORMABLE_TYPES.include?(v.class) ? HTTMultiParty.file_to_upload_io(v, detect_mime_type) : v]
29
+ [k, v.respond_to?(:read) ? HTTMultiParty.file_to_upload_io(v, detect_mime_type) : v]
32
30
  else
33
31
  "#{k}=#{v}"
34
32
  end
@@ -83,15 +81,19 @@ module HTTMultiParty
83
81
  def self.file_present_in_params?(params)
84
82
  params.values.any? do |v|
85
83
  if v.is_a? Array
86
- v.any? { |vv| TRANSFORMABLE_TYPES.include?(vv.class) || vv.is_a?(UploadIO) }
84
+ v.any? { |vv| file_present?(vv) }
87
85
  elsif v.is_a? Hash
88
- v.values.any? { |vv| TRANSFORMABLE_TYPES.include?(vv.class) || vv.is_a?(UploadIO) }
86
+ v.values.any? { |vv| file_present?(vv) }
89
87
  else
90
- TRANSFORMABLE_TYPES.include?(v.class) || v.is_a?(UploadIO)
88
+ file_present?(v)
91
89
  end
92
90
  end
93
91
  end
94
92
 
93
+ def self.file_present?(value)
94
+ value.respond_to?(:read)
95
+ end
96
+
95
97
  module ClassMethods
96
98
  def post(path, options={})
97
99
  method = Net::HTTP::Post
@@ -115,8 +117,8 @@ module HTTMultiParty
115
117
 
116
118
  private
117
119
  def hash_contains_files?(hash)
118
- hash.is_a?(Hash) && HTTMultiParty.flatten_params(hash).select do |(k,v)|
119
- TRANSFORMABLE_TYPES.include?(v.class) || v.is_a?(UploadIO)
120
+ hash.is_a?(Hash) && HTTMultiParty.flatten_params(hash).select do |_,v|
121
+ HTTMultiParty.file_present?(v)
120
122
  end.size > 0
121
123
  end
122
124
  end
@@ -1,3 +1,3 @@
1
1
  module HTTMultiParty
2
- VERSION = '0.3.14'
2
+ VERSION = '0.3.15'
3
3
  end
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httmultiparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15
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-04-08 00:00:00.000000000 Z
11
+ date: 2014-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.7.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.7.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: multipart-post
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mimemagic
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: fakeweb
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: HTTMultiParty is a thin wrapper around HTTParty to provide multipart
@@ -102,12 +102,12 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - README.md
105
106
  - lib/httmultiparty.rb
106
- - lib/httmultiparty/version.rb
107
- - lib/httmultiparty/multipart_put.rb
108
107
  - lib/httmultiparty/multipart_post.rb
108
+ - lib/httmultiparty/multipart_put.rb
109
109
  - lib/httmultiparty/multipartable.rb
110
- - README.md
110
+ - lib/httmultiparty/version.rb
111
111
  homepage: http://github.com/jwagener/httmultiparty
112
112
  licenses:
113
113
  - MIT
@@ -118,17 +118,17 @@ require_paths:
118
118
  - lib
119
119
  required_ruby_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - '>='
121
+ - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
- - - '>='
126
+ - - ">="
127
127
  - !ruby/object:Gem::Version
128
128
  version: 1.3.6
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.0.14
131
+ rubygems_version: 2.2.2
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: HTTMultiParty is a thin wrapper around HTTParty to provide multipart uploads.