ratsit 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/ratsit.rb +82 -58
- data/lib/ratsit/errors.rb +3 -0
- data/lib/ratsit/filter/filter.rb +212 -0
- data/lib/ratsit/filter/filter_company.rb +27 -0
- data/lib/ratsit/filter/filter_get_annual_report.rb +21 -0
- data/lib/ratsit/filter/filter_get_companies.rb +27 -0
- data/lib/ratsit/filter/filter_get_company_information_package.rb +23 -0
- data/lib/ratsit/filter/filter_get_person_information_package.rb +23 -0
- data/lib/ratsit/filter/filter_person.rb +30 -0
- data/lib/ratsit/filter/filter_search_one_person.rb +26 -0
- data/lib/ratsit/filter/filter_search_persons.rb +34 -0
- data/lib/ratsit/request/open_request.rb +65 -0
- data/lib/ratsit/request/request.rb +48 -0
- data/lib/ratsit/request/request_get_companies.rb +46 -0
- data/lib/ratsit/request/request_search_one_person.rb +41 -0
- data/lib/ratsit/request/request_search_persons.rb +47 -0
- data/lib/ratsit/request/token_request.rb +35 -0
- data/lib/ratsit/version.rb +2 -1
- data/ratsit.gemspec +3 -2
- metadata +35 -9
- data/lib/ratsit/filters.rb +0 -155
- data/lib/ratsit/package.rb +0 -22
- data/lib/ratsit/person.rb +0 -39
- data/lib/ratsit/request.rb +0 -80
- data/lib/ratsit/search_type.rb +0 -19
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2e5949f1ca309cd41832cb8f648f0f51e6957302
         | 
| 4 | 
            +
              data.tar.gz: 53be756f285f8a21e755a09c62428b2b588abe00
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: bf45d638a1fd05c20c29fe7ebf3c9ea49d85826dc195797ffbf1171c97d7b386494cb5438a4d111e64a176b47b2955316e43ef5c8bf6296563caef0986bc372c
         | 
| 7 | 
            +
              data.tar.gz: be59024c037d0b9597d2ed7168a46d1fc45331a985a4b909fb9b9f3e16ce6d0b09206b06d9938b7a927c53b3742843d2441c6d43f6346020f49d1679ea9bc31c
         | 
    
        data/README.md
    CHANGED
    
    
    
        data/lib/ratsit.rb
    CHANGED
    
    | @@ -1,82 +1,106 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
            require 'ratsit/package'
         | 
| 3 | 
            -
            require 'ratsit/search_type'
         | 
| 4 | 
            -
            require 'ratsit/request'
         | 
| 5 | 
            -
            require 'ratsit/filters'
         | 
| 1 | 
            +
             | 
| 6 2 | 
             
            require 'ratsit/errors'
         | 
| 7 | 
            -
            require ' | 
| 3 | 
            +
            require 'ratsit/monkey'
         | 
| 4 | 
            +
            require 'ratsit/version'
         | 
| 8 5 |  | 
| 9 | 
            -
             | 
| 6 | 
            +
            require 'ratsit/filter/filter'
         | 
| 7 | 
            +
            require 'ratsit/filter/filter_company'
         | 
| 8 | 
            +
            require 'ratsit/filter/filter_get_annual_report'
         | 
| 9 | 
            +
            require 'ratsit/filter/filter_get_companies'
         | 
| 10 | 
            +
            require 'ratsit/filter/filter_get_company_information_package'
         | 
| 11 | 
            +
            require 'ratsit/filter/filter_get_person_information_package'
         | 
| 12 | 
            +
            require 'ratsit/filter/filter_person'
         | 
| 13 | 
            +
            require 'ratsit/filter/filter_search_one_person'
         | 
| 14 | 
            +
            require 'ratsit/filter/filter_search_persons'
         | 
| 10 15 |  | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            +
            require 'ratsit/request/request'
         | 
| 17 | 
            +
            require 'ratsit/request/open_request'
         | 
| 18 | 
            +
            require 'ratsit/request/token_request'
         | 
