Class: PadmaAccount

Inherits:
LogicalModel
  • Object
show all
Defined in:
app/models/padma_account.rb

Overview

wrapper for PADMA-Accounts Account API interaction Configuration for LogicalModel on /config/initializers/logical_model.rb

Constant Summary collapse

TIMEOUT =

milisecons

5500
PER_PAGE =
9999

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_nucleo_id(nucleo_id, params = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/padma_account.rb', line 61

def self.find_by_nucleo_id(nucleo_id, params={})
  res = nil
  params = self.merge_key(params)
  request = Typhoeus::Request.new("#{resource_uri}/by_nucleo_id/#{nucleo_id}", params: params )

  request.on_complete do |response|
    if response.code >= 200 && response.code < 400
      log_ok(response)
      res = self.new.from_json(response.body)
    else
      log_failed(response)
    end
  end

  self.hydra.queue(request)
  self.hydra.run

  res
end

.find_by_vanity_name(vanity_name, params = {}) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/models/padma_account.rb', line 81

def self.find_by_vanity_name(vanity_name, params={})
  res = nil
  params = self.merge_key(params)
  request = Typhoeus::Request.new("#{resource_uri}/by_vanity_name/#{vanity_name}", params: params )

  request.on_complete do |response|
    if response.code >= 200 && response.code < 400
      log_ok(response)
      res = self.new.from_json(response.body)
    else
      log_failed(response)
    end
  end

  self.hydra.queue(request)
  self.hydra.run

  res
end

.find_with_rails_cache(account_name, options = {}) ⇒ Object



101
102
103
104
105
106
107
108
109
110
# File 'app/models/padma_account.rb', line 101

def self.find_with_rails_cache(,options={})
  pa = Rails.cache.read([,"padma_account"])
  if pa.nil? || options[:refresh]
    pa = find()
    if pa
      Rails.cache.write([,"padma_account"], pa, :expires_in => (options[:expires_in] || 5.minutes))  
    end
  end
  pa
end

Instance Method Details

#adminObject



49
50
51
# File 'app/models/padma_account.rb', line 49

def admin
  self.users.select {|u| u.roles.select {|r| r["name"] == "admin"}.first}.first
end

#contactsObject



53
54
55
# File 'app/models/padma_account.rb', line 53

def contacts
  PadmaContact.paginate(:account_name => self.name)
end

#enabled?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/padma_account.rb', line 34

def enabled?
  self.enabled
end

#json_rootObject



57
58
59
# File 'app/models/padma_account.rb', line 57

def json_root
  :account
end

#migrated?Boolean

if true account is padma2 if false account is kshema

Returns:

  • (Boolean)


41
42
43
# File 'app/models/padma_account.rb', line 41

def migrated?
  !self.migrated_to_padma_on.nil?
end

#usersObject



45
46
47
# File 'app/models/padma_account.rb', line 45

def users
  PadmaUser.paginate(:account_name => self.name)
end