Class: PhraseApp::RequestHelper

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

Instance Method Summary collapse

Constructor Details

#initialize(data_hash, post_body = nil) ⇒ RequestHelper

Returns a new instance of RequestHelper.



804
805
806
807
# File 'lib/phraseapp-ruby.rb', line 804

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

Instance Method Details

#body ⇒ Object



809
810
811
812
813
814
815
816
817
818
# File 'lib/phraseapp-ruby.rb', line 809

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

#ctype ⇒ Object



820
821
822
823
824
825
826
827
828
# File 'lib/phraseapp-ruby.rb', line 820

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