| 19 | 
            +
            require 'ratsit/request/request_get_companies'
         | 
| 20 | 
            +
            require 'ratsit/request/request_search_one_person'
         | 
| 21 | 
            +
            require 'ratsit/request/request_search_persons'
         | 
| 16 22 |  | 
| 17 | 
            -
              class RatsitSearch
         | 
| 18 23 |  | 
| 19 | 
            -
             | 
| 20 | 
            -
                attr_reader :results
         | 
| 24 | 
            +
            module Ratsit
         | 
| 21 25 |  | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
                   | 
| 26 | 
            -
                  @api_key = @env_api_key
         | 
| 26 | 
            +
              def Ratsit.get_api_key
         | 
| 27 | 
            +
                key_key = 'RATSIT_API_KEY'
         | 
| 28 | 
            +
                if ENV[key_key].nil?
         | 
| 29 | 
            +
                  raise RatsitError, 'No api key specified'
         | 
| 27 30 | 
             
                end
         | 
| 31 | 
            +
                return ENV[key_key]
         | 
| 32 | 
            +
              end
         | 
| 28 33 |  | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
                  end
         | 
| 33 | 
            -
                  if search_arg.length == 0
         | 
| 34 | 
            -
                    raise RatsitError, 'Invalid search argument length'
         | 
| 35 | 
            -
                  end
         | 
| 36 | 
            -
                  if !search_area.is_a?(String)
         | 
| 37 | 
            -
                    raise RatsitError, 'Invalid search area'
         | 
| 38 | 
            -
                  end
         | 
| 39 | 
            -
                  request_class = (!@api_key.nil?)? Ratsit::RatsitTokenRequest: Ratsit::RatsitOpenRequest
         | 
| 40 | 
            -
                  @request = request_class.new(search_arg, search_area, @search_type, @filter)
         | 
| 41 | 
            -
                  @request.exec()
         | 
| 42 | 
            -
                  # check this...
         | 
| 43 | 
            -
                  if @request.response_ok
         | 
| 44 | 
            -
                    #puts "response ok"
         | 
| 45 | 
            -
                    #@results = @request.response_body.to_json
         | 
| 46 | 
            -
                    @results = @request.response_body
         | 
| 47 | 
            -
                  else
         | 
| 48 | 
            -
                    @results = nil
         | 
| 49 | 
            -
                  end
         | 
| 50 | 
            -
                  @results
         | 
| 34 | 
            +
              def Ratsit.OpenPersonSearch(search_term, search_area, filter_instance=nil)
         | 
| 35 | 
            +
                if !filter_instance.nil? && !filter_instance.instance_of?(Ratsit::Filter::PersonFilter)
         | 
| 36 | 
            +
                  raise RatsitFilterError, 'Invalid filter given to function'
         | 
| 51 37 | 
             
                end
         | 
| 38 | 
            +
                req = Ratsit::Request::OpenRequest.new(Ratsit::Request::OPEN_REQUEST_EPTS[:person], search_term, search_area, filter_instance || Ratsit::Filter::PersonFilter.new())
         | 
| 39 | 
            +
                req.exec()
         | 
| 40 | 
            +
                if req.response_ok
         | 
| 41 | 
            +
                  return req.response_body
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
                nil
         | 
| 44 | 
            +
              end
         | 
| 52 45 |  | 
| 46 | 
            +
              def Ratsit.OpenCompanySearch(search_term, search_area, filter_instance=nil)
         | 
| 47 | 
            +
                if !filter_instance.nil? && !filter_instance.instance_of?(Ratsit::Filter::CompanyFilter)
         | 
| 48 | 
            +
                  raise RatsitFilterError, 'Invalid filter given to function'
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
                req = Ratsit::Request::OpenRequest.new(Ratsit::Request::OPEN_REQUEST_EPTS[:company], search_term, search_area, filter_instance || Ratsit::Filter::CompanyFilter.new())
         | 
| 51 | 
            +
                req.exec()
         | 
