Class: MyInfo::V3::Person

Inherits:
Api
  • Object
show all
Defined in:
lib/myinfo/v3/person.rb

Overview

Calls the Person API

Instance Attribute Summary collapse

Instance Method Summary collapse

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_tokenObject

Returns the value of attribute access_token.



7
8
9
# File 'lib/myinfo/v3/person.rb', line 7

def access_token
  @access_token
end

#attributesObject

Returns the value of attribute attributes.



7
8
9
# File 'lib/myinfo/v3/person.rb', line 7

def attributes
  @attributes
end

#decoded_tokenObject

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_noObject

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

#callObject



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

#errorsObject



49
50
51
# File 'lib/myinfo/v3/person.rb', line 49

def errors
  %w[401 403 404]
end

#nric_finObject



45
46
47
# File 'lib/myinfo/v3/person.rb', line 45

def nric_fin
  @nric_fin ||= decoded_token['sub']
end

#paramsObject



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

#slugObject



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

Returns:

  • (Boolean)


32
33
34
# File 'lib/myinfo/v3/person.rb', line 32

def support_gzip?
  true
end