Class: Megam::Account
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).
-
.show(email, api_key = nil) ⇒ 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(email = nil, api_key = nil) ⇒ Account
constructor
A new instance of Account.
- #last_name(arg = nil) ⇒ Object
- #password(arg = nil) ⇒ Object
- #password_reset_key(arg = nil) ⇒ Object
- #phone(arg = nil) ⇒ 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(email = nil, api_key = nil) ⇒ Account
Returns a new instance of Account.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/megam/core/account.rb', line 18 def initialize(email=nil, api_key=nil) @id = nil @email = nil @api_key = nil @first_name = nil @last_name = nil @phone = nil @password = nil = nil @password_reset_key = nil @created_at = nil @some_msg = {} super(email, api_key) end |
Class Method Details
.create(o) ⇒ Object
210 211 212 213 |
# File 'lib/megam/core/account.rb', line 210 def self.create(o) acct = from_hash(o) acct.create end |
.from_hash(o) ⇒ Object
190 191 192 193 194 |
# File 'lib/megam/core/account.rb', line 190 def self.from_hash(o) acct = self.new(o[:email], o[:api_key]) acct.from_hash(o) acct end |
.json_create(o) ⇒ Object
Create a Megam::Account from JSON (used by the backgroud job workers)
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/megam/core/account.rb', line 171 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.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 |
.show(email, api_key = nil) ⇒ Object
Load a account by email_p
222 223 224 225 |
# File 'lib/megam/core/account.rb', line 222 def self.show(email,api_key=nil) acct = self.new(email, api_key) acct.megam_rest.get_accounts(email) end |
.update(o) ⇒ Object
228 229 230 231 232 |
# File 'lib/megam/core/account.rb', line 228 def self.update(o) puts "called uda" acct = from_hash(o) acct.update end |
Instance Method Details
#account ⇒ Object
used by resque workers and any other background job
34 35 36 |
# File 'lib/megam/core/account.rb', line 34 def account self end |
#api_key(arg = nil) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/megam/core/account.rb', line 54 def api_key(arg=nil) if arg != nil @api_key = arg else @api_key end end |
#authority(arg = nil) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/megam/core/account.rb', line 94 def (arg=nil) if arg != nil = arg else end end |
#create ⇒ Object
Create the node via the REST API
216 217 218 |
# File 'lib/megam/core/account.rb', line 216 def create megam_rest.post_accounts(to_hash) end |
#created_at(arg = nil) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/megam/core/account.rb', line 110 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#email(arg = nil) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/megam/core/account.rb', line 46 def email(arg=nil) if arg != nil @email = arg else @email end end |
#error? ⇒ Boolean
126 127 128 |
# File 'lib/megam/core/account.rb', line 126 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#first_name(arg = nil) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/megam/core/account.rb', line 62 def first_name(arg=nil) if arg != nil @first_name = arg else @first_name end end |
#for_json ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/megam/core/account.rb', line 154 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, "authority" => , "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/megam/core/account.rb', line 196 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) = 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) @created_at = o[:created_at] if o.has_key?(:created_at) self end |
#id(arg = nil) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/megam/core/account.rb', line 38 def id(arg=nil) if arg != nil @id = arg else @id end end |
#last_name(arg = nil) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/megam/core/account.rb', line 70 def last_name(arg=nil) if arg != nil @last_name = arg else @last_name end end |
#password(arg = nil) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/megam/core/account.rb', line 86 def password(arg=nil) if arg != nil @password = arg else @password end end |
#password_reset_key(arg = nil) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/megam/core/account.rb', line 102 def password_reset_key(arg=nil) if arg != nil @password_reset_key = arg else @password_reset_key end end |
#phone(arg = nil) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/megam/core/account.rb', line 78 def phone(arg=nil) if arg != nil @phone = arg else @phone end end |
#some_msg(arg = nil) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/megam/core/account.rb', line 118 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
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/megam/core/account.rb', line 131 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["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.
150 151 152 |
# File 'lib/megam/core/account.rb', line 150 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
239 240 241 |
# File 'lib/megam/core/account.rb', line 239 def to_s Megam::Stuff.styled_hash(to_hash) end |
#update ⇒ Object
Create the node via the REST API
235 236 237 |
# File 'lib/megam/core/account.rb', line 235 def update megam_rest.update_accounts(to_hash) end |