| 52 | 
            +
                if req.response_ok
         | 
| 53 | 
            +
                  return req.response_body
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
                nil
         | 
| 53 56 | 
             
              end
         | 
| 54 57 |  | 
| 55 | 
            -
               | 
| 58 | 
            +
              def Ratsit.doTokenRequest(req_class, filter_args)
         | 
| 59 | 
            +
                  req = req_class.new(filter_args)
         | 
| 60 | 
            +
                  puts req
         | 
| 61 | 
            +
                  req.exec()
         | 
| 62 | 
            +
                  return req.response
         | 
| 63 | 
            +
                nil
         | 
| 64 | 
            +
              end
         | 
| 56 65 |  | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
                end
         | 
| 66 | 
            +
              def Ratsit.SearchCompanies(args=nil)
         | 
| 67 | 
            +
                return Ratsit.doTokenRequest(Ratsit::Request::GetCompaniesRequest, args)
         | 
| 68 | 
            +
              end
         | 
| 61 69 |  | 
| 70 | 
            +
              def Ratsit.SearchOnePerson(args=nil)
         | 
| 71 | 
            +
                return Ratsit.doTokenRequest(Ratsit::Request::SearchOnePersonRequest, args)
         | 
| 62 72 | 
             
              end
         | 
| 63 73 |  | 
| 64 | 
            -
               | 
| 74 | 
            +
              def Ratsit.SearchPersons(args=nil)
         | 
| 75 | 
            +
                return Ratsit.doTokenRequest(Ratsit::Request::SearchPersonsRequest, args)
         | 
| 76 | 
            +
              end
         | 
| 65 77 |  | 
| 66 | 
            -
                def initialize()
         | 
| 67 | 
            -
                  super(Ratsit::SEARCH_TYPE_COMPANY, Ratsit::CompanyFilter.new())
         | 
| 68 | 
            -
                  self
         | 
| 69 | 
            -
                end
         | 
| 70 78 |  | 
| 79 | 
            +
            end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            =begin
         | 
| 82 | 
            +
              def Ratsit.GetAnnualReport(args=nil)
         | 
| 83 | 
            +
                return Ratsit.doTokenRequest('GetAnnualReport', Ratsit.parseFilterArgs(args, Ratsit::Filter::GetAnnualReportFilter))
         | 
| 71 84 | 
             
              end
         | 
| 72 85 |  | 
| 73 | 
            -
               | 
| 86 | 
            +
              def Ratsit.GetCompanies(args=nil)
         | 
| 87 | 
            +
                return Ratsit.doTokenRequest('GetCompanies', Ratsit.parseFilterArgs(args, Ratsit::Filter::GetCompaniesFilter))
         | 
| 88 | 
            +
              end
         | 
| 74 89 |  | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
                end
         | 
| 90 | 
            +
              def Ratsit.GetCompanyInformationPackage(args=nil)
         | 
| 91 | 
            +
                return Ratsit.doTokenRequest('GetCompanyInformationPackage', Ratsit.parseFilterArgs(args, Ratsit::Filter::GetCompanyInformationPackageFilter))
         | 
| 92 | 
            +
              end
         | 
| 79 93 |  | 
| 94 | 
            +
              def Ratsit.GetPersonInformationPackage(args=nil)
         | 
| 95 | 
            +
                return Ratsit.doTokenRequest('GetPersonInformationPackage', Ratsit.parseFilterArgs(args, Ratsit::Filter::GetPersonInformationPackageFilter))
         | 
| 80 96 | 
             
              end
         | 
| 81 97 |  | 
| 82 | 
            -
             | 
| 98 | 
            +
              def Ratsit.SearchOnePerson(args=nil)
         | 
| 99 | 
            +
                return Ratsit.doTokenRequest('SearchOnePerson', Ratsit.parseFilterArgs(args, Ratsit::Filter::SearchOnePersonFilter))
         | 
| 100 | 
            +
              end
         | 
| 101 | 
            +
             | 
| 102 | 
            +
              def Ratsit.SearchPersons(args=nil)
         | 
