Class: CPRClient::Client
- Inherits:
-
Object
- Object
- CPRClient::Client
- Defined in:
- lib/cpr_client/client.rb
Instance Method Summary collapse
-
#initialize(user, pass, endpoint) ⇒ Client
constructor
Returns a new Client.
-
#login ⇒ Object
Performs login for client.
-
#lookup(cpr) ⇒ Object
(also: #stamp)
Returns a Record object or nil if the record could not be found.
-
#new_password(new_password) ⇒ Object
Performs change of password.
Constructor Details
#initialize(user, pass, endpoint) ⇒ Client
Returns a new Client.
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
#login ⇒ Object
Performs login for client.
45 46 47 48 |
# File 'lib/cpr_client/client.rb', line 45 def login code = receipt_code(post(login_body)) 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.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cpr_client/client.rb', line 27 def lookup(cpr) xml_doc = post_auto_login(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.
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 |