-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathruby_send.rb
105 lines (99 loc) · 3.38 KB
/
ruby_send.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
require 'rest-client'
LOG_DIR ='c:\\inetpub\\wwwroot\\log\\'
PPT_DIR ='c:\\inetpub\\wwwroot\\preview\\ppt\\'
PPT_PARAMS_FILE ='ppt_params.json'
RESTCLIENT_LOG=$stdout #--$stdout
#RestClient.log=LOG_DIR+'send_sf.txt' #--$stdout
#
#sessionId = "00DG0000000CkUd!AQ0AQMJuKV_pdLZnWukptDBZi.OK9Cv1u9s8Djf8TIyVzgwRWy4ue5rVqZqManjWbuOVDtKXjCYs_pzUH9pDe3s4F7x4h_va"
#send_url='https://c.na11.visual.force.com/apex/test'
#ppt_state_str="done;sliders_cnt=63"
#send_res = RestClient.post(
# send_url,
# {:state => ppt_state_str},
# {:cookies => {:sessionId => sessionId}}
#)
#RestClient.log << send_res.code
#RestClient.log << send_res.body
class SFSender
def initialize
require 'logger'
@@log=Logger.new(LOG_DIR+'logsend.log')
@@log.level = Logger::INFO
@@send_url='https://na11.salesforce.com/services/Soap/class/HelperClass'
@@schema_url='http://soap.sforce.com/schemas/class/HelperClass'
@@ppt_session_id='00DG0000000CkUd!AQ0AQGm6koOyXnC8wEqRnUPgNXCl2d14HDwKJmsOovS0QC0On9eIr7F0kijnFUJI0A9oi5I_ewziKnewkLpFDQQtv2kV6DYC'
@@org_id='00DG0000000CkUdMAK'
@@app_id='a01G000000BRpLFIA2'
@@sliders_cnt=12
end
#-----------------------getSoapXml--------------------
def getSoapXml
s_id = @@ppt_session_id
soap_url= @@schema_url #--http://soap.sforce.com/schemas/class/HelperClass
cur_sliders_cnt=@@sliders_cnt
cur_app_id=@@app_id
tpl=%{
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="#{soap_url}">
<soapenv:Header>
<hel:AllowFieldTruncationHeader>
<hel:allowFieldTruncation>0</hel:allowFieldTruncation>
</hel:AllowFieldTruncationHeader>
<hel:CallOptions>
<hel:client>27.0</hel:client>
</hel:CallOptions>
<hel:SessionHeader>
<hel:sessionId>#{s_id}</hel:sessionId>
</hel:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<hel:presentationUploaded>
<hel:sliders_cnt>#{cur_sliders_cnt}</hel:sliders_cnt>
<hel:app_id>#{cur_app_id}</hel:app_id>
</hel:presentationUploaded>
</soapenv:Body>
</soapenv:Envelope>
}
end
#------------------------extract ppt params----------
def extractPptParams
content=File.read(PPT_DIR+@@org_id+'/'+@@app_id+'/'+PPT_PARAMS_FILE)
unless content.empty?
require 'json'
#--extract json string from content
ppt_params=JSON.parse(content)
end
@@send_url=ppt_params['send_url']
@@ppt_session_id=ppt_params['ppt_session_id']
rescue RuntimeError => error
@@log.info('Extract PptParams ERROR '+error.inspect)
end
#------------------------send state-------------------
def sendState
####extractPptParams()
require 'rest-client'
RestClient.log=LOG_DIR+'send_sf.txt' #--$stdout
#send_url='https://c.na11.visual.force.com/apex/test'
post_data=getSoapXml()
#---ENV['PERL_LWP_SSL_VERIFY_HOSTNAME']=0;
send_res = RestClient.post(
@@send_url,
post_data,{
"content-type" => "text/xml;charset=\"utf-8\"",
"Accept" =>"text/xml",
"Cache-Control" => "no-cache",
"Pragma" =>"no-cache",
"SOAPAction" =>"\"Run\"",
"Content-length" =>post_data.size,
"verify_ssl" => 0,
"verify_host" => 0
}
)
RestClient.log << send_res.code
RestClient.log << send_res.body
rescue RuntimeError => error
@@log.info('Send ERROR '+error.inspect)
end
end #--class
sf=SFSender.new
sf.sendState