gvive 1.0.0 → 1.1.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
  SHA1:
3
- metadata.gz: 2eaf74e4921bc1ab21759c460a8655c350df6e07
4
- data.tar.gz: '0954b56a1456ca6452ff48933d45758a15ec803d'
3
+ metadata.gz: 0f42745844ffddfcd7269bd08365ee80518ca179
4
+ data.tar.gz: '044974c569d35df4b488b5939da0ffae3ac965dc'
5
5
  SHA512:
6
- metadata.gz: 94186cf9843777f5cf64659ae294b9b39ba7d29e81b7d2cdb6e904c29042436344d3998011f9b6afec6483bd646d739c9f00fd77cfb0e5632b2d293f512d32ed
7
- data.tar.gz: c514974adf452accf88b8412c08f7dc2c59a0d85e3b5535856bae876c23c7f5164246c20cc4b7e7cf779955db665ac1027eee6a1b405d124bdd4e58e55fb0b9a
6
+ metadata.gz: 9c91a649208b21b9bcf9161e304dd8c3de2c02fe49cdd59607c6256357c28ae6457dd57220ed3fcb333ba33259b67566f198d5a9339b088f618d9f8a180cd134
7
+ data.tar.gz: 0a1f34f154619ec91fc8b87c23c5d307e67e76e8c94864a45404c8db419033338476e75cf00caae1456b394dbb856e9a9f33c71c2833fb368c99e4bf51a18ed1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gvive (0.1.0)
4
+ gvive (1.1.0)
5
5
  http (~> 2.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -50,12 +50,12 @@ You are required to provide the Voter ID number
50
50
  ```ruby
51
51
  voter = GVIVE::Identity::Voter.new('6580676543')
52
52
  if voter.valid?
53
- p voter.data.Fullname
54
- p voter.data.PollingStation
55
- p voter.data.ResidentialAddress
53
+ p voter.data.fullname
54
+ p voter.data.polling_station
55
+ p voter.data.residential_address
56
56
  # ...
57
57
  else
58
- p voter.data.Message
58
+ p voter.data.message
59
59
  end
60
60
  ```
61
61
 
@@ -65,13 +65,13 @@ You are required to provide the Passport ID number
65
65
  ```ruby
66
66
  passport = GVIVE::Identity::Passport.new('G00827283')
67
67
  if passport.valid?
68
- p passport.data.FirstName
69
- p passport.data.LastName
70
- p passport.data.Gender
71
- p passport.data.ExpiryDate
68
+ p passport.data.first_name
69
+ p passport.data.last_name
70
+ p passport.data.gender
71
+ p passport.data.expiry_date
72
72
  # ...
73
73
  else
74
- p passport.data.Message
74
+ p passport.data.message
75
75
  end
76
76
  ```
77
77
 
@@ -81,16 +81,26 @@ You are required to provide the Certificate of Competence Number & the full name
81
81
  ```ruby
82
82
  driver = GVIVE::Identity::Driver.new('COO92930','Alfred Rowe')
83
83
  if driver.valid?
84
- p driver.data.FirstName
85
- p driver.data.LastName
86
- p driver.data.Gender
87
- p driver.data.ExpiryDate
84
+ p driver.data.first_name
85
+ p driver.data.last_name
86
+ p driver.data.class_of_licence
87
+ p driver.data.date_of_issue
88
88
  # ...
89
89
  else
90
- p driver.data.Message
90
+ p driver.data.message
91
91
  end
92
92
  ```
93
93
 
94
+ ## Testing
95
+ In order to protect valid identity information, all valid IDs have been moved to environment variables. You will need to set them up before tests can pass for valid ID specs.
96
+
97
+ ```sh
98
+ export GVIVE_VALID_VID=VOTER_ID_NUMBER
99
+ export GVIVE_VALID_PID=PASSPORT_ID_NUMBER
100
+ export GVIVE_VALID_DCOC=DRIVER_CERTIFICATE_OF_COMPETENCE_NUMBER
101
+ export GVIVE_VALID_DNAME=⁠⁠⁠⁠⁠"Full name as printed exactly on ID card"
102
+ ```
103
+
94
104
  ## Development
95
105
 
96
106
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,5 +1,3 @@
1
- require 'cgi'
2
-
3
1
  module GVIVE
4
2
  module Identity
5
3
  class Driver < GVIVE::Identities
@@ -15,7 +15,26 @@ module GVIVE
15
15
  # Convert response data to plain Ruby Objects
16
16
  # @return [OpenStruct]
17
17
  def to_o
18
- @cache = JSON.parse @http_response.body.to_s, object_class: OpenStruct
18
+ old_hash = JSON.parse @http_response.body.to_s
19
+ new_hash = {}
20
+ old_hash.each do |k,v|
21
+ new_hash["#{snakecase(k)}"] = v
22
+ end
23
+ @cache = OpenStruct.new(new_hash)
24
+ end
25
+
26
+ # Shamelessly copied from the internet with 1% modifications :)
27
+ # http://www.rubydoc.info/github/rubyworks/facets/String%3Asnakecase
28
+ # Convert all CamelCased strings to snake_cased
29
+ # @param [String] str
30
+ # @return [String]
31
+ def snakecase(str)
32
+ str.to_s.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
33
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
34
+ tr('-', '_').
35
+ gsub(/\s/, '_').
36
+ gsub(/__+/, '_').
37
+ downcase
19
38
  end
20
39
 
21
40
  # GVIVE returned valid response
@@ -23,7 +42,7 @@ module GVIVE
23
42
  # Check also for GVIVE ResponseCode Key in the response body 200 for data found
24
43
  # @return [Boolean]
25
44
  def success?
26
- @http_response.code == 200 && to_o.ResponseCode == "200"
45
+ @http_response.code == 200 && to_o.response_code == "200"
27
46
  end
28
47
  end
29
48
  end
@@ -1,3 +1,3 @@
1
1
  module GVIVE
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gvive
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alfred Rowe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-29 00:00:00.000000000 Z
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler