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.
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
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
- #id(arg = nil) ⇒ Object
-
#initialize(email = nil, api_key = nil) ⇒ Account
constructor
A new instance of Account.
- #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
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 |
# File 'lib/megam/core/account.rb', line 18 def initialize(email=nil, api_key=nil) @id = nil @email = nil @api_key = nil @authority = nil @created_at = nil @some_msg = {} super(email, api_key) end |
Class Method Details
.create(o) ⇒ Object
145 146 147 148 |
# File 'lib/megam/core/account.rb', line 145 def self.create(o) acct = from_hash(o) acct.create end |
.from_hash(o) ⇒ Object
130 131 132 133 134 |
# File 'lib/megam/core/account.rb', line 130 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)
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/megam/core/account.rb', line 116 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.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
151 152 153 154 |
# File 'lib/megam/core/account.rb', line 151 def self.show(email,api_key=nil) acct = self.new(email, api_key) acct.megam_rest.get_accounts(email) end |
Instance Method Details
#account ⇒ Object
used by resque workers and any other background job
29 30 31 |
# File 'lib/megam/core/account.rb', line 29 def account self end |
#api_key(arg = nil) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/megam/core/account.rb', line 49 def api_key(arg=nil) if arg != nil @api_key = arg else @api_key end end |
#authority(arg = nil) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/megam/core/account.rb', line 57 def (arg=nil) if arg != nil @authority = arg else @authority end end |
#create ⇒ Object
Create the node via the REST API
157 158 159 |
# File 'lib/megam/core/account.rb', line 157 def create megam_rest.post_accounts(to_hash) end |
#created_at(arg = nil) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/megam/core/account.rb', line 65 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#email(arg = nil) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/megam/core/account.rb', line 41 def email(arg=nil) if arg != nil @email = arg else @email end end |
#error? ⇒ Boolean
81 82 83 |
# File 'lib/megam/core/account.rb', line 81 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/megam/core/account.rb', line 104 def for_json result = { "id" => id, "email" => email, "api_key" => api_key, "authority" => , "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/megam/core/account.rb', line 136 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) @created_at = o[:created_at] if o.has_key?(:created_at) self end |
#id(arg = nil) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/megam/core/account.rb', line 33 def id(arg=nil) if arg != nil @id = arg else @id end end |
#some_msg(arg = nil) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/megam/core/account.rb', line 73 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
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/megam/core/account.rb', line 86 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["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.
100 101 102 |
# File 'lib/megam/core/account.rb', line 100 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
161 162 163 |
# File 'lib/megam/core/account.rb', line 161 def to_s Megam::Stuff.styled_hash(to_hash) end |