Module: Cetustek::Soap

Overview

Shared SOAP plumbing: every operation hits the same WSDL and authenticates with 網站代碼+APIPassword (source) and the 租賃者統編 (rentid).

Constant Summary collapse

TIMEOUT =
300

Instance Method Summary collapse

Instance Method Details

#faraday_clientObject

savon 2.17 的 FaradayMigrationHint::OPTIONS 會讓 open_timeout/read_timeout 在 transport: :faraday 下直接 raise,逾時改由 faraday 連線自己設。



23
24
25
26
27
28
29
# File 'lib/cetustek/soap.rb', line 23

def faraday_client
  require 'faraday'
  Savon.client(wsdl: Cetustek.config.url, transport: :faraday).tap do |client|
    client.faraday.options.open_timeout = TIMEOUT
    client.faraday.options.read_timeout = TIMEOUT
  end
end

#httpi_clientObject



17
18
19
# File 'lib/cetustek/soap.rb', line 17

def httpi_client
  Savon.client(wsdl: Cetustek.config.url, open_timeout: TIMEOUT, read_timeout: TIMEOUT)
end

#rentidObject



35
36
37
# File 'lib/cetustek/soap.rb', line 35

def rentid
  Cetustek.config.username
end

#soap_call(operation, message) ⇒ Object



39
40
41
# File 'lib/cetustek/soap.rb', line 39

def soap_call(operation, message)
  soap_client.call(operation, message: message.merge(source: source, rentid: rentid))
end

#soap_clientObject



11
12
13
14
15
# File 'lib/cetustek/soap.rb', line 11

def soap_client
  return httpi_client unless Cetustek.config.transport == :faraday

  faraday_client
end

#soap_return(response, operation) ⇒ Object



43
44
45
# File 'lib/cetustek/soap.rb', line 43

def soap_return(response, operation)
  response.body[:"#{operation}_response"][:return]
end

#sourceObject



31
32
33
# File 'lib/cetustek/soap.rb', line 31

def source
  Cetustek.config.site_id + Cetustek.config.password
end