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


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

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


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

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


98
99
100
101
102
103
104
105
106
107
# File 'app/models/padma_account.rb', line 98

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


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

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

#contactsObject


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

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

#enabled?Boolean


31
32
33
# File 'app/models/padma_account.rb', line 31

def enabled?
  self.enabled
end

#json_rootObject


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

def json_root
  :account
end

#migrated?Boolean

if true account is padma2 if false account is kshema


38
39
40
# File 'app/models/padma_account.rb', line 38

def migrated?
  !self.migrated_to_padma_on.nil?
end

#usersObject


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

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