Class: PhraseApp::ParamsHelpers::BodyTypeHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/phraseapp-ruby.rb

Instance Method Summary collapse

Constructor Details

#initialize(data_hash, post_body = nil) ⇒ BodyTypeHelper

Returns a new instance of BodyTypeHelper.



1104
1105
1106
1107
# File 'lib/phraseapp-ruby.rb', line 1104

def initialize(data_hash, post_body=nil)
  @data_hash = data_hash
  @post_body = post_body
end

Instance Method Details

#bodyObject



1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
# File 'lib/phraseapp-ruby.rb', line 1109

def body
  if @post_body != nil
    body = @post_body.join+PhraseApp.multipart(@data_hash)
    body << "--#{PhraseApp::MULTIPART_BOUNDARY}--\r\n"
  elsif defined?(@data_hash) && @data_hash.is_a?(Hash) && @data_hash.keys.any?
    JSON.dump(@data_hash)
  else
    nil
  end
end

#ctypeObject



1120
1121
1122
1123
1124
1125
1126
1127
1128
# File 'lib/phraseapp-ruby.rb', line 1120

def ctype
  if @post_body != nil
    return "multipart/form-data; boundary=#{PhraseApp::MULTIPART_BOUNDARY}"
  elsif defined?(@data_hash) && @data_hash.is_a?(Hash) && @data_hash.keys.any?
    return "application/json"
  else
    return ""
  end
end