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.
Constructor Details
#initialize(user, pass, endpoint) ⇒ Client
Returns a new Client.
16 17 18 19 20 21 22 |
# File 'lib/cpr_client/client.rb', line 16 def initialize(user, pass, endpoint) @user, @pass, @endpoint = user, pass, endpoint @http = HTTPClient.new( agent_name: "CPRClient/#{CPRClient::VERSION}", default_header: { 'Content-Type' => 'text/xml' } ) end |
Instance Method Details
#login ⇒ Object
Performs login for client.
49 50 51 52 |
# File 'lib/cpr_client/client.rb', line 49 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.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cpr_client/client.rb', line 31 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 |