barkibu-kb 0.21.0 â 0.23.0
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/CHANGELOG.md +7 -1
- data/Gemfile.lock +5 -5
- data/README.md +20 -5
- data/barkibu-kb.gemspec +1 -1
- data/lib/kb/client_resolver.rb +2 -2
- data/lib/kb/errors/error.rb +3 -2
- data/lib/kb/fake/bounded_context/paginable.rb +18 -0
- data/lib/kb/fake/bounded_context/pet_family/pet_contracts.rb +19 -0
- data/lib/kb/models/concerns/searchable.rb +19 -0
- data/lib/kb/models/concerns.rb +1 -0
- data/lib/kb/models/pet_contract.rb +1 -0
- data/lib/kb/models/search_result.rb +11 -0
- data/lib/kb/models.rb +1 -0
- data/lib/kb/version.rb +1 -1
- metadata +7 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: aa7e82e12cf78117dbe83ba60f544050a2f46b0c24a9dacd88ff6aac23061863
         | 
| 4 | 
            +
              data.tar.gz: 9c5541c4cf7f89a55ae003fc75c3520e95fc798fe6d780242895da5797f7abf5
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f79f76c3209b161230e60e6e05522d1de24d9bc8e63c381cca6f33199b7c74ddd21dcbc3d311d866816a46abb7ba5327841919f85b820361a9e36553cea7824b
         | 
| 7 | 
            +
              data.tar.gz: 4b58d329d5271f89649153d417838ab93f30c4e0f991060522b08d21f3e716c0333eb529723866db443776411a64336b2ec909b310e092d49980d517032145f4
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -6,7 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | |
| 6 6 | 
             
            and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
         | 
| 7 7 |  | 
| 8 8 | 
             
            ## [unreleased]
         | 
| 9 | 
            -
            - See diff: https://github.com/barkibu/kb-ruby/compare/v0. | 
| 9 | 
            +
            - See diff: https://github.com/barkibu/kb-ruby/compare/v0.23.0...HEAD
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            # [0.23.0]
         | 
| 12 | 
            +
            - Add support for `.search` method on `PetContract`
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            # [0.22.0]
         | 
| 15 | 
            +
            - Fix error parsing if HTTP client returns no response
         | 
| 10 16 |  | 
| 11 17 | 
             
            ## [0.21.0]
         | 
