cra.ge 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ *.pem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cra.ge.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Dimitri Kurashvili
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # CRA.ge
2
+
3
+ `cra.ge` is a gem for working with Georgian Civil Registry Agency web-services.
4
+
5
+ ## Configure
6
+
7
+ First of all you need to configure the gem. You need a PEM certificate file for this:
8
+
9
+ ```ruby
10
+ CRA.config.pem_file = '/home/dimakura/certificates/my-company.pem'
11
+ ```
12
+
13
+ ## Getting person information by private number
14
+
15
+ If you have person's private number (11 digits code), then you can get the last entry in CRA database,
16
+ like this:
17
+
18
+ ```ruby
19
+ private_number = '02001000490'
20
+ person_info = CRA.serv.by_personal_id(private_number) # CRA::PassportInfo
21
+ ```
22
+
23
+ ## Getting full documentation for the person
24
+
25
+ If you have first/last names of the person and know their birthdate, then it's easy to get
26
+ full list of documentation for this person:
27
+
28
+ ```ruby
29
+ fname = 'დიმიტრი'
30
+ lname = 'ყურაშვილი'
31
+ year, month, day = 1979, 4, 4
32
+ docs = CRA.serv.list_by_name_and_dob(lname, fname, year, month, day) # array of CRA::PassportInfo
33
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cra/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "cra.ge"
8
+ gem.version = CRA::VERSION
9
+ gem.authors = ["Dimitri Kurashvili"]
10
+ gem.email = ["dimitri@c12.ge"]
11
+ gem.description = %q{CRA services}
12
+ gem.summary = %q{Ruby client for C(ivil)R(egistry)A(gency) services}
13
+ gem.homepage = "http://github.com/dimakura/cra.ge"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'rspec', '~> 2.11'
21
+ gem.add_runtime_dependency 'savon', '~> 1.2'
22
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'savon'
3
+ require 'cra/version'
4
+
5
+ require 'cra/config'
6
+
7
+ module CRA
8
+ BASE_URL = 'http://stateinstitution.cra.ge'
9
+ WSDL_URL = 'https://stateinstitutions.cra.ge/Service.asmx?WSDL'
10
+
11
+ MALE = 1
12
+ FEMALE = 2
13
+
14
+ class Base
15
+
16
+ def get_client
17
+ Savon::Client.new WSDL_URL do
18
+ http.auth.ssl.cert_file = CRA.config.pem_file
19
+ http.auth.ssl.cert_key_file = CRA.config.pem_file
20
+ http.auth.ssl.verify_mode = :peer
21
+ end
22
+ end
23
+
24
+ def soap_action(name)
25
+ "#{BASE_URL}/#{name}"
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+ require 'cra/pasport_info'
33
+ require 'cra/services'
@@ -0,0 +1,17 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'singleton'
3
+
4
+ module CRA
5
+
6
+ class Config
7
+ include Singleton
8
+ attr_accessor :pem_file
9
+ end
10
+
11
+ class << self
12
+ def config
13
+ CRA::Config.instance
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,92 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'base64'
3
+
4
+ class CRA::PasportInfo
5
+
6
+ attr_accessor :doc_id, :doc_type, :doc_description, :doc_status, :doc_status_text
7
+ attr_accessor :is_id_card, :id_card_serial, :id_card_number, :id_card_issuer, :id_card_issue_date, :id_card_valid_date
8
+ attr_accessor :pasport_number, :passport_issuer, :passport_issue_date, :passport_valid_date
9
+ attr_accessor :person_id, :social_id, :private_number
10
+ attr_accessor :first_name, :last_name, :middle_name
11
+ attr_accessor :birth_date, :birth_place
12
+ attr_accessor :gender
13
+ attr_accessor :citizenship, :citizenship_code, :second_citizenship, :second_citizenship_code
14
+ attr_accessor :living_place_id, :living_place, :living_place_registration, :living_place_registration_end, :actual_living_place
15
+ attr_accessor :region_id, :region_name
16
+ attr_accessor :response_id, :response_code
17
+ attr_accessor :is_person_dead, :is_document_lost
18
+ attr_accessor :photos
19
+
20
+ def self.init_with_hash(hash)
21
+ passport = CRA::PasportInfo.new
22
+ passport.doc_id = hash[:document_id].to_i
23
+ passport.doc_type = hash[:document_type_id].to_i
24
+ passport.doc_description = hash[:document_description]
25
+ passport.doc_status = hash[:document_status_enum]
26
+ passport.doc_status_text = hash[:document_status_str]
27
+ passport.is_id_card = hash[:is_id_card]
28
+ passport.id_card_serial = hash[:id_card_serial]
29
+ passport.id_card_number = hash[:id_card_number]
30
+ passport.id_card_issuer = hash[:id_card_issuer]
31
+ passport.id_card_issue_date = hash[:id_card_issue_date]
32
+ passport.id_card_valid_date = hash[:id_card_valid_date]
33
+ passport.pasport_number = hash[:pasport_number]
34
+ passport.passport_issuer = hash[:passport_issuer]
35
+ passport.passport_issue_date = hash[:passport_issue_date]
36
+ passport.passport_valid_date = hash[:passport_valid_date]
37
+ passport.person_id = hash[:person_id].to_i
38
+ passport.social_id = hash[:social_id].to_i
39
+ passport.private_number = hash[:private_number]
40
+ passport.first_name = hash[:first_name]
41
+ passport.last_name = hash[:last_name]
42
+ passport.middle_name = hash[:middle_name]
43
+ passport.birth_date = hash[:birth_date]
44
+ passport.birth_place = hash[:birth_place]
45
+ passport.gender = hash[:gender].to_i
46
+ passport.citizenship = hash[:citizenship]
47
+ passport.citizenship_code = hash[:citizenship_code]
48
+ passport.second_citizenship = hash[:double_citizenship]
49
+ passport.second_citizenship_code = hash[:double_citizenship_code]
50
+ passport.living_place_id = hash[:living_place_id].to_i
51
+ passport.living_place = hash[:living_place]
52
+ passport.actual_living_place = hash[:fa_living_place]
53
+ passport.living_place = passport.living_place.split(' ').join(' ') if passport.living_place
54
+ passport.actual_living_place = passport.actual_living_place.split(' ').join(' ') if passport.actual_living_place
55
+ passport.living_place_registration = hash[:living_place_reg_date]
56
+ passport.living_place_registration_end = hash[:living_place_reg_end_date]
57
+ passport.region_id = hash[:region_id].to_i
58
+ passport.region_name = hash[:region_str_]
59
+ passport.response_id = hash[:response_id].to_i
60
+ passport.is_person_dead = hash[:is_person_dead]
61
+ passport.is_document_lost = hash[:is_document_lost]
62
+ passport.photos = []
63
+ if hash[:photos].is_a?(Array)
64
+ hash[:photos].each do |photo|
65
+ passport.photos.push(photo[:base64_binary])
66
+ end
67
+ else
68
+ passport.photos.push(hash[:photos][:base64_binary])
69
+ end
70
+ passport
71
+ end
72
+
73
+ def full_name(opts = {})
74
+ if opts[:with_middle_name]
75
+ "#{first_name} #{last_name} #{middle_name}"
76
+ else
77
+ "#{first_name} #{last_name}"
78
+ end
79
+ end
80
+
81
+ # Returns binary content of the photo.
82
+ def binary(index)
83
+ Base64.decode64(self.photos[index])
84
+ end
85
+
86
+ def write_photo(index, file = nil)
87
+ File.open(file || 'photo', 'wb') do |file|
88
+ file.write self.binary(index)
89
+ end
90
+ end
91
+
92
+ end
@@ -0,0 +1,83 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'singleton'
3
+
4
+ module CRA
5
+
6
+ class Services < CRA::Base
7
+ include Singleton
8
+
9
+ # Get service consumer UPN.
10
+ def my_upn
11
+ action_name = 'GetMyUPN'
12
+ soap_action = self.soap_action(action_name)
13
+ response = get_client.request action_name do
14
+ http.headers['SOAPAction'] = soap_action
15
+ end
16
+ response.to_hash[:get_my_upn_response][:get_my_upn_result]
17
+ end
18
+
19
+ # Getting personal information by personal number.
20
+ def by_personal_id(personal_number)
21
+ raise ArgumentError('personal_number required') if personal_number.blank?
22
+ action_name = 'GetDataUsingPrivateNumber'
23
+ soap_action = self.soap_action(action_name)
24
+ response = get_client.request action_name do
25
+ http.headers['SOAPAction'] = soap_action
26
+ soap.body = { 'privateNumber' => personal_number }
27
+ end
28
+ CRA::PasportInfo.init_with_hash(response.to_hash[:get_data_using_private_number_response][:get_data_using_private_number_result])
29
+ end
30
+
31
+ # Getting personal information by ID card information.
32
+ def by_id_card(serial, number)
33
+ raise ArgumentError('id card serial required') if serial.blank?
34
+ raise ArgumentError('id card number required') if serial.blank?
35
+ action_name = 'PersonInfoByDocumentNumber'
36
+ soap_action = self.soap_action(action_name)
37
+ response = get_client.request action_name do
38
+ http.headers['SOAPAction'] = soap_action
39
+ soap.body = { 'idCardSerial' => serial, 'idCardNumber' => number }
40
+ end
41
+ CRA::PasportInfo.init_with_hash(response.to_hash[:person_info_by_document_number_response][:person_info_by_document_number_result])
42
+ end
43
+
44
+ # Getting documents by name and date of birth.
45
+ def list_by_name_and_dob(last_name, first_name, year, month, day)
46
+ raise ArgumentError('first_name required') if first_name.blank?
47
+ raise ArgumentError('last_name required') if last_name.blank?
48
+ raise ArgumentError('year required') if year.blank?
49
+ raise ArgumentError('month required') if month.blank?
50
+ raise ArgumentError('day required') if day.blank?
51
+ action_name = 'GetDataUsingCriteria'
52
+ soap_action = self.soap_action(action_name)
53
+ response = get_client.request action_name do
54
+ http.headers['SOAPAction'] = soap_action
55
+ soap.body = { 'lastName' => last_name, 'firstName' => first_name, 'year' => year, 'month' => month, 'day' => day }
56
+ end
57
+ data = response.to_hash[:get_data_using_criteria_response][:get_data_using_criteria_result][:person_info]
58
+ documents = []
59
+ data.each do |row|
60
+ documents << CRA::PasportInfo.init_with_hash(row)
61
+ end
62
+ documents
63
+ end
64
+
65
+ def test_service
66
+ action_name = 'PersonInfoByDocumentNumber'
67
+ soap_action = self.soap_action(action_name)
68
+ response = get_client.request action_name do
69
+ http.headers['SOAPAction'] = soap_action
70
+ soap.body = { 'idCardSerial' => 'გ', 'idCardNumber' => '1355876' }
71
+ end
72
+ puts response.to_hash
73
+ end
74
+
75
+ end
76
+
77
+ class << self
78
+ def serv
79
+ CRA::Services.instance
80
+ end
81
+ end
82
+
83
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module CRA
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,6 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe 'configure CRA gem' do
5
+ specify { CRA.config.pem_file.should == 'spec/data/telasi.pem' }
6
+ end
@@ -0,0 +1,79 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'cra'
4
+
5
+ describe 'my UPN' do
6
+ before(:all) do
7
+ @upn = CRA.serv.my_upn
8
+ end
9
+ subject { @upn }
10
+ it { should == 'CRA\telasi' }
11
+ end
12
+
13
+ describe 'get person info by id' do
14
+ before(:all) do
15
+ @person_info = CRA.serv.by_personal_id('02001000490')
16
+ end
17
+ subject { @person_info }
18
+ its(:doc_id) { should > 0 }
19
+ its(:doc_type) { should == 1 }
20
+ its(:doc_description) { should == 'პირადობის მოწმობა' }
21
+ its(:doc_status) { should == 'Active' }
22
+ its(:doc_status_text) { should == 'აქტიური' }
23
+ its(:is_id_card) { should == true }
24
+ its(:id_card_serial) { should == 'გ' }
25
+ its(:id_card_number) { should == '1355876' }
26
+ its(:id_card_issuer) { should == 'სამოქალაქო რეესტრის სააგენტოს მთაწმინდა-კრწანისის სამსახური' }
27
+ its(:id_card_issue_date) { should_not be_nil }
28
+ its(:id_card_valid_date) { should_not be_nil }
29
+ its(:pasport_number) { should be_nil }
30
+ its(:passport_issuer) { should be_nil }
31
+ its(:passport_issue_date) { should be_nil }
32
+ its(:passport_valid_date) { should be_nil }
33
+ its(:person_id) { should == 969036 }
34
+ its(:private_number) { should == '02001000490' }
35
+ its(:first_name) { should == 'დიმიტრი' }
36
+ its(:last_name) { should == 'ყურაშვილი' }
37
+ its(:middle_name) { should == 'ალბერტი' }
38
+ its(:birth_date) { should_not be_nil }
39
+ its(:birth_place) { should == 'საქართველო, აბაშა' }
40
+ its(:gender) { should == CRA::MALE }
41
+ its(:citizenship) { should == 'საქართველო' }
42
+ its(:citizenship_code) { should == 'GEO' }
43
+ its(:second_citizenship) { should be_nil }
44
+ its(:second_citizenship_code) { should be_nil }
45
+ its(:living_place_id) { should == 920434 }
46
+ its(:living_place) { should == 'თბილისი მისამართის გარეშე' }
47
+ its(:living_place_registration) { should_not be_nil }
48
+ its(:living_place_registration_end) { should be_nil }
49
+ its(:actual_living_place) { should == 'თბილისი აკ.ხორავას ჩიხი N 8' }
50
+ its(:is_person_dead) { should == false }
51
+ its(:is_document_lost) { should == false }
52
+ its(:photos) { should_not be_empty }
53
+ end
54
+
55
+ describe 'get person info by id card' do
56
+ before(:all) do
57
+ @person_info = CRA.serv.by_id_card('გ', '1355876')
58
+ end
59
+ subject { @person_info }
60
+ its(:doc_id) { should > 0 }
61
+ its(:first_name) { should == 'დიმიტრი' }
62
+ its(:last_name) { should == 'ყურაშვილი' }
63
+ its(:private_number) { should == '02001000490' }
64
+ end
65
+
66
+ describe 'find person documents by name and dob' do
67
+ before(:all) do
68
+ @documents = CRA.serv.list_by_name_and_dob('ყურაშვილი', 'დიმიტრი', 1979, 4, 4)
69
+ end
70
+ context do
71
+ subject { @documents }
72
+ its(:size) { should == 5 }
73
+ end
74
+ context do
75
+ subject { @documents.first }
76
+ its(:person_id) { should == 969036 }
77
+ its(:private_number) { should == '02001000490' }
78
+ end
79
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ # Savon
4
+
5
+ require 'savon'
6
+
7
+ HTTPI.log = false
8
+ Savon.configure do |config|
9
+ config.log = false
10
+ end
11
+
12
+ # RSpec
13
+
14
+ require 'rspec'
15
+
16
+ RSpec.configure do |config|
17
+ config.include(RSpec::Matchers)
18
+ end
19
+
20
+ # Test options.
21
+
22
+ require 'cra'
23
+
24
+ CRA.config.pem_file = 'spec/data/telasi.pem'
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cra.ge
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Dimitri Kurashvili
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-10-26 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "2.11"
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: savon
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: "1.2"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ description: CRA services
38
+ email:
39
+ - dimitri@c12.ge
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .DS_Store
48
+ - .gitignore
49
+ - .rspec
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - cra.gemspec
55
+ - lib/cra.rb
56
+ - lib/cra/config.rb
57
+ - lib/cra/pasport_info.rb
58
+ - lib/cra/services.rb
59
+ - lib/cra/version.rb
60
+ - spec/config_spec.rb
61
+ - spec/service_spec.rb
62
+ - spec/spec_helper.rb
63
+ homepage: http://github.com/dimakura/cra.ge
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.24
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Ruby client for C(ivil)R(egistry)A(gency) services
90
+ test_files:
91
+ - spec/config_spec.rb
92
+ - spec/service_spec.rb
93
+ - spec/spec_helper.rb