| 103 | 
            +
                return Ratsit.doTokenRequest('SearchPersons', Ratsit.parseFilterArgs(args, Ratsit::Filter::SearchPersonsFilter))
         | 
| 104 | 
            +
              end
         | 
| 105 | 
            +
            =end
         | 
| 106 | 
            +
             | 
    
        data/lib/ratsit/errors.rb
    CHANGED
    
    
| @@ -0,0 +1,212 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            require 'json'
         | 
| 3 | 
            +
            require 'ratsit/errors'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Ratsit
         | 
| 6 | 
            +
              module Filter
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                # Person filters
         | 
| 9 | 
            +
                FILTER_MARRIED = 'Married'
         | 
| 10 | 
            +
                FILTER_UNMARRIED = 'Unmarried'
         | 
| 11 | 
            +
                FILTER_MALE = 'Male'
         | 
| 12 | 
            +
                FILTER_FEMALE = 'Female'
         | 
| 13 | 
            +
                FILTER_COMPANY_ENGAGEMENT = 'CompanyEngagement'
         | 
| 14 | 
            +
                FILTER_NO_COMPANY_ENGAGEMENT = 'NoCompanyEngagement'
         | 
| 15 | 
            +
                FILTER_AGE_FROM = 'AgeFrom'
         | 
| 16 | 
            +
                FILTER_AGE_TO = 'AgeTo'
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                FILTER_FIRST_NAME = 'firstName'
         | 
| 19 | 
            +
                FILTER_LAST_NAME = 'lastName'
         | 
| 20 | 
            +
                FILTER_SSN = 'ssn'
         | 
| 21 | 
            +
                FILTER_USE_PHONETIC_SEARCH = 'usePhoneticSearch'
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                # Company filters
         | 
| 24 | 
            +
                FILTER_AB = 'AB'
         | 
| 25 | 
            +
                FILTER_EF = 'EF'
         | 
| 26 | 
            +
                FILTER_HB = 'HB'
         | 
| 27 | 
            +
                FILTER_KB = 'KB'
         | 
| 28 | 
            +
                FILTER_HB_KB = "#{FILTER_HB}/#{FILTER_KB}"
         | 
| 29 | 
            +
                FILTER_OTHER = 'Other'
         | 
| 30 | 
            +
             | 
| 31 | 
            +
             | 
| 32 | 
            +
                # token filters
         | 
| 33 | 
            +
                FILTER_TOKEN = 'token'
         | 
| 34 | 
            +
                FILTER_IDS = 'IDs'
         | 
| 35 | 
            +
                FILTER_COMPANY_NAME = 'companyName'
         | 
| 36 | 
            +
                FILTER_ADDRESS = 'address'
         | 
| 37 | 
            +
                FILTER_ZIP_CODE = 'zipCode'
         | 
| 38 | 
            +
                FILTER_CITY = 'city'
         | 
| 39 | 
            +
                FILTER_MUNICIPALITY = 'municipality'
         | 
| 40 | 
            +
                FILTER_PHONE = 'phone'
         | 
| 41 | 
            +
                FILTER_COMPANY_TYPE = 'companyType'
         | 
| 42 | 
            +
                FILTER_SEARCH_AGE = 'searchAge'
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                FILTER_PACKAGES = 'packages'
         | 
| 45 | 
            +
                FILTER_ORG_NR = 'orgnr'
         | 
| 46 | 
            +
                FILTER_PNR = 'pnr'
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                FILTER_NUMBER_OF_HITS = 'numberOfHits'
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                FILTER_PACKAGE_SMALL_1 = 'small 1'
         | 
| 51 | 
            +
                FILTER_PACKAGE_SMALL_2 = 'small 2'
         | 
| 52 | 
            +
                FILTER_PACKAGE_SMALL_3 = 'small 3'
         | 
| 53 | 
            +
                FILTER_PACKAGE_REMARK = 'anmärkning'
         | 
| 54 | 
            +
                FILTER_PACKAGE_MEDIUM = 'medium'
         | 
