Module: XamarinTestCloud::HTTP::Payload

Extended by:
Payload
Included in:
Payload
Defined in:
lib/xamarin-test-cloud/http/payload.rb

Overview

Copied from rest-client

Defined Under Namespace

Classes: Base, Multipart, Streamed, UrlEncoded

Instance Method Summary collapse

Instance Method Details

#generate(params) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/xamarin-test-cloud/http/payload.rb', line 37

def generate(params)
  if params.is_a?(String)
    Base.new(params)
  elsif params.is_a?(Hash)
    if params.delete(:multipart) == true || has_file?(params)
      Multipart.new(params)
    else
      UrlEncoded.new(params)
    end
  elsif params.respond_to?(:read)
    Streamed.new(params)
  else
    nil
  end
end

#has_file?(params) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/xamarin-test-cloud/http/payload.rb', line 53

def has_file?(params)
  params.any? do |_, v|
    case v
      when Hash
        has_file?(v)
      when Array
        has_file_array?(v)
      else
        v.respond_to?(:path) && v.respond_to?(:read)
    end
  end
end

#has_file_array?(params) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/xamarin-test-cloud/http/payload.rb', line 66

def has_file_array?(params)
  params.any? do |v|
    case v
      when Hash
        has_file?(v)
      when Array
        has_file_array?(v)
      else
        v.respond_to?(:path) && v.respond_to?(:read)
    end
  end
end