Class: Megam::ScmmAccount

Inherits:
Object
  • Object
show all
Defined in:
lib/megam/core/scmm/scmmaccount.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, displayName = nil, mail = nil, password = nil) ⇒ ScmmAccount



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/megam/core/scmm/scmmaccount.rb', line 19

def initialize(name=nil, displayName=nil, mail=nil, password=nil)
  @creationDate = nil
  @admin = nil
  @type = nil
  @password = nil
  @name = nil
  @mail = nil
  @displayName = nil
  @lastModified = nil
  @active = nil     
  @some_msg = {}
  super(name, displayName, mail, password)
end

Class Method Details

.create(o) ⇒ Object



198
199
200
201
# File 'lib/megam/core/scmm/scmmaccount.rb', line 198

def self.create(o)
  acct = from_hash(o)
  acct.create
end

.from_hash(o) ⇒ Object



179
180
181
182
183
# File 'lib/megam/core/scmm/scmmaccount.rb', line 179

def self.from_hash(o)
  acct = self.new(o[:name], o[:displayName], o[:mail], o[:password])
  acct.from_hash(o)
  acct
end

.json_create(o) ⇒ Object

Create a Megam::Account from JSON (used by the backgroud job workers)



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/megam/core/scmm/scmmaccount.rb', line 161

def self.json_create(o)
  acct = new
  acct.creationDate(o["creationDate"]) if o.has_key?("creationDate")
  acct.admin(o["admin"]) if o.has_key?("admin")
  acct.type(o["type"]) if o.has_key?("type")
  acct.password(o["password"]) if o.has_key?("password")
  acct.name(o["name"]) if o.has_key?("name")
  acct.mail(o["mail"]) if o.has_key?("mail")
  acct.displayName(o["displayName"]) if o.has_key?("displayName]")
  acct.lastModified(o["lastModifiec"]) if o.has_key?("lastModified")
  acct.active(o["active"]) if o.has_key?("active")
  acct.some_msg[:code] = o["code"] if o.has_key?("code")
  acct.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
  acct.some_msg[:msg]= o["msg"] if o.has_key?("msg")
  acct.some_msg[:links] = o["links"] if o.has_key?("links")
  acct
end

.show(name, displayName, mail, password) ⇒ Object

Load a account by email_p



204
205
206
207
# File 'lib/megam/core/scmm/scmmaccount.rb', line 204

def self.show(name, displayName, mail, password)
  acct = self.new(name, displayName, mail, password)
  acct.megam_rest.get_accounts(mail)
end

Instance Method Details

#accountObject

used by resque workers and any other background job



34
35
36
# File 'lib/megam/core/scmm/scmmaccount.rb', line 34

def 
  self
end

#active(arg = nil) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/megam/core/scmm/scmmaccount.rb', line 102

def active(arg=nil)
  if arg != nil
    @active = arg
  else
  @active
  end
end

#admin(arg = nil) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/megam/core/scmm/scmmaccount.rb', line 46

def admin(arg=nil)
  if arg != nil
    @admin = arg
  else
  @admin
  end
end

#createObject

Create the node via the REST API



210
211
212
# File 'lib/megam/core/scmm/scmmaccount.rb', line 210

def create
  megam_rest.post_accounts(to_hash)
end

#creationDate(arg = nil) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/megam/core/scmm/scmmaccount.rb', line 38

def creationDate(arg=nil)
  if arg != nil
    @creationDate = arg
  else
  @creationDate
  end
end

#displayName(arg = nil) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/megam/core/scmm/scmmaccount.rb', line 86

def displayName(arg=nil)
  if arg != nil
    @displayName = arg
  else
  @displayName
  end
end

#error?Boolean



118
119
120
# File 'lib/megam/core/scmm/scmmaccount.rb', line 118

def error?
  crocked  = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end

#for_jsonObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/megam/core/scmm/scmmaccount.rb', line 145

def for_json
  result = {
    "creationDate" => creationDate,
    "admin" => admin,
    "type" => type,
    "password" => password,
    "name" => name,
    "mail" => mail,
    "displayName" => displayName,
    "lastModified" => lastModified,
    "active" => active        
  }
  result
end

#from_hash(o) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/megam/core/scmm/scmmaccount.rb', line 185

def from_hash(o)
  @creationDate        = o[:creationDate] if o.has_key?(:creationDate)
  @admin     = o[:admin] if o.has_key?(:admin)
  @type   = o[:type] if o.has_key?(:type)
  @password = o[:password] if o.has_key?(:password)
  @name = o[:name] if o.has_key?(:name)
  @mail = o[:mail] if o.has_key?(:mail)
  @displayName = o[:displayName] if o.has_key?(:displayName)
  @lastModified = o[:lastModified] if o.has_key?(:lastModified)
  @active = o[:active] if o.has_key?(:active)
  self
end

#lastModified(arg = nil) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/megam/core/scmm/scmmaccount.rb', line 94

def lastModified(arg=nil)
  if arg != nil
    @lastModified = arg
  else
  @lastModified
  end
end

#mail(arg = nil) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/megam/core/scmm/scmmaccount.rb', line 78

def mail(arg=nil)
  if arg != nil
    @mail = arg
  else
  @mail
  end
end

#name(arg = nil) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/megam/core/scmm/scmmaccount.rb', line 70

def name(arg=nil)
  if arg != nil
    @name = arg
  else
  @name
  end
end

#password(arg = nil) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/megam/core/scmm/scmmaccount.rb', line 62

def password(arg=nil)
  if arg != nil
    @password = arg
  else
  @password
  end
end

#some_msg(arg = nil) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/megam/core/scmm/scmmaccount.rb', line 110

def some_msg(arg=nil)
  if arg != nil
    @some_msg = arg
  else
  @some_msg
  end
end

#to_hashObject

Transform the ruby obj -> to a Hash



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/megam/core/scmm/scmmaccount.rb', line 123

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["creationDate"] = creationDate
  index_hash["admin"] = admin
  index_hash["type"] = type
  index_hash["password"] = password
  index_hash["name"] = name
  index_hahs["mail"] = mail
  index_hash["displayName"] = displayName
  index_hash["lastModified"] = lastModified
  index_hash["active"] = active
  index_hash["some_msg"] = some_msg
  index_hash
end

#to_json(*a) ⇒ Object

Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.



141
142
143
# File 'lib/megam/core/scmm/scmmaccount.rb', line 141

def to_json(*a)
  for_json.to_json(*a)
end

#to_sObject



214
215
216
# File 'lib/megam/core/scmm/scmmaccount.rb', line 214

def to_s
  Megam::Stuff.styled_hash(to_hash)
end

#type(arg = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/megam/core/scmm/scmmaccount.rb', line 54

def type(arg=nil)
  if arg != nil
    @type = arg
  else
  @type
  end
end