module Salesforce::Connection::HttpMethods::ClassMethods

Public Instance Methods

content_type_headers(options) click to toggle source
# File lib/salesforce/connection/http_methods.rb, line 56
def content_type_headers(options)
  {}.tap do |hash|
    hash[:content_type] = if options[:content_type]
       options[:content_type]
    elsif options[:format].to_s == 'json'
      "application/json"
    elsif options[:format].to_s == 'xml'
      "application/xml"
    end
  end
end
delete(path) click to toggle source
# File lib/salesforce/connection/http_methods.rb, line 24
def delete(path)
  true if http(:delete, path, nil, :format => :xml)
end
get(path, options = {}) click to toggle source
# File lib/salesforce/connection/http_methods.rb, line 12
def get(path, options = {})
  http(:get, path, nil, options)
end
headers(options = {}) click to toggle source
# File lib/salesforce/connection/http_methods.rb, line 8
def headers(options = {})
  {'Authorization' => "OAuth #{::Salesforce::Authentication.session_id}"}.merge(content_type_headers(options))
end
http(action, path, body, options) click to toggle source
# File lib/salesforce/connection/http_methods.rb, line 36
def http(action, path, body, options)
  as_logged_in_user do
    begin
      response = if body
        RestClient.send(action, salesforce_url(path), body, headers(options))
      else
        RestClient.send(action, salesforce_url(path), headers(options))
      end

      if response.body.present?
        convert_body(response, options) 
      else
        response
      end
    rescue RestClient::ResourceNotFound, RestClient::BadRequest => e
      convert_error(e, salesforce_url(path), options)
    end
  end
end
patch(path, body, options = {}) click to toggle source
# File lib/salesforce/connection/http_methods.rb, line 16
def patch(path, body, options = {})
  http(:patch, path, body, options)
end
post(path, body, options = {}) click to toggle source
# File lib/salesforce/connection/http_methods.rb, line 20
def post(path, body, options = {})
  http(:post, path, body, options)
end
salesforce_url(path) click to toggle source
# File lib/salesforce/connection/http_methods.rb, line 28
def salesforce_url(path)
  if path.include?("services/data")
    ::Salesforce::Config.server_host + path
  else
    ::Salesforce::Config.server_url + "/" + path
  end
end