| 55 | 
            +
                FILTER_PACKAGE_LARGE = 'large'
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                class RatsitFilter
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                  def abstract(msg=nil)
         | 
| 60 | 
            +
                    _msg = msg || 'This class should not be used directly'
         | 
| 61 | 
            +
                    raise RatsitAbstractError, _msg
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  def initialize()
         | 
| 65 | 
            +
                    @abstract_interface_msg = 'This interface is abstract. Implement method in subclass'
         | 
| 66 | 
            +
                    if self.instance_of?(RatsitFilter)
         | 
| 67 | 
            +
                      abstract
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
                    @active_filters = {}
         | 
| 70 | 
            +
                    @filter_defaults = {}
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  def active_filters
         | 
| 74 | 
            +
                    return (@active_filters.nil?)? nil: @active_filters
         | 
| 75 | 
            +
                  end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                  def to_json
         | 
| 78 | 
            +
                    af = self.active_filters
         | 
| 79 | 
            +
                    return '{}' if af.nil?
         | 
| 80 | 
            +
                    af.to_json
         | 
| 81 | 
            +
                  end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                  def to_obj
         | 
| 84 | 
            +
                    @active_filters
         | 
| 85 | 
            +
                  end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                  def update(filter_key='', filter_value)
         | 
| 88 | 
            +
                    #puts "update #{filter_key}: #{filter_value}"
         | 
| 89 | 
            +
                    if !filter_key.is_a?(String)
         | 
| 90 | 
            +
                      raise RatsitFilterError, 'Invalid filter key'
         | 
| 91 | 
            +
                    end
         | 
| 92 | 
            +
                    if filter_value.nil?
         | 
| 93 | 
            +
                      raise RatsitFilterError, 'Invalid filter value'
         | 
| 94 | 
            +
                    end
         | 
| 95 | 
            +
                    if !@active_filters.has_key?(filter_key)
         | 
| 96 | 
            +
                      raise RatsitFilterError, 'Non-existent filter key'
         | 
| 97 | 
            +
                    end
         | 
| 98 | 
            +
                    @curr_filters = Marshal.load(Marshal.dump(@active_filters))
         | 
| 99 | 
            +
                    @curr_filters[filter_key] = filter_value
         | 
| 100 | 
            +
                    @active_filters = validate_filters(@filter_defaults, @curr_filters)
         | 
| 101 | 
            +
                  end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                  def reset(filter_name='')
         | 
| 104 | 
            +
                    if !filter_name.is_a?(String)
         | 
| 105 | 
            +
                      raise RatsitFilterError, 'Invalid filter key'
         | 
| 106 | 
            +
                    end
         | 
| 107 | 
            +
                    if !@filter_defaults.has_key?(filter_name)
         | 
| 108 | 
            +
                      raise RatsitFilterError, 'Non-existent filter key'
         | 
| 109 | 
            +
                    end
         | 
| 110 | 
            +
                    @active_filters[filter_name] = @filter_defaults[filter_name][:default]
         | 
| 111 | 
            +
                  end
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                end
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                private
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                def parse_string(arg)
         | 
| 118 | 
            +
                  return arg if arg.is_a?(String)
         | 
| 119 | 
            +
                  raise RatsitFilterError, 'Invalid string'
         | 
| 120 | 
            +
                end
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                def parse_bool(arg)
         | 
| 123 | 
            +
                  return arg if arg.is_a?(TrueClass) || arg.is_a?(FalseClass)
         | 
| 124 | 
            +
                  raise RatsitFilterError, 'Invalid bool representation' if !arg.is_a?(String)
         | 
| 125 | 
            +
                  return true if arg.downcase == 'true'
         | 
| 126 | 
            +
                  return false if arg.downcase == 'false'
         | 
| 127 | 
            +
                  raise RatsitFilterError, 'Invalid textual bool value'
         | 
| 128 | 
            +
                end
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                def parse_bool_string(arg)
         | 
| 131 | 
            +
                  return arg if arg == 'true' || arg == 'false'
         | 
