Module: Salesforce::Connection::HttpMethods::ClassMethods

Defined in:
lib/salesforce/connection/http_methods.rb

Instance Method Summary collapse

Instance Method Details

#content_type_headers(options) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# 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) ⇒ Object



24
25
26
# File 'lib/salesforce/connection/http_methods.rb', line 24

def delete(path)
  true if http(:delete, path, nil, :format => :xml)
end

#get(path, options = {}) ⇒ Object



12
13
14
# File 'lib/salesforce/connection/http_methods.rb', line 12

def get(path, options = {})
  http(:get, path, nil, options)
end

#headers(options = {}) ⇒ Object



8
9
10
# 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) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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 = {}) ⇒ Object



16
17
18
# File 'lib/salesforce/connection/http_methods.rb', line 16

def patch(path, body, options = {})
  http(:patch, path, body, options)
end

#post(path, body, options = {}) ⇒ Object



20
21
22
# File 'lib/salesforce/connection/http_methods.rb', line 20

def post(path, body, options = {})
  http(:post, path, body, options)
end

#salesforce_url(path) ⇒ Object



28
29
30
31
32
33
34
# 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