Class: Megam::Account
- Inherits:
-
RestAdapter
- Object
- RestAdapter
- Megam::Account
- Defined in:
- lib/megam/core/account.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#approval ⇒ Object
Returns the value of attribute approval.
-
#code ⇒ Object
Returns the value of attribute code.
-
#dates ⇒ Object
Returns the value of attribute dates.
-
#email ⇒ Object
Returns the value of attribute email.
-
#id ⇒ Object
Returns the value of attribute id.
-
#json_claz ⇒ Object
Returns the value of attribute json_claz.
-
#links ⇒ Object
Returns the value of attribute links.
-
#more ⇒ Object
Returns the value of attribute more.
-
#msg ⇒ Object
Returns the value of attribute msg.
-
#msg_type ⇒ Object
Returns the value of attribute msg_type.
-
#name ⇒ Object
Returns the value of attribute name.
-
#password ⇒ Object
Returns the value of attribute password.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#registration_ip_address ⇒ Object
Returns the value of attribute registration_ip_address.
-
#some_msg(arg = nil) ⇒ Object
Returns the value of attribute some_msg.
-
#states ⇒ Object
Returns the value of attribute states.
-
#suspend ⇒ Object
Returns the value of attribute suspend.
Attributes inherited from RestAdapter
#headers, #host, #master_key, #org_id, #password_hash
Class Method Summary collapse
- .create(o) ⇒ Object
- .forgot(o) ⇒ Object
- .from_hash(o) ⇒ Object
- .json_create(o) ⇒ Object
- .list(o) ⇒ Object
- .login(o) ⇒ Object
- .password_reset(o) ⇒ Object
- .show(o) ⇒ Object
- .update(o) ⇒ Object
Instance Method Summary collapse
- #account ⇒ Object
- #create ⇒ Object
- #error? ⇒ Boolean
-
#expanded ⇒ Object
Can be used by the calling classes to get the full hash (eg: Nilavu: User model).
- #for_json ⇒ Object
- #forgot ⇒ Object
- #from_hash(o) ⇒ Object
-
#initialize(o = {}) ⇒ Account
constructor
A new instance of Account.
- #list ⇒ Object
- #login ⇒ Object
- #password_reset ⇒ Object
- #to_json(*a) ⇒ Object
- #to_s ⇒ Object
- #update ⇒ Object
Methods inherited from RestAdapter
Constructor Details
#initialize(o = {}) ⇒ Account
Returns a new instance of Account.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/megam/core/account.rb', line 19 def initialize(o={}) @id = nil @email = nil @api_key = nil @name = {} @phone = {} @password = {} @states = {} @approval = {} @suspend = {} @dates = {} @some_msg = {} super({ email: o[:email], api_key: o[:api_key], host: o[:host], password_hash: o[:password_hash], org_id: o[:org_id] }) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/megam/core/account.rb', line 7 def api_key @api_key end |
#approval ⇒ Object
Returns the value of attribute approval.
11 12 13 |
# File 'lib/megam/core/account.rb', line 11 def approval @approval end |
#code ⇒ Object
Returns the value of attribute code.
15 16 17 |
# File 'lib/megam/core/account.rb', line 15 def code @code end |
#dates ⇒ Object
Returns the value of attribute dates.
14 15 16 |
# File 'lib/megam/core/account.rb', line 14 def dates @dates end |
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/megam/core/account.rb', line 5 def email @email end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/megam/core/account.rb', line 4 def id @id end |
#json_claz ⇒ Object
Returns the value of attribute json_claz.
15 16 17 |
# File 'lib/megam/core/account.rb', line 15 def json_claz @json_claz end |
#links ⇒ Object
Returns the value of attribute links.
15 16 17 |
# File 'lib/megam/core/account.rb', line 15 def links @links end |
#more ⇒ Object
Returns the value of attribute more.
15 16 17 |
# File 'lib/megam/core/account.rb', line 15 def more @more end |
#msg ⇒ Object
Returns the value of attribute msg.
15 16 17 |
# File 'lib/megam/core/account.rb', line 15 def msg @msg end |
#msg_type ⇒ Object
Returns the value of attribute msg_type.
15 16 17 |
# File 'lib/megam/core/account.rb', line 15 def msg_type @msg_type end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/megam/core/account.rb', line 8 def name @name end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/megam/core/account.rb', line 6 def password @password end |
#phone ⇒ Object
Returns the value of attribute phone.
9 10 11 |
# File 'lib/megam/core/account.rb', line 9 def phone @phone end |
#registration_ip_address ⇒ Object
Returns the value of attribute registration_ip_address.
13 14 15 |
# File 'lib/megam/core/account.rb', line 13 def registration_ip_address @registration_ip_address end |
#some_msg(arg = nil) ⇒ Object
Returns the value of attribute some_msg.
16 17 18 |
# File 'lib/megam/core/account.rb', line 16 def some_msg @some_msg end |
#states ⇒ Object
Returns the value of attribute states.
10 11 12 |
# File 'lib/megam/core/account.rb', line 10 def states @states end |
#suspend ⇒ Object
Returns the value of attribute suspend.
12 13 14 |
# File 'lib/megam/core/account.rb', line 12 def suspend @suspend end |
Class Method Details
.create(o) ⇒ Object
159 160 161 162 |
# File 'lib/megam/core/account.rb', line 159 def self.create(o) acct = from_hash(o) acct.create end |
.forgot(o) ⇒ Object
187 188 189 190 |
# File 'lib/megam/core/account.rb', line 187 def self.forgot(o) acct = from_hash(o) acct.forgot end |
.from_hash(o) ⇒ Object
106 107 108 109 110 |
# File 'lib/megam/core/account.rb', line 106 def self.from_hash(o) acct = new(email: o[:email], api_key: o[:api_key], host: o[:host], password_hash: o[:password_hash], org_id: o[:org_id]) acct.from_hash(o) acct end |
.json_create(o) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/megam/core/account.rb', line 73 def self.json_create(o) acct = new() o.symbolize_keys! o = o[:results] if o.has_key?(:results) o.each { |k, v| acct.send("#{k}=", v) } acct.some_msg[:code] = @code if @code acct.some_msg[:msg_type] = @msg_type if @msg_type acct.some_msg[:msg] = @msg if @msg acct.some_msg[:more] = @more if @more acct.some_msg[:links] = @links if @links acct end |
.list(o) ⇒ Object
173 174 175 176 |
# File 'lib/megam/core/account.rb', line 173 def self.list(o) acct = from_hash(o) acct.list end |
.login(o) ⇒ Object
149 150 151 152 |
# File 'lib/megam/core/account.rb', line 149 def self.login(o) acct = from_hash(o) acct.login end |
.password_reset(o) ⇒ Object
192 193 194 195 |
# File 'lib/megam/core/account.rb', line 192 def self.password_reset(o) acct = from_hash(o) acct.password_reset end |
.show(o) ⇒ Object
168 169 170 171 |
# File 'lib/megam/core/account.rb', line 168 def self.show(o) acct = from_hash(o) acct.megam_rest.get_accounts(o[:email]) end |
.update(o) ⇒ Object
182 183 184 185 |
# File 'lib/megam/core/account.rb', line 182 def self.update(o) acct = from_hash(o) acct.update end |
Instance Method Details
#account ⇒ Object
36 37 38 |
# File 'lib/megam/core/account.rb', line 36 def account self end |
#create ⇒ Object
164 165 166 |
# File 'lib/megam/core/account.rb', line 164 def create megam_rest.post_accounts(to_hash) end |
#error? ⇒ Boolean
48 49 50 |
# File 'lib/megam/core/account.rb', line 48 def error? crocked = true if some_msg.key?(:msg_type) && some_msg[:msg_type] == 'error' end |
#expanded ⇒ Object
Can be used by the calling classes to get the full hash (eg: Nilavu: User model)
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/megam/core/account.rb', line 92 def h = Hash.new [:id, :email, :api_key, :name, :phone, :password,:states, :approval, :suspend, :registration_ip_address, :dates, :some_msg].each do |setting| if grouped = self.send("#{setting}").is_a?(Hash) self.send("#{setting}").each {|k,v| h[k.to_sym] = v} else h[setting] = self.send("#{setting}") end end h end |
#for_json ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/megam/core/account.rb', line 56 def for_json result = { 'id' => @id, 'email' => @email, 'api_key' => @api_key, 'name' => @name, 'phone' => @phone, 'password' => @password, 'states' => @states, 'approval' => @approval, 'suspend' => @suspend, 'registration_ip_address' => @registration_ip_address, 'dates' => @dates } result end |
#forgot ⇒ Object
201 202 203 |
# File 'lib/megam/core/account.rb', line 201 def forgot megam_rest.forgot(to_hash) end |
#from_hash(o) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/megam/core/account.rb', line 112 def from_hash(o) @id = o[:id] if o.key?(:id) @email = o[:email] if o.key?(:email) @api_key = o[:api_key] if o.key?(:api_key) @name[:first_name] = o[:first_name] if o.key?(:first_name) @name[:last_name] = o[:last_name] if o.key?(:last_name) @phone[:phone] = o[:phone] if o.key?(:phone) @phone[:phone_verified] = o[:phone_verified] if o.key?(:phone_verified) @password[:password_hash] = o[:password_hash] if o.key?(:password_hash) @password[:password_reset_key] = o[:password_reset_key] if o.key?(:password_reset_key) @password[:password_reset_sent_at] = o[:password_reset_sent_at] if o.key?(:password_reset_sent_at) @states[:authority] = o[:authority] if o.key?(:authority) @states[:active] = o[:active] if o.key?(:active) @states[:blocked] = o[:blocked] if o.key?(:blocked) @states[:staged] = o[:staged] if o.key?(:staged) @approval[:approved] = o[:approved] if o.key?(:approved) @approval[:approved_by_id] = o[:approved_by_id] if o.key?(:approved_by_id) @approval[:approved_at] = o[:approved_at] if o.key?(:approved_at) @suspend[:suspended] = o[:suspended] if o.key?(:suspended) @suspend[:suspended_at] = o[:suspend] if o.key?(:suspended_at) @suspend[:suspended_till] = o[:suspended_till] if o.key?(:suspended_till) @registration_ip_address = o[:registration_ip_address] if o.key?(:registration_ip_address) @dates[:last_posted_at] = o[:last_posted_at] if o.key?(:last_posted_at) @dates[:last_emailed_at] = o[:last_emailed_at] if o.key?(:last_emailed_at) @dates[:previous_visit_at] = o[:previous_visit_at] if o.key?(:previous_visit_at) @dates[:first_seen_at] = o[:first_seen_at] if o.key?(:first_seen_at) @dates[:created_at] = o[:created_at] if o.key?(:created_at) self end |
#list ⇒ Object
178 179 180 |
# File 'lib/megam/core/account.rb', line 178 def list megam_rest.list_accounts end |
#login ⇒ Object
154 155 156 |
# File 'lib/megam/core/account.rb', line 154 def login megam_rest.login(to_hash) end |
#password_reset ⇒ Object
205 206 207 |
# File 'lib/megam/core/account.rb', line 205 def password_reset megam_rest.password_reset(to_hash) end |
#to_json(*a) ⇒ Object
52 53 54 |
# File 'lib/megam/core/account.rb', line 52 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
209 210 211 |
# File 'lib/megam/core/account.rb', line 209 def to_s Megam::Stuff.styled_hash(to_hash) end |
#update ⇒ Object
197 198 199 |
# File 'lib/megam/core/account.rb', line 197 def update megam_rest.update_accounts(to_hash) end |