Class: HooplaSalesforce::Deployer
- Inherits:
-
Object
- Object
- HooplaSalesforce::Deployer
- Defined in:
- lib/hoopla_salesforce/deployer.rb
Overview
Deploys and retreives zip files from salesforce using the metadata API. Use ENV = ‘test.salesforce.com’ to use this on sandbox organizations.
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#header ⇒ Object
Returns the value of attribute header.
-
#metaclient ⇒ Object
Returns the value of attribute metaclient.
-
#password ⇒ Object
Returns the value of attribute password.
-
#token ⇒ Object
Returns the value of attribute token.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #build_clients ⇒ Object
- #deploy(zipfile, options = {}) ⇒ Object
- #error_out ⇒ Object
-
#initialize(username, password, token, enterprise_wsdl, metadata_wsdl) ⇒ Deployer
constructor
A new instance of Deployer.
- #login ⇒ Object
- #retrieve(request) ⇒ Object
- #set_certs ⇒ Object
- #setup_metaclient_and_store_header ⇒ Object
Constructor Details
#initialize(username, password, token, enterprise_wsdl, metadata_wsdl) ⇒ Deployer
Returns a new instance of Deployer.
16 17 18 19 20 21 22 |
# File 'lib/hoopla_salesforce/deployer.rb', line 16 def initialize(username, password, token, enterprise_wsdl, ) @username = username @password = password @token = token @enterprise_wsdl = enterprise_wsdl @metadata_wsdl = end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
13 14 15 |
# File 'lib/hoopla_salesforce/deployer.rb', line 13 def client @client end |
#header ⇒ Object
Returns the value of attribute header.
13 14 15 |
# File 'lib/hoopla_salesforce/deployer.rb', line 13 def header @header end |
#metaclient ⇒ Object
Returns the value of attribute metaclient.
13 14 15 |
# File 'lib/hoopla_salesforce/deployer.rb', line 13 def @metaclient end |
#password ⇒ Object
Returns the value of attribute password.
13 14 15 |
# File 'lib/hoopla_salesforce/deployer.rb', line 13 def password @password end |
#token ⇒ Object
Returns the value of attribute token.
13 14 15 |
# File 'lib/hoopla_salesforce/deployer.rb', line 13 def token @token end |
#username ⇒ Object
Returns the value of attribute username.
13 14 15 |
# File 'lib/hoopla_salesforce/deployer.rb', line 13 def username @username end |
Instance Method Details
#build_clients ⇒ Object
30 31 32 33 |
# File 'lib/hoopla_salesforce/deployer.rb', line 30 def build_clients @client = Savon::Client.new @enterprise_wsdl @metaclient = Savon::Client.new @metadata_wsdl end |
#deploy(zipfile, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/hoopla_salesforce/deployer.rb', line 52 def deploy(zipfile, = {}) login data = Base64.encode64(File.read(zipfile)) response = .deploy do |soap, wsse| soap.header = header soap.body = { "wsdl:ZipFile" => data, "wsdl:DeployOptions" => , :order! => ['wsdl:ZipFile', 'wsdl:DeployOptions'] } end.to_hash[:deploy_response][:result] puts "Deployment requested, awaiting completion of job #{response[:id]}..." while !response[:done] begin response = .check_status do |soap, wsse| soap.header = header soap.body = { "wsdl:asyncProcessId" => response[:id] } end.to_hash[:check_status_response][:result] rescue Timeout::Error end end response = .check_deploy_status do |soap, wsse| soap.header = header soap.body = { "wsdl:asyncProcessId" => response[:id] } end.to_hash[:check_deploy_status_response][:result] error_out unless TextReporter.new(response).report end |
#error_out ⇒ Object
84 85 86 |
# File 'lib/hoopla_salesforce/deployer.rb', line 84 def error_out raise "Deployment errors. See report for details." end |
#login ⇒ Object
24 25 26 27 28 |
# File 'lib/hoopla_salesforce/deployer.rb', line 24 def login build_clients set_certs end |
#retrieve(request) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/hoopla_salesforce/deployer.rb', line 88 def retrieve(request) login response = .retrieve do |soap, wsse| soap.header = @header soap.body = { "wsdl:retrieveRequest" => request } end.to_hash[:retrieve_response][:result] puts "Retrieve requested, awaiting completion of job #{response[:id]}..." while !response[:done] response = .check_status do |soap, wsse| soap.header = @header soap.body = { "wsdl:asyncProcessId" => response[:id] } end.to_hash[:check_status_response][:result] end response = .check_retrieve_status do |soap, wsse| soap.header = @header soap.body = { "wsdl:asyncProcessId" => response[:id] } end.to_hash[:check_retrieve_status_response][:result] File.open('retrieved.zip', 'w') { |f| f.print Base64.decode64(response[:zip_file]) } puts "Wrote retrieved contents to retrieved.zip." end |
#set_certs ⇒ Object
35 36 37 38 |
# File 'lib/hoopla_salesforce/deployer.rb', line 35 def set_certs # TODO figure out how to get Savon to validate SF's cert [@client, @metaclient].each { |c| c.request.http.ssl_client_auth(:verify_mode => OpenSSL::SSL::VERIFY_NONE) } end |
#setup_metaclient_and_store_header ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hoopla_salesforce/deployer.rb', line 40 def client.wsdl.soap_endpoint.host = ENV['LOGIN_HOST'] if ENV['LOGIN_HOST'] response = client.login do |soap, wsse| soap.body = { "wsdl:username" => username, "wsdl:password" => password + token} end.to_hash[:login_response][:result] .wsdl.soap_endpoint = response[:metadata_server_url] @header = { "wsdl:SessionHeader" => { "wsdl:sessionId" => response[:session_id] } } end |