Class: MyInfo::V3::PersonBasic
Overview
Calls the PersonBasic API
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#nric_fin ⇒ Object
Returns the value of attribute nric_fin.
-
#txn_no ⇒ Object
Returns the value of attribute txn_no.
Instance Method Summary collapse
- #call ⇒ Object
- #errors ⇒ Object
-
#initialize(nric_fin:, txn_no: nil, attributes: nil) ⇒ PersonBasic
constructor
A new instance of PersonBasic.
- #params ⇒ Object
- #parse_response(response) ⇒ Object
- #slug ⇒ Object
- #support_gzip? ⇒ Boolean
Methods inherited from Api
#endpoint, #header, #http_method
Constructor Details
#initialize(nric_fin:, txn_no: nil, attributes: nil) ⇒ PersonBasic
Returns a new instance of PersonBasic.
9 10 11 12 13 14 15 |
# File 'lib/myinfo/v3/person_basic.rb', line 9 def initialize(nric_fin:, txn_no: nil, attributes: nil) raise UnavailableError, 'person-basic endpoint is not available for public-facing APIs.' if config.public? @attributes = Attributes.parse(attributes) @nric_fin = nric_fin @txn_no = txn_no end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/myinfo/v3/person_basic.rb', line 7 def attributes @attributes end |
#nric_fin ⇒ Object
Returns the value of attribute nric_fin.
7 8 9 |
# File 'lib/myinfo/v3/person_basic.rb', line 7 def nric_fin @nric_fin end |
#txn_no ⇒ Object
Returns the value of attribute txn_no.
7 8 9 |
# File 'lib/myinfo/v3/person_basic.rb', line 7 def txn_no @txn_no end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/myinfo/v3/person_basic.rb', line 17 def call super do headers = header(params: params) endpoint_url = "/#{slug}?#{params.to_query}" response = http.request_get(endpoint_url, headers) parse_response(response) end end |
#errors ⇒ Object
44 45 46 |
# File 'lib/myinfo/v3/person_basic.rb', line 44 def errors %w[401 403 404 428 default] end |
#params ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/myinfo/v3/person_basic.rb', line 35 def params { txnNo: txn_no, attributes: attributes, client_id: config.client_id, sp_esvcId: config.singpass_eservice_id }.compact end |
#parse_response(response) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/myinfo/v3/person_basic.rb', line 48 def parse_response(response) super do json = decrypt_jwe(response.body) json = decode_jws(json.delete('\"')) unless config.sandbox? Response.new(success: true, data: json) end end |
#slug ⇒ Object
27 28 29 |
# File 'lib/myinfo/v3/person_basic.rb', line 27 def slug "gov/v3/person-basic/#{nric_fin}/" end |
#support_gzip? ⇒ Boolean
31 32 33 |
# File 'lib/myinfo/v3/person_basic.rb', line 31 def support_gzip? true end |