Sha256: 5d7f3f1d4d169859adabe170920a3ea2f32dcb07f52972ec007eafedeefd0282

Contents?: true

Size: 1.16 KB

Versions: 8

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Dhis2
  module Api
    module Shared
      module SaveValidator
        def self.included(base)
          base.extend(ClassMethods)
        end

        private

        def validate_instance_update(response)
          unless instance_update_success?(response)
            raise Dhis2::UpdateError, "Update error. #{response}"
          end
        end

        def instance_update_success?(response)
          self.class.base_response_check(response) &&
            response["http_status"] == "OK"
        end

        module ClassMethods
          def validate_instance_creation(response)
            unless instance_creation_success?(response)
              raise Dhis2::CreationError, "Creation error. #{response}"
            end
          end

          def instance_creation_success?(response)
            base_response_check(response) &&
              response["http_status"] == "Created"
          end

          def created_instance_id(response)
            response["response"]["uid"]
          end

          def base_response_check(response)
            response["status"] == "OK"
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dhis2-3.3.1 lib/dhis2/api/shared/save_validator.rb
dhis2-3.2.1 lib/dhis2/api/shared/save_validator.rb
dhis2-3.0.7 lib/dhis2/api/shared/save_validator.rb
dhis2-3.0.5 lib/dhis2/api/shared/save_validator.rb
dhis2-3.0.4 lib/dhis2/api/shared/save_validator.rb
dhis2-3.0.3 lib/dhis2/api/shared/save_validator.rb
dhis2-3.0.2 lib/dhis2/api/shared/save_validator.rb
dhis2-3.0.0 lib/dhis2/api/shared/save_validator.rb