| 12 18 | 
             
            - Add city attribute to PetParent model
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                barkibu-kb (0. | 
| 4 | 
            +
                barkibu-kb (0.23.0)
         | 
| 5 5 | 
             
                  activemodel (>= 4.0.2)
         | 
| 6 6 | 
             
                  activerecord
         | 
| 7 7 | 
             
                  activesupport (>= 3.0.0)
         | 
| @@ -10,8 +10,8 @@ PATH | |
| 10 10 | 
             
                  faraday-http
         | 
| 11 11 | 
             
                  faraday_middleware
         | 
| 12 12 | 
             
                  i18n
         | 
| 13 | 
            -
                barkibu-kb-fake (0. | 
| 14 | 
            -
                  barkibu-kb (= 0. | 
| 13 | 
            +
                barkibu-kb-fake (0.23.0)
         | 
| 14 | 
            +
                  barkibu-kb (= 0.23.0)
         | 
| 15 15 | 
             
                  countries
         | 
| 16 16 | 
             
                  sinatra
         | 
| 17 17 | 
             
                  webmock
         | 
| @@ -168,7 +168,7 @@ PLATFORMS | |
| 168 168 | 
             
            DEPENDENCIES
         | 
| 169 169 | 
             
              barkibu-kb!
         | 
| 170 170 | 
             
              barkibu-kb-fake!
         | 
| 171 | 
            -
              bundler (~>  | 
| 171 | 
            +
              bundler (~> 2.4.12)
         | 
| 172 172 | 
             
              byebug
         | 
| 173 173 | 
             
              rake (>= 12.3.3)
         | 
| 174 174 | 
             
              rspec (~> 3.0)
         | 
| @@ -178,4 +178,4 @@ DEPENDENCIES | |
| 178 178 | 
             
              webmock
         | 
| 179 179 |  | 
| 180 180 | 
             
            BUNDLED WITH
         | 
| 181 | 
            -
               2.4. | 
| 181 | 
            +
               2.4.19
         | 
    
        data/README.md
    CHANGED
    
    | @@ -117,7 +117,7 @@ KB.config.log_level = :debugger # :info by default | |
| 117 117 | 
             
              - returns all the KB::PetContract associated with this pet
         | 
| 118 118 | 
             
            - `upsert`
         | 
| 119 119 | 
             
              - updates KB:Pet if exists a Pet with same name for its PetParent
         | 
| 120 | 
            -
              - creates a new KB:Pet if not exists a Pet with same name for its PetParent | 
| 120 | 
            +
              - creates a new KB:Pet if not exists a Pet with same name for its PetParent
         | 
| 121 121 |  | 
| 122 122 | 
             
            #### PetContract đ
         | 
| 123 123 |  | 
| @@ -138,6 +138,15 @@ KB.config.log_level = :debugger # :info by default | |
| 138 138 | 
             
            - `save!`
         | 
| 139 139 | 
             
              - persists (create or update) the entity to the Knowledge Base
         | 
| 140 140 | 
             
              - throws an `KB::Error` exception if something went wrong
         | 
| 141 | 
            +
            - `search`
         | 
| 142 | 
            +
              - arg: `filters` hash. Currently, KB API supports these keys:
         | 
| 143 | 
            +
                - `page`: results page number. Default 0.
         | 
| 144 | 
            +
                - `size`: amount of results per page. Default 10.
         | 
| 145 | 
            +
                - `chip`: searches contracts by insured pet chip
         | 
| 146 | 
            +
              - returns: a hash including:
         | 
| 147 | 
            +
                - `total`: total amount of contracts found
         | 
| 148 | 
            +
                - `page`: current page number
         | 
| 149 | 
            +
                - `elements`: array of PetContract instances matching the filters
         | 
| 141 150 |  | 
| 142 151 | 
             
            #### Plan đș
         | 
| 143 152 |  | 
| @@ -234,12 +243,18 @@ You should be able to use the API seemlessly and the calls to the API will be in | |
| 234 243 | 
             
            ## Development & Testing
         | 
| 235 244 |  | 
| 236 245 | 
             
            ```bash
         | 
| 237 | 
            -
             | 
| 238 | 
            -
             | 
| 239 | 
            -
             | 
| 240 | 
            -
                > rspec
         | 
| 246 | 
            +
            docker run -it --rm -v $(pwd):/app --workdir=/app ruby:2.7.2 bash
         | 
| 247 | 
            +
            > bundle install
         | 
| 248 | 
            +
            > rspec
         | 
| 241 249 | 
             
            ```
         | 
| 242 250 |  | 
| 251 | 
            +
            You can also start an interactive console if needed:
         | 
| 252 | 
            +
            ```bash
         | 
| 253 | 
            +
            KB_API_URL_TEMPLATE=https://example.com/%{version}/%{entity} \
         | 
| 254 | 
            +
            KB_API_KEY=YourKbApiKey \
         | 
| 255 | 
            +
            KB_PARTNER_KEY=YourKbPartnerKey \
         | 
| 256 | 
            +
            bin/console
         | 
| 257 | 
            +
            ```
         | 
| 243 258 | 
             
            ## Contributing
         | 
| 244 259 |  | 
| 245 260 | 
             
            Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
         | 
    
        data/barkibu-kb.gemspec
    CHANGED
    
    | @@ -37,7 +37,7 @@ Gem::Specification.new do |spec| | |
| 37 37 | 
             
              spec.required_ruby_version = '>= 2.6'
         | 
| 38 38 |  | 
| 39 39 | 
             
              spec.add_dependency 'dry-configurable', '~> 0.9'
         | 
| 40 | 
            -
              spec.add_development_dependency 'bundler', '~>  | 
| 40 | 
            +
              spec.add_development_dependency 'bundler', '~> 2.4.12'
         | 
| 41 41 | 
             
              spec.add_development_dependency 'byebug'
         | 
| 42 42 | 
             
              spec.add_development_dependency 'rake', '>= 12.3.3'
         | 
| 43 43 | 
             
              spec.add_development_dependency 'rspec', '~> 3.0'
         | 
    
        data/lib/kb/client_resolver.rb
    CHANGED
    
    
    
        data/lib/kb/errors/error.rb
    CHANGED
    
    | @@ -7,11 +7,12 @@ module KB | |
| 7 7 | 
             
                  @status_code = status_code
         | 
| 8 8 | 
             
                  @body = body
         | 
| 9 9 | 
             
                  @message = "Received Status: #{status_code}\n#{body}"
         | 
| 10 | 
            +
                  @message = error.message if error.present? && body.nil? && status_code.nil?
         | 
| 10 11 | 
             
                  set_backtrace error.backtrace if error
         | 
| 11 12 | 
             
                end
         | 
| 12 13 |  | 
| 13 14 | 
             
                def self.from_faraday(error)
         | 
| 14 | 
            -
                  case error.response[:status | 
| 15 | 
            +
                  case error.response&.[](:status)
         | 
| 15 16 | 
             
                  when 404
         | 
| 16 17 | 
             
                    ResourceNotFound
         | 
| 17 18 | 
             
                  when 409
         | 
| @@ -20,7 +21,7 @@ module KB | |
| 20 21 | 
             
                    UnprocessableEntityError
         | 
| 21 22 | 
             
                  else
         | 
| 22 23 | 
             
                    self
         | 
| 23 | 
            -
                  end.new(error.response[:status | 
| 24 | 
            +
                  end.new(error.response&.[](:status), error.response&.[](:body), error)
         | 
| 24 25 | 
             
                end
         | 
| 25 26 | 
             
              end
         | 
| 26 27 | 
             
            end
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            module BoundedContext
         | 
| 2 | 
            +
              module Paginable
         | 
| 3 | 
            +
                extend ActiveSupport::Concern
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                included do
         | 
| 6 | 
            +
                  def paginate(list)
         | 
| 7 | 
            +
                    list = list.to_a
         | 
| 8 | 
            +
                    page = params.fetch('page', 1).to_i
         | 
| 9 | 
            +
                    page_size = params.fetch('size', 10).to_i
         | 
| 10 | 
            +
                    offset = (page - 1) * page_size
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                    { total: list.size,
         | 
| 13 | 
            +
                      page: page,
         | 
| 14 | 
            +
                      elements: list[offset, page_size] }
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
            end
         | 
| @@ -1,12 +1,15 @@ | |
| 1 1 | 
             
            require 'kb/fake/bounded_context/rest_resource'
         | 
| 2 | 
            +
            require 'kb/fake/bounded_context/paginable'
         | 
| 2 3 |  | 
| 3 4 | 
             
            module BoundedContext
         | 
| 4 5 | 
             
              module PetFamily
         | 
| 5 6 | 
             
                module PetContracts
         | 
| 6 7 | 
             
                  extend ActiveSupport::Concern
         | 
| 7 8 |  | 
| 9 | 
            +
                  # rubocop:disable Metrics/BlockLength
         | 
| 8 10 | 
             
                  included do
         | 
| 9 11 | 
             
                    include RestResource
         | 
| 12 | 
            +
                    include Paginable
         | 
| 10 13 |  | 
| 11 14 | 
             
                    get '/v1/petcontracts/contractnumber/:contract_number' do
         | 
| 12 15 | 
             
                      resource = resource_state(:petcontracts).detect do |contract|
         | 
| @@ -17,8 +20,24 @@ module BoundedContext | |
| 17 20 | 
             
                      json_response 200, resource
         | 
| 18 21 | 
             
                    end
         | 
| 19 22 |  | 
| 23 | 
            +
                    get '/v1/petcontracts/search' do
         | 
| 24 | 
            +
                      return json_response 400, {} unless params['chip']
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                      pet_by_chip = resource_state(:pets).detect do |pet|
         | 
| 27 | 
            +
                        pet['chip'] == params['chip']
         | 
| 28 | 
            +
                      end
         | 
| 29 | 
            +
                      return json_response 200, paginate([]) if pet_by_chip.nil?
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                      contracts = resource_state(:petcontracts).select do |contract|
         | 
| 32 | 
            +
                        contract['petKey'] == pet_by_chip['key']
         | 
| 33 | 
            +
                      end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                      json_response 200, paginate(contracts)
         | 
| 36 | 
            +
                    end
         | 
| 37 | 
            +
             | 
| 20 38 | 
             
                    resource :petcontracts, except: %i[index destroy]
         | 
| 21 39 | 
             
                  end
         | 
| 40 | 
            +
                  # rubocop:enable Metrics/BlockLength
         | 
| 22 41 | 
             
                end
         | 
| 23 42 | 
             
              end
         | 
| 24 43 | 
             
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module KB
         | 
| 2 | 
            +
              module Searchable
         | 
| 3 | 
            +
                extend ActiveSupport::Concern
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                included do
         | 
| 6 | 
            +
                  include Queryable
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                module ClassMethods
         | 
| 10 | 
            +
                  def search(filters)
         | 
| 11 | 
            +
                    response = kb_client.request('search', filters: filters).symbolize_keys
         | 
| 12 | 
            +
                    elements = response[:elements].map { |contract| from_api(contract) }
         | 
| 13 | 
            +
                    KB::SearchResult.new(**response.merge(elements: elements))
         | 
| 14 | 
            +
                  rescue Faraday::Error => e
         | 
| 15 | 
            +
                    raise KB::Error.from_faraday(e)
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
    
        data/lib/kb/models/concerns.rb
    CHANGED
    
    
    
        data/lib/kb/models.rb
    CHANGED
    
    
    
        data/lib/kb/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: barkibu-kb
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.23.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Léo Figea
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023- | 
| 11 | 
            +
            date: 2023-09-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: dry-configurable
         | 
| @@ -30,14 +30,14 @@ dependencies: | |
| 30 30 | 
             
                requirements:
         | 
| 31 31 | 
             
                - - "~>"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version:  | 
| 33 | 
            +
                    version: 2.4.12
         | 
| 34 34 | 
             
              type: :development
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 38 | 
             
                - - "~>"
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version:  | 
| 40 | 
            +
                    version: 2.4.12
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: byebug
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -276,6 +276,7 @@ files: | |
| 276 276 | 
             
            - lib/kb/errors/unprocessable_entity_error.rb
         | 
| 277 277 | 
             
            - lib/kb/fake.rb
         | 
| 278 278 | 
             
            - lib/kb/fake/api.rb
         | 
| 279 | 
            +
            - lib/kb/fake/bounded_context/paginable.rb
         | 
| 279 280 | 
             
            - lib/kb/fake/bounded_context/pet_family/breeds.rb
         | 
| 280 281 | 
             
            - lib/kb/fake/bounded_context/pet_family/hubspot_relationship.rb
         | 
| 281 282 | 
             
            - lib/kb/fake/bounded_context/pet_family/pet_contracts.rb
         | 
| @@ -296,6 +297,7 @@ files: | |
| 296 297 | 
             
            - lib/kb/models/concerns/inspectionable.rb
         | 
| 297 298 | 
             
            - lib/kb/models/concerns/listable.rb
         | 
| 298 299 | 
             
            - lib/kb/models/concerns/queryable.rb
         | 
| 300 | 
            +
            - lib/kb/models/concerns/searchable.rb
         | 
| 299 301 | 
             
            - lib/kb/models/concerns/updatable.rb
         | 
| 300 302 | 
             
            - lib/kb/models/concerns/upsertable.rb
         | 
| 301 303 | 
             
            - lib/kb/models/condition.rb
         | 
| @@ -306,6 +308,7 @@ files: | |
| 306 308 | 
             
            - lib/kb/models/plan.rb
         | 
| 307 309 | 
             
            - lib/kb/models/product.rb
         | 
| 308 310 | 
             
            - lib/kb/models/referral.rb
         | 
| 311 | 
            +
            - lib/kb/models/search_result.rb
         | 
| 309 312 | 
             
            - lib/kb/models/symptom.rb
         | 
| 310 313 | 
             
            - lib/kb/type/array_of_conditions_type.rb
         | 
| 311 314 | 
             
            - lib/kb/type/array_of_strings_type.rb
         |