Class: ESP::Suppression

Inherits:
Resource
  • Object
show all
Defined in:
lib/esp/resources/suppression.rb,
lib/esp/resources/suppression/region.rb,
lib/esp/resources/suppression/signature.rb,
lib/esp/resources/suppression/unique_identifier.rb

Defined Under Namespace

Classes: Region, Signature, UniqueIdentifier

Constant Summary

Constants inherited from Resource

Resource::PREDICATES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

arrange_options, filters, find, make_pageable, #serializable_hash, where

Class Method Details

.element_nameObject

Overriden so the correct param is sent on the has_many relationships. API needs this one to be plural.



52
53
54
# File 'lib/esp/resources/suppression.rb', line 52

def self.element_name # :nodoc:
  'suppressions'
end

Instance Method Details

#created_byObject

The user who created the suppression.



13
# File 'lib/esp/resources/suppression.rb', line 13

belongs_to :created_by, class_name: 'ESP::User'

#custom_signaturesObject

The custom signatures being suppressed.



44
45
46
47
48
49
# File 'lib/esp/resources/suppression.rb', line 44

def custom_signatures
  # When custom_signatures come back in an include, the method still gets called, to return the object from the attributes.
  return attributes['custom_signatures'] if attributes['custom_signatures'].present?
  return [] unless respond_to? :custom_signature_ids
  ESP::CustomSignature.where(id_in: custom_signature_ids)
end

#deactivateObject

Deactivate the current suppression instance. The current object will be updated with the new status if successful. If not successful, populates its errors object.

Once deactivated the suppression cannot be reactivated.



80
81
82
83
84
85
86
87
88
# File 'lib/esp/resources/suppression.rb', line 80

def deactivate
  patch(:deactivate).tap do |response|
    load_attributes_from_response(response)
  end
rescue ActiveResource::BadRequest, ActiveResource::ResourceInvalid, ActiveResource::UnauthorizedAccess => error
  load_remote_errors(error, true)
  self.code = error.response.code
  false
end

#deactivate!Object

Deactivate the current suppression instance. The current object will be updated with the new status if successful. Throws an error if not successful.

Once deactivated the suppression cannot be reactivated.



70
71
72
73
74
# File 'lib/esp/resources/suppression.rb', line 70

def deactivate!
  return self if deactivate
  self.message = errors.full_messages.join(' ')
  fail(ActiveResource::ResourceInvalid.new(self)) # rubocop:disable Style/RaiseArgs
end

#destroyObject

Not Implemented. You cannot destroy a Suppression.



62
63
64
# File 'lib/esp/resources/suppression.rb', line 62

def destroy
  fail ESP::NotImplementedError
end

#external_accountsObject

The external accounts affected by this suppression.



26
27
28
29
30
31
# File 'lib/esp/resources/suppression.rb', line 26

def external_accounts
  # When external_accounts come back in an include, the method still gets called, to return the object from the attributes.
  return attributes['external_accounts'] if attributes['external_accounts'].present?
  return [] unless respond_to? :external_account_ids
  ESP::ExternalAccount.where(id_in: )
end

#organizationObject

The organization this sub organization belongs to.



9
# File 'lib/esp/resources/suppression.rb', line 9

belongs_to :organization, class_name: 'ESP::Organization'

#regionsObject

The regions affected by this suppression.



17
18
19
20
21
22
# File 'lib/esp/resources/suppression.rb', line 17

def regions
  # When regions come back in an include, the method still gets called, to return the object from the attributes.
  return attributes['regions'] if attributes['regions'].present?
  return [] unless respond_to? :region_ids
  ESP::Region.where(id_in: region_ids)
end

#saveObject

Not Implemented. You cannot create or update a Suppression.



57
58
59
# File 'lib/esp/resources/suppression.rb', line 57

def save
  fail ESP::NotImplementedError
end

#signaturesObject

The signatures being suppressed.



35
36
37
38
39
40
# File 'lib/esp/resources/suppression.rb', line 35

def signatures
  # When signatures come back in an include, the method still gets called, to return the object from the attributes.
  return attributes['signatures'] if attributes['signatures'].present?
  return [] unless respond_to? :signature_ids
  ESP::Signature.where(id_in: signature_ids)
end