Class: CPRClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cpr_client/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(user, pass, endpoint) ⇒ Client

Returns a new Client.

Parameters:

  • user

    your cpr username

  • pass

    your current cpr password

  • endpoint

    the full URI to the cpr gctp service



16
17
18
# File 'lib/cpr_client/client.rb', line 16

def initialize(user, pass, endpoint)
  @user, @pass, @endpoint = user, pass, endpoint
end

Instance Method Details

#loginObject

Performs login for client.

Returns:

  • true

Raises:

  • LoginError if login failed



45
46
47
48
# File 'lib/cpr_client/client.rb', line 45

def 
  code = receipt_code(post())
  code == 900 or raise LoginError, code
end

#lookup(cpr) ⇒ Object Also known as: stamp

Returns a Record object or nil if the record could not be found. If the client is not logged in, a login is performed before a retry.

The cpr parameter is stripped of any non-digits.

Parameters:

  • cpr

    a string

Returns:

  • a #Record or nil if no record was found



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cpr_client/client.rb', line 27

def lookup(cpr)
  xml_doc = (stamp_body(digits(cpr)))
  case receipt_code(xml_doc)
    when 0
      Record.new(xml_doc)
    when 172, 52
      nil
    else
      raise ClientError, "Unexpected STAMP resp: #{xml_doc}"
  end
end

#new_password(new_password) ⇒ Object

Performs change of password.

Returns:

  • true

Raises:

  • NewPasswordError if password change failed



55
56
57
58
# File 'lib/cpr_client/client.rb', line 55

def new_password(new_password)
  code = receipt_code(post(new_password_body(new_password)))
  code == 900 or raise NewPasswordError, code
end