Class: Megam::Account
Instance Attribute Summary collapse
Attributes inherited from RestAdapter
#headers, #host, #master_key, #org_id, #password_hash
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from RestAdapter
#megam_rest
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
35
|
# File 'lib/megam/core/account.rb', line 19
def initialize(o={})
@id = nil
@email = nil
@user_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
|
#user_email ⇒ Object
Returns the value of attribute user_email.
15
16
17
|
# File 'lib/megam/core/account.rb', line 15
def user_email
@user_email
end
|
Class Method Details
.create(o) ⇒ Object
161
162
163
164
|
# File 'lib/megam/core/account.rb', line 161
def self.create(o)
acct = from_hash(o)
acct.create
end
|
.forgot(o) ⇒ Object
189
190
191
192
|
# File 'lib/megam/core/account.rb', line 189
def self.forgot(o)
acct = from_hash(o)
acct.forgot
end
|
.from_hash(o) ⇒ Object
107
108
109
110
111
|
# File 'lib/megam/core/account.rb', line 107
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/megam/core/account.rb', line 74
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
175
176
177
178
|
# File 'lib/megam/core/account.rb', line 175
def self.list(o)
acct = from_hash(o)
acct.list
end
|
.login(o) ⇒ Object
151
152
153
154
|
# File 'lib/megam/core/account.rb', line 151
def self.login(o)
acct = from_hash(o)
acct.login
end
|
.password_reset(o) ⇒ Object
203
204
205
206
|
# File 'lib/megam/core/account.rb', line 203
def self.password_reset(o)
acct = from_hash(o)
acct.password_reset
end
|
.remove(o) ⇒ Object
194
195
196
197
|
# File 'lib/megam/core/account.rb', line 194
def self.remove(o)
acct = from_hash(o)
acct.remove
end
|
.show(o) ⇒ Object
170
171
172
173
|
# File 'lib/megam/core/account.rb', line 170
def self.show(o)
acct = from_hash(o)
acct.megam_rest.get_accounts(o[:email])
end
|
.update(o) ⇒ Object
184
185
186
187
|
# File 'lib/megam/core/account.rb', line 184
def self.update(o)
acct = from_hash(o)
acct.update
end
|
Instance Method Details
#account ⇒ Object
37
38
39
|
# File 'lib/megam/core/account.rb', line 37
def account
self
end
|
#create ⇒ Object
166
167
168
|
# File 'lib/megam/core/account.rb', line 166
def create
megam_rest.post_accounts(to_hash)
end
|
#error? ⇒ Boolean
49
50
51
|
# File 'lib/megam/core/account.rb', line 49
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)
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/megam/core/account.rb', line 93
def expanded
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/megam/core/account.rb', line 57
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
212
213
214
|
# File 'lib/megam/core/account.rb', line 212
def forgot
megam_rest.forgot(to_hash)
end
|
#from_hash(o) ⇒ Object
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
148
149
|
# File 'lib/megam/core/account.rb', line 113
def from_hash(o)
@id = o[:id] if o.key?(:id)
@email = o[:email] if o.key?(:email)
@user_email = o[:user_email] if o.key?(:user_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
180
181
182
|
# File 'lib/megam/core/account.rb', line 180
def list
megam_rest.list_accounts
end
|
#login ⇒ Object
156
157
158
|
# File 'lib/megam/core/account.rb', line 156
def login
megam_rest.login(to_hash)
end
|
#password_reset ⇒ Object
216
217
218
|
# File 'lib/megam/core/account.rb', line 216
def password_reset
megam_rest.password_reset(to_hash)
end
|
#remove ⇒ Object
199
200
201
|
# File 'lib/megam/core/account.rb', line 199
def remove
megam_rest.delete_accounts(to_hash)
end
|
#to_json(*a) ⇒ Object
53
54
55
|
# File 'lib/megam/core/account.rb', line 53
def to_json(*a)
for_json.to_json(*a)
end
|
#update ⇒ Object
208
209
210
|
# File 'lib/megam/core/account.rb', line 208
def update
megam_rest.update_accounts(to_hash)
end
|