Class: GusBir1::Client
- Inherits:
-
Object
- Object
- GusBir1::Client
- Defined in:
- lib/gus_bir1/client.rb
Constant Summary collapse
- SESSION_TIMEOUT =
3600- PUBL_OPERATIONS =
%i[ wyloguj dane_szukaj_podmioty dane_pobierz_pelny_raport dane_komunikat zaloguj ].freeze
Instance Attribute Summary collapse
-
#client_key ⇒ Object
Returns the value of attribute client_key.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#logging ⇒ Object
Returns the value of attribute logging.
-
#production ⇒ Object
Returns the value of attribute production.
Instance Method Summary collapse
- #find_and_get_full_data(hash) ⇒ Object
- #find_by(nip: nil, regon: nil, krs: nil, nips: nil, krss: nil, regons14: nil, regons9: nil) ⇒ Object
- #get_full_data(regon, report = 'BIR11OsPrawna') ⇒ Object
- #get_full_data_from_response(hash) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #service_status ⇒ Object
- #session_status ⇒ Object
- #status_date_state ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
18 19 20 |
# File 'lib/gus_bir1/client.rb', line 18 def initialize @logging = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (private)
102 103 104 105 106 107 108 109 |
# File 'lib/gus_bir1/client.rb', line 102 def method_missing(method, *args) if savon_client.operations.include? method response_hash = call(method, args[0]).full_hash response_hash.dig(:envelope, :body, "#{method}_response".to_sym, "#{method}_result".to_sym) else super end end |
Instance Attribute Details
#client_key ⇒ Object
Returns the value of attribute client_key.
16 17 18 |
# File 'lib/gus_bir1/client.rb', line 16 def client_key @client_key end |
#log_level ⇒ Object
Returns the value of attribute log_level.
16 17 18 |
# File 'lib/gus_bir1/client.rb', line 16 def log_level @log_level end |
#logging ⇒ Object
Returns the value of attribute logging.
16 17 18 |
# File 'lib/gus_bir1/client.rb', line 16 def logging @logging end |
#production ⇒ Object
Returns the value of attribute production.
16 17 18 |
# File 'lib/gus_bir1/client.rb', line 16 def production @production end |
Instance Method Details
#find_and_get_full_data(hash) ⇒ Object
75 76 77 78 |
# File 'lib/gus_bir1/client.rb', line 75 def find_and_get_full_data(hash) r = find_by(**hash) r.map { |h| get_full_data_from_response(h) } end |
#find_by(nip: nil, regon: nil, krs: nil, nips: nil, krss: nil, regons14: nil, regons9: nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gus_bir1/client.rb', line 38 def find_by(nip: nil, regon: nil, krs: nil, nips: nil, krss: nil, regons14: nil, regons9: nil) types = [nip, regon, krs, nips, krss, regons14, regons9].compact raise TooMuchTypesSelected if types.size > 1 raise NoOneTypeSelected if types.empty? if nip search_by Constants::SEARCH_TYPE_NIP, nip elsif regon search_by Constants::SEARCH_TYPE_REGON, regon elsif krs search_by Constants::SEARCH_TYPE_KRS, krs elsif nips search_by Constants::SEARCH_TYPE_NIPS, nips elsif regons9 search_by Constants::SEARCH_TYPE_REGONS_9, regons9 elsif regons14 search_by Constants::SEARCH_TYPE_REGONS_14, regons14 elsif krss search_by Constants::SEARCH_TYPE_KRSS, krss end end |
#get_full_data(regon, report = 'BIR11OsPrawna') ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/gus_bir1/client.rb', line 60 def get_full_data(regon, report = 'BIR11OsPrawna') set_session_id Response::FullData.new dane_pobierz_pelny_raport( Constants::PARAM_REGON => regon, Constants::PARAM_REPORT_NAME => report ) end |
#get_full_data_from_response(hash) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/gus_bir1/client.rb', line 68 def get_full_data_from_response(hash) get_full_data( hash.regon, Report::TypeMapper.get_report_type(hash) ) end |
#service_status ⇒ Object
22 23 24 25 |
# File 'lib/gus_bir1/client.rb', line 22 def service_status v = get_value(Constants::PARAM_PARAM_NAME => Constants::PARAM_SERVICE_STATUS) Response::Simple.new(v, Constants::PARAM_SERVICE_STATUS) end |
#session_status ⇒ Object
27 28 29 30 31 |
# File 'lib/gus_bir1/client.rb', line 27 def session_status set_session_id v = get_value(Constants::PARAM_PARAM_NAME => Constants::PARAM_SESSION_STATUS) Response::Simple.new(v, Constants::PARAM_SESSION_STATUS) end |
#status_date_state ⇒ Object
33 34 35 36 |
# File 'lib/gus_bir1/client.rb', line 33 def status_date_state set_session_id get_value(Constants::PARAM_PARAM_NAME => Constants::PARAM_STATUS_DATE_STATE) end |