Module: SparkApi::Models::Concerns::Destroyable

Included in:
SparkApi::Models::Comment, SparkApi::Models::Contact, IncompleteListing, ListingCart, Newsfeed, QuickSearch, SavedSearch, Video, VirtualTour, VowAccount
Defined in:
lib/spark_api/models/concerns/destroyable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/spark_api/models/concerns/destroyable.rb', line 7

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#destroy(arguments = {}) ⇒ Object Also known as: delete



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/spark_api/models/concerns/destroyable.rb', line 20

def destroy(arguments = {})
  self.errors = []
  begin
    return destroy!(arguments)
  rescue BadResourceRequest => e
    self.errors << {:code => e.code, :message => e.message}
    SparkApi.logger.error("Failed to destroy resource #{self}: #{e.message}")
  rescue NotFound => e
    SparkApi.logger.error("Failed to destroy resource #{self}: #{e.message}")
  end
  false
end

#destroy!(arguments = {}) ⇒ Object



32
33
34
35
36
# File 'lib/spark_api/models/concerns/destroyable.rb', line 32

def destroy!(arguments = {})
  connection.delete(resource_uri, arguments) if persisted?
  @destroyed = true
  true
end

#destroyed?Boolean

Returns:

  • (Boolean)


39
# File 'lib/spark_api/models/concerns/destroyable.rb', line 39

def destroyed?; @destroyed ? @destroyed : false end