Sha256: 3015abb47eedc065a515b144bf7373435c741d1adde7f5a68a4ef220b2a01f6f

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

module Nova
  module API
    module Resource
      class Receivable < Nova::API::Resource::Bill
        ALLOWED_ATTRIBUTES = Nova::API::Resource::Bill::ALLOWED_ATTRIBUTES.dup << :gross_value

        attribute? :gross_value, Dry::Types['coercible.decimal'].optional

        def self.endpoint
          '/api/receivables'
        end

        def self.create(parameters)
          model = new parameters

          model.attributes.delete(:id)

          model.save
        end

        def self.update(id, parameters)
          model = new parameters.merge(id: id)

          model.update
        end

        def self.destroy(id)
          model = initialize_empty_model_with_id(self, id, date: Date.today.iso8601, first_due_date: Date.today.iso8601)

          model.destroy
        end

        def endpoint
          protect_operation_from_missing_value

          "/api/receivables/#{id}"
        end

        def save
          if id.nil?
            do_post(self.class.endpoint, allowed_attributes)
          else
            do_patch("#{endpoint}", allowed_attributes)
          end
        end

        def update
          protect_operation_from_missing_value

          do_patch("#{endpoint}", allowed_attributes)
        end

        def destroy
          protect_operation_from_missing_value

          do_delete("#{endpoint}")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nova-api-0.6.0 lib/nova/api/resource/receivable.rb
nova-api-0.5.0 lib/nova/api/resource/receivable.rb