Sha256: 3df4388fe9e274638b350af136afb5f41e779aac3657c0f476653a4b80e0a7b2

Contents?: true

Size: 1.43 KB

Versions: 81

Compression:

Stored size: 1.43 KB

Contents

module Alula
  module ApiOperations
    module Delete
      def self.extended(base)
        base.include(InstanceMethods)
      end

      module InstanceMethods
        def delete
          # payload = {
          #   data: {
          #     id: id,
          #     attributes: as_patchable_json
          #   }
          # }

          response = Alula::Client.request(:delete, resource_url)

          return true if response.ok?

          handle_errors(response)
        end

        private

        def handle_errors(response)
          # Should never see a 300-range response code
          if (300..399).cover?(response.http_status)
            raise Alula::UnknownError, "The Alula-Ruby gem encountered a response code of #{response.code}, that should not happen"

          # Server errors, malformed crap, etc
          elsif (500..599).cover?(response.http_status)
            return AlulaError.for_response(response)

          # Validation errors usually
          elsif (400..499).cover?(response.http_status)
            model_errors = Util.model_errors_from_response(response)

            if model_errors
              annotate_errors(model_errors)
              return false
            else
              return AlulaError.for_response(response)
            end
          else
            raise Alula::UnknownError, "Unknown HTTP response code, aborting. Code: #{response.http_status}"
          end
        end
      end
    end
  end
end

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
alula-ruby-2.6.1 lib/alula/api_operations/delete.rb
alula-ruby-2.6.0 lib/alula/api_operations/delete.rb
alula-ruby-2.5.0 lib/alula/api_operations/delete.rb
alula-ruby-2.4.0 lib/alula/api_operations/delete.rb
alula-ruby-2.3.0 lib/alula/api_operations/delete.rb
alula-ruby-2.2.0 lib/alula/api_operations/delete.rb
alula-ruby-2.1.2 lib/alula/api_operations/delete.rb
alula-ruby-2.1.1 lib/alula/api_operations/delete.rb
alula-ruby-2.1.0 lib/alula/api_operations/delete.rb
alula-ruby-2.0.0 lib/alula/api_operations/delete.rb
alula-ruby-1.10.5 lib/alula/api_operations/delete.rb
alula-ruby-1.10.4 lib/alula/api_operations/delete.rb
alula-ruby-1.10.3 lib/alula/api_operations/delete.rb
alula-ruby-1.10.2 lib/alula/api_operations/delete.rb
alula-ruby-1.10.1 lib/alula/api_operations/delete.rb
alula-ruby-1.10.0 lib/alula/api_operations/delete.rb
alula-ruby-1.9.17 lib/alula/api_operations/delete.rb
alula-ruby-1.9.16 lib/alula/api_operations/delete.rb
alula-ruby-1.9.15 lib/alula/api_operations/delete.rb
alula-ruby-1.9.14 lib/alula/api_operations/delete.rb