Class: MyInfo::V3::Person
Overview
Calls the Person API
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#decoded_token ⇒ Object
Returns the value of attribute decoded_token.
-
#txn_no ⇒ Object
Returns the value of attribute txn_no.
Instance Method Summary collapse
- #call ⇒ Object
- #errors ⇒ Object
-
#initialize(access_token:, txn_no: nil, attributes: nil) ⇒ Person
constructor
A new instance of Person.
- #nric_fin ⇒ Object
- #params ⇒ Object
- #parse_response(response) ⇒ Object
- #slug ⇒ Object
- #support_gzip? ⇒ Boolean
Methods inherited from Api
#endpoint, #header, #http_method
Constructor Details
#initialize(access_token:, txn_no: nil, attributes: nil) ⇒ Person
Returns a new instance of Person.
9 10 11 12 13 14 |
# File 'lib/myinfo/v3/person.rb', line 9 def initialize(access_token:, txn_no: nil, attributes: nil) @access_token = access_token @decoded_token = decode_jws(access_token) @attributes = Attributes.parse(attributes) @txn_no = txn_no end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/myinfo/v3/person.rb', line 7 def access_token @access_token end |
#attributes ⇒ Object
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/myinfo/v3/person.rb', line 7 def attributes @attributes end |
#decoded_token ⇒ Object
Returns the value of attribute decoded_token.
7 8 9 |
# File 'lib/myinfo/v3/person.rb', line 7 def decoded_token @decoded_token end |
#txn_no ⇒ Object
Returns the value of attribute txn_no.
7 8 9 |
# File 'lib/myinfo/v3/person.rb', line 7 def txn_no @txn_no end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/myinfo/v3/person.rb', line 16 def call super do headers = header(params: params, access_token: access_token) endpoint_url = "/#{slug}?#{params.to_query}" response = http.request_get(endpoint_url, headers) parse_response(response) end end |
#errors ⇒ Object
49 50 51 |
# File 'lib/myinfo/v3/person.rb', line 49 def errors %w[401 403 404] end |
#nric_fin ⇒ Object
45 46 47 |
# File 'lib/myinfo/v3/person.rb', line 45 def nric_fin @nric_fin ||= decoded_token['sub'] end |
#params ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/myinfo/v3/person.rb', line 36 def params { txnNo: txn_no, attributes: attributes, client_id: config.client_id, sp_esvcId: config.singpass_eservice_id }.compact end |
#parse_response(response) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/myinfo/v3/person.rb', line 53 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
26 27 28 29 30 |
# File 'lib/myinfo/v3/person.rb', line 26 def slug slug_prefix = config.public? ? 'com' : 'gov' "#{slug_prefix}/v3/person/#{nric_fin}/" end |
#support_gzip? ⇒ Boolean
32 33 34 |
# File 'lib/myinfo/v3/person.rb', line 32 def support_gzip? true end |