turkish_id 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4dbab23fd1a1c8ee8c67c3630a171a135bed41bce82708dc6c03c42b61651bf3
4
- data.tar.gz: '0385cf9eb915caf2a0f8c41cb3663e7bdb2c9b50d17b8915f6fc2e1416eab8f8'
3
+ metadata.gz: b6f16411294196075f7ddc2420a83b1073bca92bbcbf08d872afd22c88de0198
4
+ data.tar.gz: 3a340241b1446a80046e1b3f62ceaffb77d7ed37ff37c4343bfeb7c2fa236ab3
5
5
  SHA512:
6
- metadata.gz: 39f88acd307c6a3ac8d5c446cad44ed78a5fb7f998d8fdd4223c5550705880d67d617ed106f1465de98fb9c3c92415e72901b5ce8582fe3a04d80502f8c1402e
7
- data.tar.gz: 6fa037e2073337069638a364f2a8277f48d50630a0bd80f46a43a5ef49bd674b5226dcfa941dd59d02c7c43466a8b6403be4288df33ad3403fbd748b04f6497a
6
+ metadata.gz: ab688e6d2faf494f3ddcfb3f24d26840d9231dae8639af97145d39408658919140ef52dfbab5d583596517801232ff5b6e4c49aa2bf200be777ec7acf941fd04
7
+ data.tar.gz: f9d19b0cf457aa1f257c8547ac9122ae4293b66aa875945f604c569bcdfe1955d4a5f07eed26f751d6252b528ca7eef4d7ba1fd3d73078b395d773ec69606e4e
@@ -4,7 +4,7 @@ on:
4
4
  pull_request:
5
5
 
6
6
  push:
7
- branches: [ develop, master ]
7
+ branches: [develop, master]
8
8
 
9
9
  env:
10
10
  GIT_COMMIT_SHA: ${{ github.sha }}
@@ -12,14 +12,13 @@ env:
12
12
  COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
13
13
 
14
14
  jobs:
15
-
16
15
  lint:
17
16
  runs-on: ubuntu-latest
18
17
  name: lint ${{ matrix.ruby }}
19
18
  strategy:
20
19
  fail-fast: false
21
20
  matrix:
22
- ruby: [ '2.6.9', '2.7.5', '3.0.3', '3.1.1' ]
21
+ ruby: ["2.7.8", "3.0.6", "3.1.4", "3.2.2"]
23
22
 
24
23
  steps:
25
24
  - uses: actions/checkout@v2
@@ -33,13 +32,13 @@ jobs:
33
32
  run: bundle exec standardrb --parallel --format progress
34
33
 
35
34
  test:
36
- needs: [ lint ]
35
+ needs: [lint]
37
36
  runs-on: ubuntu-latest
38
37
  name: test ${{ matrix.ruby }}
39
38
  strategy:
40
39
  fail-fast: false
41
40
  matrix:
42
- ruby: [ '2.6.9', '2.7.5', '3.0.3', '3.1.1' ]
41
+ ruby: ["2.7.8", "3.0.6", "3.1.4", "3.2.2"]
43
42
 
44
43
  steps:
45
44
  - uses: actions/checkout@v2
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.1.1
1
+ ruby 3.2.2
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2022 Kerem Bozdas
3
+ Copyright (c) 2015-2023 Kerem Bozdas
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Turkish ID 🔖
2
2
 
