Class: IHopeYouDie
- Inherits:
-
Object
- Object
- IHopeYouDie
- Defined in:
- lib/i_hope_you_die.rb
Constant Summary collapse
- WSDL_PROD_AUTH =
"https://ewus.nfz.gov.pl/ws-broker-server-ewus/services/Auth?wsdl"
- WSDL_PROD_BROK =
"https://ewus.nfz.gov.pl/ws-broker-server-ewus/services/ServiceBroker?wsdl"
- WSDL_TEST_AUTH =
"https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/Auth?wsdl"
- WSDL_TEST_BROK =
"https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/ServiceBroker?wsdl"
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#ident_string ⇒ Object
Returns the value of attribute ident_string.
-
#login ⇒ Object
Returns the value of attribute login.
-
#login_type ⇒ Object
Returns the value of attribute login_type.
-
#password ⇒ Object
Returns the value of attribute password.
-
#prod ⇒ Object
Returns the value of attribute prod.
Instance Method Summary collapse
- #auth! ⇒ Object
- #brok_date ⇒ Object
- #check_pesels(pesels) ⇒ Object
- #cwu_for_pesel(pesel) ⇒ Object
- #cwu_xml(pesel) ⇒ Object
- #domain_string ⇒ Object
-
#initialize ⇒ IHopeYouDie
constructor
A new instance of IHopeYouDie.
- #login_xml ⇒ Object
- #parse_cwu_response(doc) ⇒ Object
- #session_id ⇒ Object
- #session_token ⇒ Object
- #wsdl_auth ⇒ Object
- #wsdl_brok ⇒ Object
Constructor Details
#initialize ⇒ IHopeYouDie
Returns a new instance of IHopeYouDie.
32 33 34 35 36 37 38 39 40 |
# File 'lib/i_hope_you_die.rb', line 32 def initialize @prod = true @domain = '15' # '01' @login_type = '' @ident_string = '' @login = 'TEST1' @password = 'qwerty!@#' end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
42 43 44 |
# File 'lib/i_hope_you_die.rb', line 42 def domain @domain end |
#ident_string ⇒ Object
Returns the value of attribute ident_string.
42 43 44 |
# File 'lib/i_hope_you_die.rb', line 42 def ident_string @ident_string end |
#login ⇒ Object
Returns the value of attribute login.
42 43 44 |
# File 'lib/i_hope_you_die.rb', line 42 def login @login end |
#login_type ⇒ Object
Returns the value of attribute login_type.
42 43 44 |
# File 'lib/i_hope_you_die.rb', line 42 def login_type @login_type end |
#password ⇒ Object
Returns the value of attribute password.
42 43 44 |
# File 'lib/i_hope_you_die.rb', line 42 def password @password end |
#prod ⇒ Object
Returns the value of attribute prod.
42 43 44 |
# File 'lib/i_hope_you_die.rb', line 42 def prod @prod end |
Instance Method Details
#auth! ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/i_hope_you_die.rb', line 114 def auth! client_login = Savon::Client.new(wsdl: wsdl_auth) Savon::Builder.forced_output = login_xml response = client_login.call(:login) Savon::Builder.clear_forced_output login_doc = response.doc # get token and session id h = Hash.new login_doc.search('//soapenv:Envelope/soapenv:Header/*').each do |n| h[n.name] = n.attributes['id'].to_s end @session_token = h['authToken'] @session_id = h['session'] end |
#brok_date ⇒ Object
98 99 100 |
# File 'lib/i_hope_you_die.rb', line 98 def brok_date '2008-09-12T09:37:36.406+01:00' end |
#check_pesels(pesels) ⇒ Object
186 187 188 189 |
# File 'lib/i_hope_you_die.rb', line 186 def check_pesels(pesels) pesels = [pesels] unless pesels.kind_of?(Array) return pesels.collect { |pesel| cwu_for_pesel(pesel) } end |
#cwu_for_pesel(pesel) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/i_hope_you_die.rb', line 131 def cwu_for_pesel(pesel) #puts "PESEL #{pesel}" xml = cwu_xml(pesel) client = Savon::Client.new(wsdl: wsdl_brok) Savon::Builder.forced_output = xml response = client.call(:execute_service) Savon::Builder.clear_forced_output doc = response.doc return parse_cwu_response(doc) end |
#cwu_xml(pesel) ⇒ Object
110 111 112 |
# File 'lib/i_hope_you_die.rb', line 110 def cwu_xml(pesel) '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://xml.kamsoft.pl/ws/common" xmlns:brok="http://xml.kamsoft.pl/ws/broker"> <soapenv:Header> <com:session id="' + session_id + '" xmlns:ns1="http://xml.kamsoft.pl/ws/common"/> <com:authToken id="' + session_token + '" xmlns:ns1="http://xml.kamsoft.pl/ws/common"/> </soapenv:Header> <soapenv:Body> <brok:executeService> <com:location> <com:namespace>nfz.gov.pl/ws/broker/cwu</com:namespace> <com:localname>checkCWU</com:localname> <com:version>2.0</com:version> </com:location> <brok:date>' + brok_date + '</brok:date> <brok:payload> <brok:textload> <ewus:status_cwu_pyt xmlns:ewus="https://ewus.nfz.gov.pl/ws/broker/ewus/status_cwu/v2"> <ewus:numer_pesel>' + pesel + '</ewus:numer_pesel> <ewus:system_swiad nazwa="eWUĆ" wersja="2012.07.1.0"/> </ewus:status_cwu_pyt> </brok:textload> </brok:payload> </brok:executeService> </soapenv:Body> </soapenv:Envelope>' end |
#domain_string ⇒ Object
60 61 62 |
# File 'lib/i_hope_you_die.rb', line 60 def domain_string @domain.to_s || '01' end |
#login_xml ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/i_hope_you_die.rb', line 80 def login_xml s = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:auth="http://xml.kamsoft.pl/ws/kaas/login_types"> <soapenv:Header/> <soapenv:Body> <auth:login> <auth:credentials>' unless domain_string.to_s == '' s += ' <auth:item> <auth:name>domain</auth:name> <auth:value><auth:stringValue>' + domain_string + '</auth:stringValue></auth:value> </auth:item>' end unless login_type.to_s == '' s += ' <auth:item> <auth:name>type</auth:name> <auth:value><auth:stringValue>' + login_type + '</auth:stringValue></auth:value> </auth:item>' end unless ident_string.to_s == '' s += ' <auth:item> <auth:name>idntSwd</auth:name> <auth:value><auth:stringValue>' + ident_string + '</auth:stringValue></auth:value> </auth:item>' end unless login.to_s == '' s += ' <auth:item> <auth:name>login</auth:name> <auth:value><auth:stringValue>' + login + '</auth:stringValue></auth:value> </auth:item>' end s += ' </auth:credentials> <auth:password>' + password + '</auth:password> </auth:login> </soapenv:Body> </soapenv:Envelope>' return s end |
#parse_cwu_response(doc) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/i_hope_you_die.rb', line 144 def parse_cwu_response(doc) # fuck this shit.. regexp h = Hash.new keys = { time: 'ns3:date', cwu_status: 'ns2:status_cwu', pesel: 'ns2:numer_pesel', id_swiad: 'ns2:id_swiad', id_ow: 'ns2:id_ow', id_operatora: 'ns2:id_operatora', time_valid_to: 'ns2:data_waznosci_potwierdzenia', status_ubezp: 'ns2:status_ubezp', name: 'ns2:imie', surname: 'ns2:nazwisko' } s = doc.to_s keys.keys.each do |k| if s =~ /<#{keys[k]}>([^<]*)<\/#{keys[k]}>/ h[k] = $1.to_s end end if s =~ /<ns2:status_cwu_odp([^>]+)>/ t = $1 if t =~ /id_operacji="([^"]+)"/ h[:operation_id] = $1 end if t =~ /data_czas_operacji="([^"]+)"/ h[:operation_time] = $1 end end h[:doc] = s return h end |
#session_id ⇒ Object
102 103 104 |
# File 'lib/i_hope_you_die.rb', line 102 def session_id @session_id end |
#session_token ⇒ Object
106 107 108 |
# File 'lib/i_hope_you_die.rb', line 106 def session_token @session_token end |
#wsdl_auth ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/i_hope_you_die.rb', line 44 def wsdl_auth if @prod WSDL_PROD_AUTH else WSDL_TEST_AUTH end end |
#wsdl_brok ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/i_hope_you_die.rb', line 52 def wsdl_brok if @prod WSDL_PROD_BROK else WSDL_TEST_BROK end end |