Class: Request

Inherits:
Object
  • Object
show all
Defined in:
lib/mernis/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(id_number, first_name, last_name, birth_year, version, open_timeout, read_timeout, log, wsdl) ⇒ Request

Initialize params.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mernis/request.rb', line 7

def initialize(id_number, first_name, last_name, birth_year, version, open_timeout, read_timeout, log, wsdl)
  @id_number = id_number
  @first_name = first_name
  @last_name = last_name
  @birth_year = birth_year
  @version = version
  @open_timeout = open_timeout
  @read_timeout = read_timeout
  @log = log
  @wsdl = wsdl
end

Instance Method Details

#sorgulaObject

Initialize the SOAP client



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
# File 'lib/mernis/request.rb', line 20

def sorgula
  kps_client = Savon.client(
    wsdl: @wsdl,
    soap_version: @version,
    open_timeout: @open_timeout,
    read_timeout: @read_timeout,
    log: @log
  )

  # Create message pattern
  message = {
    'TCKimlikNo' => @id_number.to_s,
    'Ad' => UnicodeUtils.upcase(@first_name, :tr),
    'Soyad' => UnicodeUtils.upcase(@last_name, :tr),
    'DogumYili' => @birth_year.to_s
  }

  # Make the SOAP request and handle errors.
  begin
    response = kps_client.call(:tc_kimlik_no_dogrula, message: message)
  rescue Savon::SOAPFault => error
    puts "SOAP fault. Error: #{error}"
  rescue Savon::HTTPError => error
    puts "HTTP connection error. Error: #{error}"
  end

  # Get the SOAP response and handle errors.
  begin
    bool_value = response.body[:tc_kimlik_no_dogrula_response][:tc_kimlik_no_dogrula_result]
    return bool_value
  rescue NoMethodError => error
    if response.nil?
      puts "Errors occured. Response is nil! Error: #{error}"
    else
      puts "There is an error with the response. Error: #{error}"
    end
  rescue Savon::InvalidResponseError => error
    puts "Not a valid response! Error: #{error}"
  end
end