3
- [![Status](https://img.shields.io/github/workflow/status/krmbzds/turkish_id/Test/master)](https://github.com/krmbzds/turkish_id/actions/workflows/test.yml)
3
+ [![Status](https://img.shields.io/github/actions/workflow/status/krmbzds/turkish_id/test.yml?branch=master)](https://github.com/krmbzds/turkish_id/actions/workflows/test.yml)
4
4
  [![Coverage](https://img.shields.io/coveralls/github/krmbzds/turkish_id)](https://coveralls.io/github/krmbzds/turkish_id)
5
5
  [![Downloads](https://img.shields.io/gem/dt/turkish_id.svg)](https://rubygems.org/gems/turkish_id)
6
- [![Dependencies](https://img.shields.io/badge/dependencies-none-brightgreen.svg)](https://rubygems.org/gems/turkish_id)
6
+ [![Dependencies](https://img.shields.io/badge/dependencies-1-yellowgreen.svg)](https://rubygems.org/gems/turkish_id)
7
7
  [![Maintainability](https://img.shields.io/codeclimate/maintainability/krmbzds/turkish_id)](https://codeclimate.com/github/krmbzds/turkish_id)
8
8
  [![Version](https://img.shields.io/gem/v/turkish_id.svg)](https://github.com/krmbzds/turkish_id)
9
9
  [![Docs](https://img.shields.io/badge/rubydoc-info-blue.svg)](https://www.rubydoc.info/gems/turkish_id)
@@ -42,13 +42,18 @@ Use ```valid?``` method to check validity:
42
42
  identity_number.valid? #=> true
43
43
  ```
44
44
 
45
- Or use the command line executable:
45
+ ### Querying the Government Registry
46
46
 
47
- ```sh
48
- $ turkish_id 10000000078 #=> true
49
- $ echo $? #=> 0
50
- $ turkish_id 10000000079 #=> false
51
- $ echo $? #=> 1
47
+ Create a new instance:
48
+
49
+ ```rb
50
+ identity_number = TurkishId.new(10000000146)
51
+ ```
52
+
53
+ Use ```registered?``` method to query the government registry:
54
+
55
+ ```rb
56
+ identity_number.registered?("Ahmet", "Yılmaz", 1987) #=> false
52
57
  ```
53
58
 
54
59
  ### Generating Relatives
@@ -87,6 +92,40 @@ me.elder_relative.take(5) #=> [10003000082, 10005999902, 10008999848, 100119997
87
92
 
88
93
  And so on.
89
94
 
95
+ ## CLI (Command Line Interface)
96
+
97
+ You can use the CLI for quick lookups:
98
+
99
+ ```sh
100
+ $ turkish_id 10000000078 #=> true
101
+ ```
102
+
103
+ The executable terminates with a proper [exit status](https://en.wikipedia.org/wiki/Exit_status):
104
+
105
+ ```sh
106
+ $ turkish_id 10000000078 #=> true
107
+ $ echo $? #=> 0
108
+ $ turkish_id 10000000079 #=> false
109
+ $ echo $? #=> 1
110
+ ```
111
+
112
+ Run `turkish_id --help` to learn more:
113
+
114
+ ```groff
115
+ Usage
116
+ turkish_id ID_NUMBER [GIVEN_NAME SURNAME YEAR_OF_BIRTH]
117
+
118
+ Description
119
+ turkish_id validates Turkish identity numbers.
120
+ Only providing ID_NUMBER performs numerical validation (offline).
121
+ Providing all arguments will query government registry (online).
122
+
123
+ Examples
124
+ turkish_id 10000000078
125
+ turkish_id 10000000146 Ahmet Yılmaz 1984
126
+ turkish_id 10005999902 "Ayşe Nur" Yılmaz 1996
127
+ ```
128
+
90
129
  ## Anatomy of the Turkish ID Number
91
130
 
92
131
  The Turkish Identification Number consists of ```11``` digits.
@@ -99,7 +138,7 @@ There are three conditions for a valid identification number:
99
138
 
100
139
  Where ```dn``` refers to the ```n-th``` digit of the identification number.
101
140
 
102
- Remember that a valid identification number does not imply the existence of an ID. It could only be used as a preliminary check e.g. before querying a government website. This is very similar to credit card validation.
141
+ Remember that a valid identification number does not imply the existence of an ID. It could only be used as a preliminary check e.g. before [querying a government website](#querying-the-government-registry). This is very similar to credit card validation.
103
142
 
104
143
  ## Support
105
144
 
@@ -107,10 +146,10 @@ Remember that a valid identification number does not imply the existence of an I
107
146
 
108
147
  This gem is used in production and tested against the following Ruby versions:
109
148
 
110
- - ✅ `3.1.1` (stable)
111
- - ✅ `3.0.3` (stable)
112
- - `2.7.5` (stable)
113
- - `2.6.9` (security maintenance)
149
+ - ✅ `3.2.2` (stable)
150
+ - ✅ `3.1.4` (stable)
151
+ - `3.0.6` (security maintenance)
152
+ - 🪦 `2.7.8` (end of life)
114
153
 
115
154
  ## Development
116
155
 
@@ -136,7 +175,7 @@ Yes.
136
175
 
137
176
  ## License
138
177
 
139
- Copyright © 2015-2022 [Kerem Bozdas][Personal Webpage]
178
+ Copyright © 2015-2023 [Kerem Bozdas][Personal Webpage]
140
179
 
141
180
  This gem is available under the terms of the [MIT License][License].
142
181
 
data/bin/turkish_id CHANGED
@@ -5,21 +5,41 @@ lib = File.expand_path(File.dirname(__FILE__) + "/../lib")
5
5
  $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
6
6
 
7
7
  require "turkish_id"
8
+ require "turkish_id/version"
8
9
 
9
- @help = '
10
+ HELP = '
10
11
  Usage
11
- turkish_id QUERY
12
+ turkish_id ID_NUMBER [GIVEN_NAME SURNAME YEAR_OF_BIRTH]
13
+
14
+ Description
15
+ turkish_id validates Turkish identity numbers.
16
+ Only providing ID_NUMBER performs numerical validation (offline).
17
+ Providing all arguments will query government registry (online).
12
18
 
13
19
  Examples
14
20
  turkish_id 10000000078
15
- turkish_id 10000000146
21
+ turkish_id 10000000146 Ahmet Yılmaz 1984
22
+ turkish_id 10005999902 "Ayşe Nur" Yılmaz 1996
16
23
 
17
24
  '
18
25
 
19
- if ARGV[0]
20
- result = TurkishId.new(ARGV[0]).valid?
21
- $stdout.puts result
22
- exit result ? 0 : 1
23
- else
24
- $stdout.puts @help
26
+ result =
27
+ case ARGV.length
28
+ when 1 then TurkishId.new(ARGV[0]).valid?
29
+ when 4 then TurkishId.new(ARGV[0]).registered?(ARGV[1], ARGV[2], ARGV[3])
30
+ else $stdout.puts HELP
31
+ exit 1
32
+ end
33
+
34
+ if ["-?", "-h", "--help", "--usage"].include?(ARGV[0])
35
+ $stdout.puts HELP
36
+ exit 1
25
37
  end
38
+
39
+ if ["-v", "-V", "--version"].include?(ARGV[0])
40
+ $stdout.puts TurkishId::VERSION
41
+ exit 0
42
+ end
43
+
44
+ $stdout.puts result
45
+ exit result ? 0 : 1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TurkishId
4
- VERSION = "1.4.0"
4
+ VERSION = "1.5.0"
5
5
  end
data/lib/turkish_id.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "turkish_id/version"
4
+ require "savon"
4
5
 
5
6
  class TurkishId
6
7
  attr_reader :id_number, :checksum, :elder_relative, :younger_relative
@@ -19,6 +20,10 @@ class TurkishId
19
20
  true
20
21
  end
21
22
 
23
+ def registered?(given_name, surname, year_of_birth)
24
+ valid? && query_government_registry(given_name, surname, year_of_birth)
25
+ end
26
+
22
27
  private
23
28
 
24
29
  def calculate_checksum(id_array)
@@ -76,4 +81,18 @@ class TurkishId
76
81
  def get_core(id_array)
77
82
  join_num(split_num(id_array).take(9))
78
83
  end
84
+
85
+ def query_government_registry(given_name, surname, year_of_birth)
86
+ client = Savon.client(wsdl: "https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx?WSDL")
87
+ response = client.call(:tc_kimlik_no_dogrula, message: {
88
+ "TCKimlikNo" => join_num(@id_number),
89
+ "Ad" => given_name.upcase(:turkic),
90
+ "Soyad" => surname.upcase(:turkic),
91
+ "DogumYili" => String(Date.new(Integer(year_of_birth)).year)
92
+ })
93
+
94
+ response.body.dig(:tc_kimlik_no_dogrula_response, :tc_kimlik_no_dogrula_result).is_a?(TrueClass)
95
+ rescue TypeError, ArgumentError, NoMethodError
96
+ false
97
+ end
79
98
  end
data/turkish_id.gemspec CHANGED
@@ -21,8 +21,12 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib", "lib/turkish_id"]
22
22
 
23
23
  spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "coveralls_reborn"
24
25
  spec.add_development_dependency "rake"
25
26
  spec.add_development_dependency "rspec"
26
27
  spec.add_development_dependency "standard"
27
- spec.add_development_dependency "coveralls_reborn"
28
+ spec.add_development_dependency "vcr"
29
+ spec.add_development_dependency "webmock"
30
+
31
+ spec.add_runtime_dependency "savon"
28
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turkish_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kerem Bozdas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-16 00:00:00.000000000 Z
11
+ date: 2023-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls_reborn
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +81,21 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: coveralls_reborn
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
101
  - - ">="
@@ -80,6 +108,20 @@ dependencies:
80
108
  - - ">="
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: savon
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  description: Validate Turkish Identification Numbers and More!
84
126
  email:
85
127
  - krmbzds.github@gmail.com
@@ -88,7 +130,6 @@ executables:
88
130
  extensions: []
89
131
  extra_rdoc_files: []
90
132
  files:
91
- - ".github/dependabot.yml"
92
133
  - ".github/workflows/publish.yml"
93
134
  - ".github/workflows/test.yml"
94
135
  - ".gitignore"
@@ -108,7 +149,7 @@ homepage: https://github.com/krmbzds/turkish_id
108
149
  licenses:
109
150
  - MIT
110
151
  metadata: {}
111
- post_install_message:
152
+ post_install_message:
112
153
  rdoc_options: []
113
154
  require_paths:
114
155
  - lib
@@ -124,8 +165,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
165
  - !ruby/object:Gem::Version
125
166
  version: '0'
126
167
  requirements: []
127
- rubygems_version: 3.3.7
128
- signing_key:
168
+ rubygems_version: 3.4.14
169
+ signing_key:
129
170
  specification_version: 4
130
171
  summary: Validate Turkish Identification Numbers and More!
131
172
  test_files: []
@@ -1,8 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: bundler
4
- directory: "/"
5
- schedule:
6
- interval: daily
7
- time: "03:00"
8
- open-pull-requests-limit: 10