| 132 | 
            +
                  return 'true' if arg.is_a?(TrueClass)
         | 
| 133 | 
            +
                  return 'false' if arg.is_a?(FalseClass)
         | 
| 134 | 
            +
                  raise RatsitFilterError, 'Invalid string representation of bool'
         | 
| 135 | 
            +
                end
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                def parse_age(arg)
         | 
| 138 | 
            +
                  if arg.is_a?(String)
         | 
| 139 | 
            +
                    if !(arg =~ /^[0-9]+$/)
         | 
| 140 | 
            +
                      raise RatsitFilterError, 'Invalid age in filter'
         | 
| 141 | 
            +
                    end
         | 
| 142 | 
            +
                    larg = arg.to_i
         | 
| 143 | 
            +
                  elsif arg.is_a?(Integer)
         | 
| 144 | 
            +
                    larg = arg
         | 
| 145 | 
            +
                  else
         | 
| 146 | 
            +
                    raise RatsitFilterError, 'Invalid arg type in filter'
         | 
| 147 | 
            +
                  end
         | 
| 148 | 
            +
                  # ratsit specifies these ages.
         | 
| 149 | 
            +
                  if larg < 0 || larg > 150
         | 
| 150 | 
            +
                    raise RatsitFilterError, 'Invalid age'
         | 
| 151 | 
            +
                  end
         | 
| 152 | 
            +
                  "#{larg}"
         | 
| 153 | 
            +
                end
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                def parse_int(arg)
         | 
| 156 | 
            +
                  return arg if arg.is_a?(Integer)
         | 
| 157 | 
            +
                  return arg.to_i if arg =~ /^[0-9]+$/
         | 
| 158 | 
            +
                  raise RatsitFilterError, 'Invalid integer'
         | 
| 159 | 
            +
                end
         | 
| 160 | 
            +
             | 
| 161 | 
            +
                def parse_list(arg)
         | 
| 162 | 
            +
                  return arg.join(',') if arg.is_a?(Array)
         | 
| 163 | 
            +
                  return arg if arg.is_a?(String)
         | 
| 164 | 
            +
                  raise RatsitFilterError, 'Invalid array'
         | 
| 165 | 
            +
                end
         | 
| 166 | 
            +
             | 
| 167 | 
            +
                def validate_list(lst, accepted_values=[])
         | 
| 168 | 
            +
                  if lst.is_a?(Array)
         | 
| 169 | 
            +
                    arr = lst
         | 
| 170 | 
            +
                  elsif lst.is_a?(String)
         | 
| 171 | 
            +
                    arr = lst.split(',').map(&:strip)
         | 
| 172 | 
            +
                  end
         | 
| 173 | 
            +
                  err = []
         | 
| 174 | 
            +
                  arr.each { |v| err.push(v) if !accepted_values.include?(v) }
         | 
| 175 | 
            +
                  if err.length > 0
         | 
| 176 | 
            +
                    raise RatsitFilterError, "Invalid list values: #{err.join(',')}"
         | 
| 177 | 
            +
                  end
         | 
| 178 | 
            +
                  arr.join(',')
         | 
| 179 | 
            +
                end
         | 
| 180 | 
            +
             | 
| 181 | 
            +
                def validate_company_types(lst)
         | 
| 182 | 
            +
                  return validate_list(lst, [FILTER_AB, FILTER_EF, FILTER_HB_KB, FILTER_OTHER])
         | 
| 183 | 
            +
                end
         | 
| 184 | 
            +
             | 
| 185 | 
            +
                def validate_package_types(lst)
         | 
| 186 | 
            +
                  return validate_list(lst, [FILTER_PACKAGE_SMALL_1, FILTER_PACKAGE_SMALL_2, FILTER_PACKAGE_SMALL_3, FILTER_PACKAGE_REMARK, FILTER_PACKAGE_MEDIUM, FILTER_PACKAGE_LARGE])
         | 
| 187 | 
            +
                end
         | 
| 188 | 
            +
             | 
