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.



1423
1424
1425
1426
# File 'lib/phraseapp-ruby.rb', line 1423

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

Instance Method Details

#bodyObject



1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
# File 'lib/phraseapp-ruby.rb', line 1428

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



1439
1440
1441
1442
1443
1444
1445
1446
1447
# File 'lib/phraseapp-ruby.rb', line 1439

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