Skip to content

Commit

Permalink
Add support for querying foreigner registry
Browse files Browse the repository at this point in the history
  • Loading branch information
krmbzds committed Nov 8, 2024
1 parent fb737d0 commit 8fad5b8
Show file tree
Hide file tree
Showing 5 changed files with 462 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ identity_number.registered?("Ahmet", "Yılmaz", 1987) #=> false

There is also a convenience method called `not_in_registry?` which is the logical equivalent of `!registered?`.

Use ```foreigner_registered?``` method to query the foreigner registry:

```rb
identity_number.foreigner_registered?("Yukihiro", "Matsumoto", 14, 4, 1965) #=> false
```

There is also a convenience method called `foreigner_not_in_registry?` which is the logical equivalent of `!foreigner_registered?`.

### Generating Relatives

You can generate ID numbers for your younger or elder relatives.
Expand Down Expand Up @@ -177,7 +185,7 @@ Yes.

## License

Copyright © 2015-2023 [Kerem Bozdas][Personal Webpage]
Copyright © 2015-2024 [Kerem Bozdas][Personal Webpage]

This gem is available under the terms of the [MIT License][License].

Expand Down
27 changes: 27 additions & 0 deletions lib/turkish_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def not_in_registry?(given_name, surname, year_of_birth)
!valid? || !query_government_registry(given_name, surname, year_of_birth)
end

def foreigner_registered?(given_name, surname, year_of_birth, month_of_birth, day_of_birth)
valid? && query_foreigner_registry(given_name, surname, year_of_birth, month_of_birth, day_of_birth)
end

def foreigner_not_in_registry?(given_name, surname, day_of_birth, month_of_birth, year_of_birth)
!valid? || !query_foreigner_registry(given_name, surname, day_of_birth, month_of_birth, year_of_birth)
end

private

def calculate_checksum(id_array)
Expand Down Expand Up @@ -99,4 +107,23 @@ def query_government_registry(given_name, surname, year_of_birth)
rescue TypeError, ArgumentError, NoMethodError
false
end

def query_foreigner_registry(given_name, surname, day_of_birth, month_of_birth, year_of_birth)
return false unless Integer(day_of_birth).between?(1, 31)
return false unless Integer(month_of_birth).between?(1, 12)

client = Savon.client(wsdl: "https://tckimlik.nvi.gov.tr/Service/KPSPublicYabanciDogrula.asmx?WSDL")
response = client.call(:yabanci_kimlik_no_dogrula, message: {
"KimlikNo" => join_num(@id_number),
"Ad" => given_name.upcase(:turkic),
"Soyad" => surname.upcase(:turkic),
"DogumGun" => String(Integer(day_of_birth)),
"DogumAy" => String(Integer(month_of_birth)),
"DogumYil" => String(Date.new(Integer(year_of_birth)).year)
})

response.body.dig(:yabanci_kimlik_no_dogrula_response, :yabanci_kimlik_no_dogrula_result).is_a?(TrueClass)
rescue TypeError, ArgumentError, NoMethodError
false
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8fad5b8

Please sign in to comment.