Class: Megam::Account
Instance Attribute Summary
Attributes inherited from ServerAPI
Class Method Summary collapse
- .create(o) ⇒ Object
- .from_hash(o) ⇒ Object
-
.json_create(o) ⇒ Object
Create a Megam::Account from JSON (used by the backgroud job workers).
- .repassword(o) ⇒ Object
- .reset(o) ⇒ Object
-
.show(o) ⇒ Object
Load a account by email_p.
- .update(o) ⇒ Object
Instance Method Summary collapse
-
#account ⇒ Object
used by resque workers and any other background job.
- #api_key(arg = nil) ⇒ Object
- #authority(arg = nil) ⇒ Object
-
#create ⇒ Object
Create the node via the REST API.
- #created_at(arg = nil) ⇒ Object
- #email(arg = nil) ⇒ Object
- #error? ⇒ Boolean
- #first_name(arg = nil) ⇒ Object
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
- #id(arg = nil) ⇒ Object
-
#initialize(o) ⇒ Account
constructor
A new instance of Account.
- #last_name(arg = nil) ⇒ Object
- #password(arg = nil) ⇒ Object
- #password_reset_key(arg = nil) ⇒ Object
- #password_reset_sent_at(arg = nil) ⇒ Object
- #phone(arg = nil) ⇒ Object
- #repassword ⇒ Object
- #reset ⇒ Object
- #some_msg(arg = nil) ⇒ Object
-
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash.
-
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat.
- #to_s ⇒ Object
-
#update ⇒ Object
Create the node via the REST API.
Methods inherited from ServerAPI
Constructor Details
#initialize(o) ⇒ Account
Returns a new instance of Account.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/megam/core/account.rb', line 18 def initialize(o) @id = nil @email = nil @api_key = nil @first_name = nil @last_name = nil @phone = nil @password = nil @authority = nil @password_reset_key = nil @password_reset_sent_at = nil @created_at = nil @some_msg = {} super({:email => o[:email], :api_key => o[:api_key], :host => o[:host], :password => o[:password], :org_id => o[:org_id]}) end |
Class Method Details
.create(o) ⇒ Object
224 225 226 227 |
# File 'lib/megam/core/account.rb', line 224 def self.create(o) acct = from_hash(o) acct.create end |
.from_hash(o) ⇒ Object
203 204 205 206 207 |
# File 'lib/megam/core/account.rb', line 203 def self.from_hash(o) acct = self.new({:email => o[:email], :api_key => o[:api_key], :host => o[:host], :password => o[:password], :org_id => o[:org_id]}) acct.from_hash(o) acct end |
.json_create(o) ⇒ Object
Create a Megam::Account from JSON (used by the backgroud job workers)
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/megam/core/account.rb', line 183 def self.json_create(o) acct = new({}) acct.id(o["id"]) if o.has_key?("id") acct.email(o["email"]) if o.has_key?("email") acct.api_key(o["api_key"]) if o.has_key?("api_key") acct.(o["authority"]) if o.has_key?("authority") acct.first_name(o["first_name"]) if o.has_key?("first_name") acct.last_name(o["last_name"]) if o.has_key?("last_name") acct.phone(o["phone"]) if o.has_key?("phone") acct.password(o["password"]) if o.has_key?("password") acct.password_reset_key(o["password_reset_key"]) if o.has_key?("password_reset_key") acct.password_reset_key(o["password_reset_sent_at"]) if o.has_key?("password_reset_sent_at") acct.created_at(o["created_at"]) if o.has_key?("created_at") 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 |
.repassword(o) ⇒ Object
250 251 252 253 |
# File 'lib/megam/core/account.rb', line 250 def self.repassword(o) acct = from_hash(o) acct.repassword end |
.reset(o) ⇒ Object
245 246 247 248 |
# File 'lib/megam/core/account.rb', line 245 def self.reset(o) acct = from_hash(o) acct.reset end |
.show(o) ⇒ Object
Load a account by email_p
235 236 237 238 |
# File 'lib/megam/core/account.rb', line 235 def self.show(o) acct = self.new({:email => o[:email], :api_key => o[:api_key], :host => o[:host], :password => o[:password], :org_id => o[:org_id]}) acct.megam_rest.get_accounts(o[:email]) end |
.update(o) ⇒ Object
240 241 242 243 |
# File 'lib/megam/core/account.rb', line 240 def self.update(o) acct = from_hash(o) acct.update end |
Instance Method Details
#account ⇒ Object
used by resque workers and any other background job
35 36 37 |
# File 'lib/megam/core/account.rb', line 35 def account self end |
#api_key(arg = nil) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/megam/core/account.rb', line 55 def api_key(arg=nil) if arg != nil @api_key = arg else @api_key end end |
#authority(arg = nil) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/megam/core/account.rb', line 95 def (arg=nil) if arg != nil @authority = arg else @authority end end |
#create ⇒ Object
Create the node via the REST API
230 231 232 |
# File 'lib/megam/core/account.rb', line 230 def create megam_rest.post_accounts(to_hash) end |
#created_at(arg = nil) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/megam/core/account.rb', line 120 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#email(arg = nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/megam/core/account.rb', line 47 def email(arg=nil) if arg != nil @email = arg else @email end end |
#error? ⇒ Boolean
136 137 138 |
# File 'lib/megam/core/account.rb', line 136 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#first_name(arg = nil) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/megam/core/account.rb', line 63 def first_name(arg=nil) if arg != nil @first_name = arg else @first_name end end |
#for_json ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/megam/core/account.rb', line 165 def for_json result = { "id" => id, "email" => email, "api_key" => api_key, "first_name" => first_name, "last_name" => last_name, "phone" => phone, "password" => password, "password_reset_key" => password_reset_key, "password_reset_sent_at" => password_reset_sent_at, "authority" => , "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/megam/core/account.rb', line 209 def from_hash(o) @id = o[:id] if o.has_key?(:id) @email = o[:email] if o.has_key?(:email) @api_key = o[:api_key] if o.has_key?(:api_key) @authority = o[:authority] if o.has_key?(:authority) @first_name = o[:first_name] if o.has_key?(:first_name) @last_name = o[:last_name] if o.has_key?(:last_name) @phone = o[:phone] if o.has_key?(:phone) @password = o[:password] if o.has_key?(:password) @password_reset_key = o[:password_reset_key] if o.has_key?(:password_reset_key) @password_reset_sent_at = o[:password_reset_sent_at] if o.has_key?(:password_reset_sent_at) @created_at = o[:created_at] if o.has_key?(:created_at) self end |
#id(arg = nil) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/megam/core/account.rb', line 39 def id(arg=nil) if arg != nil @id = arg else @id end end |
#last_name(arg = nil) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/megam/core/account.rb', line 71 def last_name(arg=nil) if arg != nil @last_name = arg else @last_name end end |
#password(arg = nil) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/megam/core/account.rb', line 87 def password(arg=nil) if arg != nil @password = arg else @password end end |
#password_reset_key(arg = nil) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/megam/core/account.rb', line 103 def password_reset_key(arg=nil) if arg != nil @password_reset_key = arg else @password_reset_key end end |
#password_reset_sent_at(arg = nil) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/megam/core/account.rb', line 111 def password_reset_sent_at(arg=nil) if arg != nil @password_reset_sent_at = arg else @password_reset_sent_at end end |
#phone(arg = nil) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/megam/core/account.rb', line 79 def phone(arg=nil) if arg != nil @phone = arg else @phone end end |
#repassword ⇒ Object
264 265 266 |
# File 'lib/megam/core/account.rb', line 264 def repassword megam_rest.repassword_accounts(to_hash) end |
#reset ⇒ Object
260 261 262 |
# File 'lib/megam/core/account.rb', line 260 def reset megam_rest.reset_accounts(to_hash) end |
#some_msg(arg = nil) ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/megam/core/account.rb', line 128 def some_msg(arg=nil) if arg != nil @some_msg = arg else @some_msg end end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/megam/core/account.rb', line 141 def to_hash index_hash = Hash.new index_hash["json_claz"] = self.class.name index_hash["id"] = id index_hash["email"] = email index_hash["api_key"] = api_key index_hash["first_name"] = first_name index_hash["last_name"] = last_name index_hash["phone"] = phone index_hash["password"] = password index_hash["password_reset_key"] = password_reset_key index_hash["password_reset_sent_at"] = password_reset_sent_at index_hash["authority"] = index_hash["created_at"] = created_at 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.
161 162 163 |
# File 'lib/megam/core/account.rb', line 161 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
268 269 270 |
# File 'lib/megam/core/account.rb', line 268 def to_s Megam::Stuff.styled_hash(to_hash) end |
#update ⇒ Object
Create the node via the REST API
256 257 258 |
# File 'lib/megam/core/account.rb', line 256 def update megam_rest.update_accounts(to_hash) end |