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.



1166
1167
1168
1169
# File 'lib/phraseapp-ruby.rb', line 1166

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

Instance Method Details

#bodyObject



1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
# File 'lib/phraseapp-ruby.rb', line 1171

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



1182
1183
1184
1185
1186
1187
1188
1189
1190
# File 'lib/phraseapp-ruby.rb', line 1182

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