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.



1311
1312
1313
1314
# File 'lib/phraseapp-ruby.rb', line 1311

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

Instance Method Details

#bodyObject



1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
# File 'lib/phraseapp-ruby.rb', line 1316

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



1327
1328
1329
1330
1331
1332
1333
1334
1335
# File 'lib/phraseapp-ruby.rb', line 1327

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