Module: Salesforce::Connection::HttpMethods::ClassMethods
- Defined in:
- lib/salesforce/connection/http_methods.rb
Instance Method Summary collapse
- #content_type_headers(options) ⇒ Object
- #delete(path) ⇒ Object
- #get(path, options = {}) ⇒ Object
- #headers(options = {}) ⇒ Object
- #http(action, path, body, options) ⇒ Object
- #patch(path, body, options = {}) ⇒ Object
- #post(path, body, options = {}) ⇒ Object
- #salesforce_url(path) ⇒ Object
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() {}.tap do |hash| hash[:content_type] = if [:content_type] [:content_type] elsif [:format].to_s == 'json' "application/json" elsif [: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, = {}) http(:get, path, nil, ) end |
#headers(options = {}) ⇒ Object
8 9 10 |
# File 'lib/salesforce/connection/http_methods.rb', line 8 def headers( = {}) {'Authorization' => "OAuth #{::Salesforce::Authentication.session_id}"}.merge(content_type_headers()) 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, ) as_logged_in_user do begin response = if body RestClient.send(action, salesforce_url(path), body, headers()) else RestClient.send(action, salesforce_url(path), headers()) end if response.body.present? convert_body(response, ) else response end rescue RestClient::ResourceNotFound, RestClient::BadRequest => e convert_error(e, salesforce_url(path), ) end end end |
#patch(path, body, options = {}) ⇒ Object
16 17 18 |
# File 'lib/salesforce/connection/http_methods.rb', line 16 def patch(path, body, = {}) http(:patch, path, body, ) end |
#post(path, body, options = {}) ⇒ Object
20 21 22 |
# File 'lib/salesforce/connection/http_methods.rb', line 20 def post(path, body, = {}) http(:post, path, body, ) 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 |