cra.ge 0.1.0 → 0.1.1

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.
data/README.md CHANGED
@@ -20,6 +20,16 @@ private_number = '02001000490'
20
20
  person_info = CRA.serv.by_personal_id(private_number) # CRA::PassportInfo
21
21
  ```
22
22
 
23
+ ## Getting person infromation by id card
24
+
25
+ You can get person's last document by their id card information:
26
+
27
+ ```ruby
28
+ id_card_serial = 'გ'
29
+ id_card_number = '1355876'
30
+ person_info = CRA.serv.by_id_card(id_card_serial, id_card_number)
31
+ ```
32
+
23
33
  ## Getting full documentation for the person
24
34
 
25
35
  If you have first/last names of the person and know their birthdate, then it's easy to get
data/lib/cra.rb CHANGED
@@ -4,6 +4,16 @@ require 'cra/version'
4
4
 
5
5
  require 'cra/config'
6
6
 
7
+ class String
8
+ def underscore
9
+ self.gsub(/::/, '/').
10
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
11
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
12
+ tr("-", "_").
13
+ downcase
14
+ end
15
+ end
16
+
7
17
  module CRA
8
18
  BASE_URL = 'http://stateinstitution.cra.ge'
9
19
  WSDL_URL = 'https://stateinstitutions.cra.ge/Service.asmx?WSDL'
@@ -12,6 +22,18 @@ module CRA
12
22
  FEMALE = 2
13
23
 
14
24
  class Base
25
+ attr_accessor :last_request, :last_response, :last_action
26
+
27
+ def process_request(action, request)
28
+ soap_action = self.soap_action(action)
29
+ response = get_client.request action do
30
+ http.headers['SOAPAction'] = soap_action
31
+ soap.body = request
32
+ end
33
+ @last_action = action
34
+ @last_request = request
35
+ @last_response = response["#{action.underscore}_response".to_sym]["#{action.underscore}_result".to_sym]
36
+ end
15
37
 
16
38
  def get_client
17
39
  Savon::Client.new WSDL_URL do
@@ -60,16 +60,24 @@ class CRA::PasportInfo
60
60
  passport.is_person_dead = hash[:is_person_dead]
61
61
  passport.is_document_lost = hash[:is_document_lost]
62
62
  passport.photos = []
63
- if hash[:photos].is_a?(Array)
63
+ if hash[:photos] and hash[:photos].is_a?(Array)
64
64
  hash[:photos].each do |photo|
65
65
  passport.photos.push(photo[:base64_binary])
66
66
  end
67
- else
67
+ elsif hash[:photos]
68
68
  passport.photos.push(hash[:photos][:base64_binary])
69
69
  end
70
70
  passport
71
71
  end
72
72
 
73
+ def self.list_with_hash(hash)
74
+ documents = []
75
+ hash[:person_info].each do |row|
76
+ documents << CRA::PasportInfo.init_with_hash(row)
77
+ end
78
+ documents
79
+ end
80
+
73
81
  def full_name(opts = {})
74
82
  if opts[:with_middle_name]
75
83
  "#{first_name} #{last_name} #{middle_name}"
@@ -8,37 +8,22 @@ module CRA
8
8
 
9
9
  # Get service consumer UPN.
10
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]
11
+ process_request('GetMyUPN', {})
17
12
  end
18
13
 
19
14
  # Getting personal information by personal number.
20
15
  def by_personal_id(personal_number)
21
16
  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])
17
+ response = process_request('GetDataUsingPrivateNumber', { 'privateNumber' => personal_number })
18
+ CRA::PasportInfo.init_with_hash(response)
29
19
  end
30
20
 
31
21
  # Getting personal information by ID card information.
32
22
  def by_id_card(serial, number)
33
23
  raise ArgumentError('id card serial required') if serial.blank?
34
24
  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])
25
+ response = process_request('PersonInfoByDocumentNumber', { 'idCardSerial' => serial, 'idCardNumber' => number })
26
+ CRA::PasportInfo.init_with_hash(response)
42
27
  end
43
28
 
44
29
  # Getting documents by name and date of birth.
@@ -48,26 +33,16 @@ module CRA
48
33
  raise ArgumentError('year required') if year.blank?
49
34
  raise ArgumentError('month required') if month.blank?
50
35
  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
36
+ response = process_request('GetDataUsingCriteria', { 'lastName' => last_name, 'firstName' => first_name, 'year' => year, 'month' => month, 'day' => day })
37
+ CRA::PasportInfo.list_with_hash(response)
63
38
  end
64
39
 
65
40
  def test_service
66
- action_name = 'PersonInfoByDocumentNumber'
41
+ action_name = 'AddrGetRootNode'
67
42
  soap_action = self.soap_action(action_name)
68
43
  response = get_client.request action_name do
69
44
  http.headers['SOAPAction'] = soap_action
70
- soap.body = { 'idCardSerial' => 'გ', 'idCardNumber' => '1355876' }
45
+ #soap.body = { 'idCardSerial' => 'გ', 'idCardNumber' => '1355876' }
71
46
  end
72
47
  puts response.to_hash
73
48
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module CRA
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
@@ -0,0 +1,11 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'cra'
4
+
5
+ describe 'test' do
6
+ before(:all) do
7
+ CRA.serv.test_service
8
+ end
9
+ subject { true }
10
+ it { should == true }
11
+ end
@@ -6,8 +6,16 @@ describe 'my UPN' do
6
6
  before(:all) do
7
7
  @upn = CRA.serv.my_upn
8
8
  end
9
- subject { @upn }
10
- it { should == 'CRA\telasi' }
9
+ context do
10
+ subject { @upn }
11
+ it { should == 'CRA\telasi' }
12
+ end
13
+ context do
14
+ subject { CRA.serv }
15
+ its(:last_request) { should == {} }
16
+ its(:last_response) { should == 'CRA\telasi' }
17
+ its(:last_action) { should == 'GetMyUPN' }
18
+ end
11
19
  end
12
20
 
13
21
  describe 'get person info by id' do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cra.ge
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dimitri Kurashvili
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-10-26 00:00:00 Z
13
+ date: 2012-10-29 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -58,6 +58,7 @@ files:
58
58
  - lib/cra/services.rb
59
59
  - lib/cra/version.rb
60
60
  - spec/config_spec.rb
61
+ - spec/experimental_spec.rb
61
62
  - spec/service_spec.rb
62
63
  - spec/spec_helper.rb
63
64
  homepage: http://github.com/dimakura/cra.ge
@@ -89,5 +90,6 @@ specification_version: 3
89
90
  summary: Ruby client for C(ivil)R(egistry)A(gency) services
90
91
  test_files:
91
92
  - spec/config_spec.rb
93
+ - spec/experimental_spec.rb
92
94
  - spec/service_spec.rb
93
95
  - spec/spec_helper.rb