Class: BlackStack::Client
- Inherits:
-
Object
- Object
- BlackStack::Client
- Defined in:
- lib/client.rb
Instance Method Summary collapse
-
#checkDomainForSSMVerified ⇒ Object
llama a la api de postmark preguntando el reseller email configurado para este clietne fue ferificado.
-
#getTimezone ⇒ Object
si el cliente no tiene una zona horaria configurada, retorna la zona horaria por defecto excepciones: => “Default timezone not found.”.
-
#hasBillingAddress? ⇒ Boolean
retorna true si la 5 variables (billing_address, billing_city, billing_state, billing_zipcode, billing_id_lncountry) tienen un valor destinto a nil o a un string vacio.
-
#hosts ⇒ Object
returns the hosts where this client has not-deleted workers, even if the host is not belong this client.
-
#not_deleted_workers ⇒ Object
returns the workers belong this clients, that have not been deleted.
-
#own_hosts ⇒ Object
returns the hosts belong this client TODO: deprecated.
-
#resellerSignature? ⇒ Boolean
retorna true si el cliente esta configurado para usar su propia nombre/email en el envio de notificaciones.
-
#resellerSignatureEmail ⇒ Object
retorna el email configurado y confirmado en PostMark para cuenta reseller, o retorna el email por defecto.
-
#resellerSignatureEnabled? ⇒ Boolean
retorna true si el cliente esta configurado para usar su propia nombre/email en el envio de notificaciones, y si el email fue verificado en postmark.
-
#resellerSignatureName ⇒ Object
retorna el nombre configurado para cuenta reseller, solo si el email esta confirmado en PostMark; o retorna el email por defecto.
-
#user_roles ⇒ Object
retorna un array de objectos UserRole, asignados a todos los usuarios de este cliente.
Instance Method Details
#checkDomainForSSMVerified ⇒ Object
llama a la api de postmark preguntando el reseller email configurado para este clietne fue ferificado
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/client.rb', line 88 def checkDomainForSSMVerified() = {} domain = self.domain_for_ssm email = self.from_email_for_ssm id = '' client = '' if domain != nil && email != nil begin # create postmark client client_postmark = Postmark::AccountApiClient.new(POSTMARK_API_TOKEN, secure: true) # get signature # more info: https://github.com/wildbit/postmark-gem/wiki/Senders # # TODO: this first strategy is not scalable if we handle a large list of signatures. # sign = client_postmark.signatures.select { |sign| sign[:domain]==domain }.first # # this other approach is a bit more scalable, but anyway we need to call the API # with filering by the domain. # # # TODO: this code is a replication from the filter ?memeber/filter_update_reseller_signature # Refer this issue for more information: https://github.com/leandrosardi/blackstack/issues/95 # pagesize = 30 # TODO: increase this value to 300 for optimization i = 0 j = 1 sign = nil while j>0 && sign.nil? buff = client_postmark.get_signatures(offset: i, count: pagesize) j = buff.size i += pagesize sign = buff.select { |s| s[:domain]==domain }.first end # while # if signature has been found? if sign.nil? # sincronizo con la central [:status] = "Client Signature Not Found" [:value] = client[:id] return .to_json else id = sign[:id] client = client_postmark.get_sender(id) if !client[:confirmed] self.domain_for_ssm_verified = false self.save [:status] = "No Verified" [:value] = client[:id] return .to_json else self.domain_for_ssm_verified = true self.save [:status] = "success" [:value] = client[:id] return .to_json end end rescue Postmark::ApiInputError => e [:status] = e.to_s return .to_json #return e rescue => e [:status] = e.to_s return .to_json #return e end else [:status] = 'error' [:value] = '' return .to_json end # checkDomainForSSMVerified end |
#getTimezone ⇒ Object
si el cliente no tiene una zona horaria configurada, retorna la zona horaria por defecto excepciones:
> “Default timezone not found.”
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/client.rb', line 74 def getTimezone() ret = nil if (self.timezone != nil) ret = self.timezone else ret = BlackStack::Timezone.where(:id=>BlackStack::Pampa::id_timezone_default).first if (ret == nil) raise "Default timezone not found." end end return ret end |
#hasBillingAddress? ⇒ Boolean
retorna true si la 5 variables (billing_address, billing_city, billing_state, billing_zipcode, billing_id_lncountry) tienen un valor destinto a nil o a un string vacio.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/client.rb', line 45 def hasBillingAddress? if ( self.billing_address.to_s.size == 0 || self.billing_city.to_s.size == 0 || self.billing_state.to_s.size == 0 || self.billing_zipcode.to_s.size == 0 || self.billing_id_lncountry.to_s.size == 0 ) return false else return true end end |
#hosts ⇒ Object
returns the hosts where this client has not-deleted workers, even if the host is not belong this client
28 29 30 |
# File 'lib/client.rb', line 28 def hosts() BlackStack::LocalHost.where(id: self.not_deleted_workers.select(:id_host).all.map(&:id_host)) end |
#not_deleted_workers ⇒ Object
returns the workers belong this clients, that have not been deleted
23 24 25 |
# File 'lib/client.rb', line 23 def not_deleted_workers() BlackStack::Worker.where(:id_client=>self.id, :delete_time=>nil) end |
#own_hosts ⇒ Object
returns the hosts belong this client TODO: deprecated
34 35 36 |
# File 'lib/client.rb', line 34 def own_hosts() BlackStack::LocalHost.where(:id_client=>self.id, :delete_time=>nil) end |
#resellerSignature? ⇒ Boolean
retorna true si el cliente esta configurado para usar su propia nombre/email en el envio de notificaciones
163 164 165 |
# File 'lib/client.rb', line 163 def resellerSignature? self.from_name_for_ssm.to_s.size>0 && self.from_email_for_ssm.to_s.size>0 end |
#resellerSignatureEmail ⇒ Object
retorna el email configurado y confirmado en PostMark para cuenta reseller, o retorna el email por defecto
184 185 186 187 188 189 190 191 |
# File 'lib/client.rb', line 184 def resellerSignatureEmail # configuracion de cuenta reseller if self.resellerSignatureEnabled? return self.from_email_for_ssm.to_s else return NOTIFICATIONS[:from_email] end end |
#resellerSignatureEnabled? ⇒ Boolean
retorna true si el cliente esta configurado para usar su propia nombre/email en el envio de notificaciones, y si el email fue verificado en postmark
168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/client.rb', line 168 def resellerSignatureEnabled? =begin # TODO: Mover esto a un proceso asincronico # si el cliente esta configurado para usar su propia nombre/email if self.resellerSignature? # pero el email fue verificado en postmark if self.domain_for_ssm_verified==nil || self.domain_for_ssm_verified!=true # hago la verificacion contra postmark self.checkDomainForSSMVerified end end =end # return resellerSignature? == true && self.domain_for_ssm_verified==true end |
#resellerSignatureName ⇒ Object
retorna el nombre configurado para cuenta reseller, solo si el email esta confirmado en PostMark; o retorna el email por defecto
194 195 196 197 198 199 200 201 |
# File 'lib/client.rb', line 194 def resellerSignatureName # configuracion de cuenta reseller if self.resellerSignatureEnabled? return self.from_name_for_ssm.to_s else return NOTIFICATIONS[:from_name] end end |
#user_roles ⇒ Object
retorna un array de objectos UserRole, asignados a todos los usuarios de este cliente
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/client.rb', line 60 def user_roles a = [] self.users.each { |o| a.concat o.user_roles # libero recursos GC.start DB.disconnect } a end |