Class: Megam::Account
- Inherits:
-
Object
- Object
- Megam::Account
- Defined in:
- lib/megam/core/account.rb
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) ⇒ 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 ⇒ Account
constructor
A new instance of Account.
- #megam_rest ⇒ 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
Constructor Details
#initialize ⇒ Account
Returns a new instance of Account.
18 19 20 21 22 23 24 25 |
# File 'lib/megam/core/account.rb', line 18 def initialize @id = nil @email = nil @api_key = nil @authority = nil @created_at = nil @some_msg = {} end |
Class Method Details
.create(o) ⇒ Object
149 150 151 152 |
# File 'lib/megam/core/account.rb', line 149 def self.create(o) acct = from_hash(o) acct.create end |
.from_hash(o) ⇒ Object
134 135 136 137 138 |
# File 'lib/megam/core/account.rb', line 134 def self.from_hash(o) acct = self.new() acct.from_hash(o) acct end |
.json_create(o) ⇒ Object
Create a Megam::Account from JSON (used by the backgroud job workers)
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/megam/core/account.rb', line 120 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) ⇒ Object
Load a account by email_p
155 156 157 158 |
# File 'lib/megam/core/account.rb', line 155 def self.show(email) acct = self.new() acct.megam_rest.get_accounts(email) end |
Instance Method Details
#account ⇒ Object
used by resque workers and any other background job
28 29 30 |
# File 'lib/megam/core/account.rb', line 28 def account self end |
#api_key(arg = nil) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/megam/core/account.rb', line 53 def api_key(arg=nil) if arg != nil @api_key = arg else @api_key end end |
#authority(arg = nil) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/megam/core/account.rb', line 61 def (arg=nil) if arg != nil @authority = arg else @authority end end |
#create ⇒ Object
Create the node via the REST API
161 162 163 |
# File 'lib/megam/core/account.rb', line 161 def create megam_rest.post_accounts(to_hash) end |
#created_at(arg = nil) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/megam/core/account.rb', line 69 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#email(arg = nil) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/megam/core/account.rb', line 45 def email(arg=nil) if arg != nil @email = arg else @email end end |
#error? ⇒ Boolean
85 86 87 |
# File 'lib/megam/core/account.rb', line 85 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/megam/core/account.rb', line 108 def for_json result = { "id" => id, "email" => email, "api_key" => api_key, "authority" => , "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/megam/core/account.rb', line 140 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
37 38 39 40 41 42 43 |
# File 'lib/megam/core/account.rb', line 37 def id(arg=nil) if arg != nil @id = arg else @id end end |
#megam_rest ⇒ Object
32 33 34 35 |
# File 'lib/megam/core/account.rb', line 32 def megam_rest = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]} Megam::API.new() end |
#some_msg(arg = nil) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/megam/core/account.rb', line 77 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
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/megam/core/account.rb', line 90 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.
104 105 106 |
# File 'lib/megam/core/account.rb', line 104 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
165 166 167 168 |
# File 'lib/megam/core/account.rb', line 165 def to_s Megam::Stuff.styled_hash(to_hash) #"---> Megam::Account:[error=#{error?}]\n"+ end |