class Omniva::API::Client

Public Class Methods

call(data = nil) click to toggle source
# File lib/omniva/api/client.rb, line 6
def self.call(data = nil)
  validate_config
  data ||= initial_request
  client = Savon.client do
    wsdl Omniva::API.config[:wsdl]
    open_timeout Omniva::API.config[:timeout].to_i
    read_timeout Omniva::API.config[:timeout].to_i
  end
  auth = { authPhrase: Omniva::API.config[:key] }
  response = client.call :single_address1, attributes: auth, message: data
  parse_response(response)
end
initial_request() click to toggle source
# File lib/omniva/api/client.rb, line 40
def self.initial_request
  { nimetus: 'Eesti' }
end
parse_response(response) click to toggle source
# File lib/omniva/api/client.rb, line 31
def self.parse_response(response)
  unwrapped =
    response
    .to_hash
    .fetch(:single_address_response)
    .fetch(:aadress_komponent_nimekiri)
  unwrapped ? unwrapped.fetch(:aadress_komponent) : {}
end
validate_config() click to toggle source
# File lib/omniva/api/client.rb, line 19
def self.validate_config
  messages = {
    wsdl: 'WSDL is missing',
    key: 'Key is missing',
    timeout: 'Timeout is missing'
  }

  messages.each do |key, value|
    fail InvalidConfiguration, value if Omniva::API.config[key].blank?
  end
end