Class: MyInfo::V3::PersonBasic

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

Overview

Calls the PersonBasic API

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Raises:



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

#attributesObject

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#nric_finObject

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_noObject

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

#callObject



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

#errorsObject



44
45
46
# File 'lib/myinfo/v3/person_basic.rb', line 44

def errors
  %w[401 403 404 428 default]
end

#paramsObject



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

#slugObject



27
28
29
# File 'lib/myinfo/v3/person_basic.rb', line 27

def slug
  "gov/v3/person-basic/#{nric_fin}/"
end

#support_gzip?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/myinfo/v3/person_basic.rb', line 31

def support_gzip?
  true
end