Module: HTTMultiParty

Included in:
Basement
Defined in:
lib/httmultiparty.rb,
lib/httmultiparty/version.rb

Defined Under Namespace

Modules: ClassMethods, Multipartable Classes: Basement, MultipartPost, MultipartPut

Constant Summary collapse

TRANSFORMABLE_TYPES =
[File, Tempfile]
QUERY_STRING_NORMALIZER =
Proc.new do |params|
  HTTMultiParty.flatten_params(params).map do |(k,v)|
    [k, TRANSFORMABLE_TYPES.include?(v.class) ? HTTMultiParty.file_to_upload_io(v) : v]
  end
end
VERSION =
'0.3.7'

Class Method Summary collapse

Class Method Details

.delete(*args) ⇒ Object



63
64
65
# File 'lib/httmultiparty.rb', line 63

def self.delete(*args)
  Basement.delete(*args)
end

.file_to_upload_io(file) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/httmultiparty.rb', line 22

def self.file_to_upload_io(file)
  if file.respond_to? :original_filename
    filename = file.original_filename
  else
    filename =  File.split(file.path).last
  end
  content_type = @base.upload_file_content_type()
  content_type = 'application/octet-stream' if content_type.blank?
  UploadIO.new(file, content_type, filename)
end

.flatten_params(params = {}, prefix = '') ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/httmultiparty.rb', line 33

def self.flatten_params(params={}, prefix='')
  flattened = []
  params.each do |(k,v)|
    if params.is_a?(Array)
      v = k
      k = ""
    end

    flattened_key = prefix == "" ? "#{k}" : "#{prefix}[#{k}]"
    if v.is_a?(Hash) || v.is_a?(Array)
      flattened += flatten_params(v, flattened_key)
    else
      flattened << [flattened_key, v]
    end
  end
  flattened
end

.get(*args) ⇒ Object



51
52
53
# File 'lib/httmultiparty.rb', line 51

def self.get(*args)
  Basement.get(*args)
end

.head(*args) ⇒ Object



67
68
69
# File 'lib/httmultiparty.rb', line 67

def self.head(*args)
  Basement.head(*args)
end

.included(base) ⇒ Object



16
17
18
19
20
# File 'lib/httmultiparty.rb', line 16

def self.included(base)
  base.send :include, HTTParty
  base.extend ClassMethods
  @base = base
end

.options(*args) ⇒ Object



71
72
73
# File 'lib/httmultiparty.rb', line 71

def self.options(*args)
  Basement.options(*args)
end

.post(*args) ⇒ Object



55
56
57
# File 'lib/httmultiparty.rb', line 55

def self.post(*args)
  Basement.post(*args)
end

.put(*args) ⇒ Object



59
60
61
# File 'lib/httmultiparty.rb', line 59

def self.put(*args)
  Basement.put(*args)
end