| 189 | 
            +
                def validate_filters(filter_defaults={}, filters={})
         | 
| 190 | 
            +
                  if !filters.is_a?(Hash)
         | 
| 191 | 
            +
                    filters = {}
         | 
| 192 | 
            +
                  end
         | 
| 193 | 
            +
                  filters.reject! { |k,_| !filter_defaults.keys.include? k }
         | 
| 194 | 
            +
                  filter_defaults.each do |filter_name, defs|
         | 
| 195 | 
            +
                    if !filters.keys.include? filter_name
         | 
| 196 | 
            +
                      filters[filter_name] = defs[:default]
         | 
| 197 | 
            +
                    end
         | 
| 198 | 
            +
                    filters[filter_name] = defs[:parse].call(filters[filter_name])
         | 
| 199 | 
            +
                    if defs.has_key?(:validate)
         | 
| 200 | 
            +
                      filters[filter_name] = defs[:validate].call(filters[filter_name])
         | 
| 201 | 
            +
                    end
         | 
| 202 | 
            +
                  end
         | 
| 203 | 
            +
                  if filters.keys.include?(FILTER_AGE_TO) && filters.keys.include?(FILTER_AGE_FROM)
         | 
| 204 | 
            +
                    if filters[FILTER_AGE_TO].to_i < filters[FILTER_AGE_FROM].to_i
         | 
| 205 | 
            +
                      raise RatsitFilterError, 'Invalid age span'
         | 
| 206 | 
            +
                    end
         | 
| 207 | 
            +
                  end
         | 
| 208 | 
            +
                  filters
         | 
| 209 | 
            +
                end
         | 
| 210 | 
            +
             | 
| 211 | 
            +
              end
         | 
| 212 | 
            +
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'ratsit/errors'
         | 
| 4 | 
            +
            require 'ratsit/filter/filter'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module Ratsit
         | 
| 7 | 
            +
              module Filter
         | 
| 8 | 
            +
             | 
| 9 | 
            +
             | 
| 10 | 
            +
             | 
| 11 | 
            +
                class CompanyFilter < Ratsit::Filter::RatsitFilter
         | 
| 12 | 
            +
                  include Ratsit::Filter
         | 
| 13 | 
            +
                  #{"AB":true,"EF":true,"HB":true,"Other":true}
         | 
| 14 | 
            +
                  def initialize(filters={})
         | 
| 15 | 
            +
                    super()
         | 
| 16 | 
            +
                    @filter_defaults = {
         | 
| 17 | 
            +
                        FILTER_AB => {:parse => method(:parse_bool), :default => true},
         | 
| 18 | 
            +
                        FILTER_EF => {:parse => method(:parse_bool), :default => true},
         | 
| 19 | 
            +
                        FILTER_HB => {:parse => method(:parse_bool), :default => true},
         | 
| 20 | 
            +
                        FILTER_OTHER => {:parse => method(:parse_bool), :default => true}
         | 
| 21 | 
            +
                    }
         | 
| 22 | 
            +
                    @active_filters = validate_filters(@filter_defaults, filters)
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            require 'ratsit/errors'
         | 
| 3 | 
            +
            require 'ratsit/filter/filter'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Ratsit
         | 
| 6 | 
            +
              module Filter
         | 
| 7 | 
            +
                class GetAnnualReportFilter < Ratsit::Filter::RatsitFilter
         | 
| 8 | 
            +
                  include Ratsit::Filter
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def initialize(filters={})
         | 
| 11 | 
            +
                    super()
         | 
| 12 | 
            +
                    @filter_defaults = {
         | 
| 13 | 
            +
                        FILTER_TOKEN => {:parse => method(:parse_string), :default => Ratsit.get_api_key()},
         | 
| 14 | 
            +
                        FILTER_IDS => {:parse => method(:parse_list), :default => '', :validate => method(:validate_list)}
         | 
| 15 | 
            +
                    }
         | 
| 16 | 
            +
                    @active_filters = validate_filters(@filter_defaults, filters)
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         |