Module: SalesforceHttpClient::SalesforceHttpAccess
- Included in:
- Client
- Defined in:
- lib/salesforce_http_client/salesforce_http_access.rb
Instance Attribute Summary collapse
-
#http_client ⇒ Object
Returns the value of attribute http_client.
Instance Method Summary collapse
- #create_http_client ⇒ Object
- #download_and_save_report(report_id, output_save_path) ⇒ Object
- #download_from_salesforce(output_save_path, report_id) ⇒ Object
- #respond_to_redirect(response) ⇒ Object
- #salesforce_login ⇒ Object
- #salesforce_logout ⇒ Object
- #save_report(response, output_save_path) ⇒ Object
Instance Attribute Details
#http_client ⇒ Object
Returns the value of attribute http_client.
3 4 5 |
# File 'lib/salesforce_http_client/salesforce_http_access.rb', line 3 def http_client @http_client end |
Instance Method Details
#create_http_client ⇒ Object
12 13 14 15 16 17 |
# File 'lib/salesforce_http_client/salesforce_http_access.rb', line 12 def create_http_client @http_client = HTTPClient.new @http_client.receive_timeout = @config.http_timeout @http_client.(@config.) @http_client end |
#download_and_save_report(report_id, output_save_path) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/salesforce_http_client/salesforce_http_access.rb', line 34 def download_and_save_report(report_id, output_save_path) @logger.info "begin download reports" response = @http_client.get report_url(report_id) if response.status == 200 save_report(response, output_save_path) else @logger.error "failed to download reports." end end |
#download_from_salesforce(output_save_path, report_id) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/salesforce_http_client/salesforce_http_access.rb', line 5 def download_from_salesforce(output_save_path, report_id) create_http_client salesforce_login download_and_save_report(report_id, output_save_path) salesforce_logout end |
#respond_to_redirect(response) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/salesforce_http_client/salesforce_http_access.rb', line 27 def respond_to_redirect(response) while response.status == 302 && response.headers['Location'] && !response.headers['Location'].empty? @logger.info "redirect to #{response.headers['Location']}" response = @http_client.get(response.headers['Location']) end end |
#salesforce_login ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/salesforce_http_client/salesforce_http_access.rb', line 19 def salesforce_login @logger.info "try salesforce login..." @http_client.get config.salesforce_login_url body = { 'un' => @config.salesforce_login_id, 'pw' => @config.salesforce_password } response = @http_client.post(config.salesforce_login_url, body) respond_to_redirect(response) end |
#salesforce_logout ⇒ Object
53 54 55 56 57 |
# File 'lib/salesforce_http_client/salesforce_http_access.rb', line 53 def salesforce_logout @logger.info "try salesforce logout..." @http_client.get config.logout_url @logger.info "salesforce logged out." end |
#save_report(response, output_save_path) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/salesforce_http_client/salesforce_http_access.rb', line 44 def save_report(response, output_save_path) report_content = response.content report_file = output_save_path @logger.info "save result to file #{report_file}" FileUtils.mkdir_p(File.dirname(report_file)) File.write(report_file, report_content) end |