Module: GitContacts
- Defined in:
- lib/gitcontacts.rb,
lib/gitcontacts/User.rb,
lib/gitcontacts/util.rb,
lib/gitcontacts/Request.rb,
lib/gitcontacts/version.rb,
lib/gitcontacts/Contacts.rb,
lib/gitcontacts/Invitation.rb
Defined Under Namespace
Classes: Contacts, ContactsObject, Invitation, InvitationObject, Request, RequestObject, User, UserObject
Constant Summary
collapse
- VERSION =
"0.0.2"
Class Method Summary
collapse
-
.add_contacts(operator, name) ⇒ Object
-
.add_contacts_card(operator, gid, payload) ⇒ Object
-
.add_contacts_user(operator, gid, uid) ⇒ Object
-
.contacts_keys ⇒ Object
-
.create_user(hash) ⇒ Object
-
.delete_contacts_card(operator, gid, card_id) ⇒ Object
-
.edit_contacts_card(operator, gid, card_id, payload) ⇒ Object
-
.edit_contacts_meta(operator, gid, new_meta) ⇒ Object
-
.edit_contacts_user_privileges(operator, gid, uid, payload) ⇒ Object
-
.edit_invitation_status(operator, payload) ⇒ Object
-
.edit_request_status(operator) ⇒ Object
-
.generate_code(n) ⇒ Object
-
.get_all_contacts(operator) ⇒ Object
meta => :owner, :gid, :count, :name.
-
.get_all_requests(operator) ⇒ Object
-
.get_contacts_card(operator, gid, card_id) ⇒ Object
-
.get_contacts_cards_by_related(operator, gid, keyword) ⇒ Object
def get_contacts_cards_by_owner operator, owner return unless GitContacts::relation_valid? operator gid contacts = Gitdb::Contacts.new operator contacts.access gid contacts.get_cards do |card| card.getdata if card.getmeta.include? owner end end.
-
.get_contacts_history(operator, gid) ⇒ Object
-
.get_contacts_if(&condition) ⇒ Object
e.g.: 获取联系人数量大于200的uid群组 get_contacts_if { |contacts| contacts.count > 200 }.
-
.get_contacts_users(operator, gid) ⇒ Object
-
.invitation_keys ⇒ Object
-
.invite_contacts_user(operator, gid, payload) ⇒ Object
-
.password_valid?(email, password) ⇒ Boolean
-
.relation_valid?(operator, gid) ⇒ Boolean
-
.request_keys ⇒ Object
-
.revert_to(operator, gid) ⇒ Object
-
.user_exist?(uid) ⇒ Boolean
-
.user_keys ⇒ Object
Class Method Details
57
58
59
60
61
62
|
# File 'lib/gitcontacts.rb', line 57
def add_contacts operator, name
contacts = Gitdb::Contacts.new operator
contacts.create name
contacts.getmeta[:gid]
end
|
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/gitcontacts.rb', line 166
def add_contacts_card operator, gid, payload
return unless GitContacts::relation_valid? operator gid
qid = Request::create :uid => operator, :gid => gid, :action => "create", :time => Time.now, :content => payload
req = Request.new qid
if req.auto_merge? operator
Request::delete qid
return req.allow operator
end
true
end
|
208
209
210
211
212
213
214
215
216
|
# File 'lib/gitcontacts.rb', line 208
def add_contacts_user operator, gid, uid
return unless result = GitContacts::relation_valid?(operator, gid)
user = result.first
contacts = result.last
if contacts.getadmins.include?(user.getuid)
contacts.add_user uid
true
end
end
|
13
14
15
|
# File 'lib/gitcontacts/util.rb', line 13
def contacts_keys
[:name, :note, :users, :admins]
end
|
.create_user(hash) ⇒ Object
20
21
22
|
# File 'lib/gitcontacts.rb', line 20
def create_user hash
User::create hash
end
|
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/gitcontacts.rb', line 191
def delete_contacts_card operator, gid, card_id
return unless GitContacts::relation_valid? operator gid
qid = GCRequest::create :uid => operator, :gid => gid, :action => "delete", :time => Time.now, :card_id => card_id
req = GCRequest.new qid
if req.auto_merge? operator
req.allow operator
Request::delete qid
end
true
end
|
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/gitcontacts.rb', line 180
def edit_contacts_card operator, gid, card_id, payload
return unless GitContacts::relation_valid? operator gid
qid = GCRequest::create :uid => operator, :gid => gid, :action => "setdata", :time => Time.now, :card_id => card_id, :content => payload
req = GCRequest.new qid
if req.auto_merge? operator
req.allow operator
Request::delete qid
end
true
end
|
64
65
66
67
68
69
|
# File 'lib/gitcontacts.rb', line 64
def edit_contacts_meta operator, gid, new_meta
return unless GitContacts::relation_valid? operator gid
contacts = Gitdb::Contacts.new operator
contacts.access gid
contacts.setmeta new_meta
end
|
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/gitcontacts.rb', line 218
def edit_contacts_user_privileges operator, gid, uid, payload
return unless result = GitContacts::relation_valid?(operator, gid)
user = result.first
contacts = result.last
if contacts.getadmins.include?(user.getuid)
case payload[:role]
when "admin"
contacts.add_admin uid
true
when "users"
contacts.remove_admin uid
true
end
end
end
|
.edit_invitation_status(operator, payload) ⇒ Object
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/gitcontacts.rb', line 243
def edit_invitation_status operator, payload
invitation = Inviation.new payload[:invite_id]
if invitation.accept? operator
user = User.new operator
gid = invitation.getcontacts
user.add_contacts gid
contacts = GCContacts.new gid
contacts.adduser user.getuid
Inviation::delete payload[:invite_id]
true
end
end
|
.edit_request_status(operator) ⇒ Object
259
260
|
# File 'lib/gitcontacts.rb', line 259
def edit_request_status operator
end
|
.generate_code(n) ⇒ Object
4
5
6
|
# File 'lib/gitcontacts/util.rb', line 4
def generate_code n
[*'a'..'z', *0..9, *'A'..'Z'].sample(n).join
end
|
meta => :owner, :gid, :count, :name
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/gitcontacts.rb', line 39
def get_all_contacts operator
contacts_arr = []
user = User.new operator
contacts = Gitdb::Contacts.new uid
user.getcontacts.each do |gid|
return unless GitContacts::relation_valid? operator gid
contacts.access gid
contacts_arr << contacts.getmeta
end
contacts_arr
end
|
.get_all_requests(operator) ⇒ Object
256
257
|
# File 'lib/gitcontacts.rb', line 256
def get_all_requests operator
end
|
71
72
73
74
75
76
|
# File 'lib/gitcontacts.rb', line 71
def get_contacts_card operator, gid, card_id
return unless GitContacts::relation_valid? operator gid
contacts = Gitdb::Contacts.new operator
contacts.access gid
contacts.get_card_by_id card_id
end
|
def get_contacts_cards_by_owner operator, owner
return unless GitContacts::relation_valid? operator gid
contacts = Gitdb::Contacts.new operator
contacts.access gid
contacts.get_cards do |card|
card.getdata if card.getmeta[:owner].include? owner
end
end
def get_contacts_cards_by_name operator, name
return unless GitContacts::relation_valid? operator gid
contacts = Gitdb::Contacts.new operator
contacts.access gid
contacts.get_cards do |card|
card.getdata if card.getdata[:firstname].include? name || card.getdata[:firstname].include? name
end
end
def get_contacts_cards_by_number operator, number
return unless GitContacts::relation_valid? operator gid
contacts = Gitdb::Contacts.new operator
contacts.access gid
contacts.get_cards do |card|
info = card.getdata
cond = info[:mobile].include? number || info[:phone].include? number || info[:im].include? number
info if cond
end
end
def get_contacts_cards_by_birthday date
contacts = Gitdb::Contacts.new uid
contacts.access gid
contacts.get_cards do |card|
card.getdata if card.getdata[:birthday].include? date
end
end
def get_contacts_cards_by_email email
contacts = Gitdb::Contacts.new uid
contacts.access gid
contacts.get_cards do |card|
card.getdata if card.getdata[:email].include? email
end
end
def get_contacts_cards_by_etc info
contacts = Gitdb::Contacts.new uid
contacts.access gid
contacts.get_cards do |card|
card.getdata if card.getdata[:address].include? info || card.getdata[:note].include? info
end
end
131
132
133
134
135
136
137
138
139
|
# File 'lib/gitcontacts.rb', line 131
def get_contacts_cards_by_related operator, gid, keyword
return unless GitContacts::relation_valid? operator gid
contacts = Gitdb::Contacts.new operator
contacts.access gid
contacts.get_cards do |card|
info = card.getdata
info if card.getmeta[:owner].include? keyword || info.find { |k| true if info[k].include? keyword }
end
end
|
.get_contacts_history(operator, gid) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/gitcontacts.rb', line 141
def get_contacts_history operator, gid
contacts = Gitdb::Contacts.new operator
contacts.access gid
contacts.read_change_history do |commit|
commit_obj = {}
commit_obj[:author] = commit.author
commit_obj[:operator] = commit.committer
commit_obj[:modified_time] = commit.time
commit_obj[:oid] = commit.oid
commit_obj[:message] = commit.message
commit_obj
end
end
|
e.g.: 获取联系人数量大于200的uid群组get_contacts_if { |contacts| contacts.count > 200 }
202
203
204
205
206
|
# File 'lib/gitcontacts.rb', line 202
def get_contacts_users operator, gid
return unless result = GitContacts::relation_valid?(operator, gid)
contacts = result.last
contacts.getusers
end
|
.invitation_keys ⇒ Object
17
18
19
|
# File 'lib/gitcontacts/util.rb', line 17
def invitation_keys
[:uid, :gid, :inviter_id]
end
|
234
235
236
237
238
239
240
241
|
# File 'lib/gitcontacts.rb', line 234
def invite_contacts_user operator, gid, payload
return unless result = GitContacts::relation_valid?(operator, gid)
user = result.first
contacts = result.last
if contacts.getadmins.include?(user.getuid)
Inviation::create :uid => User::email_to_uid(payload[:email]), :contacts => gid
end
end
|
.password_valid?(email, password) ⇒ Boolean
24
25
26
27
28
|
# File 'lib/gitcontacts.rb', line 24
def password_valid? email, password
if user = User.new(email)
user if user.password_correct? Digest::SHA1.hexdigest password
end
end
|
.relation_valid?(operator, gid) ⇒ Boolean
30
31
32
33
34
35
36
|
# File 'lib/gitcontacts.rb', line 30
def relation_valid? operator, gid
user = User.new operator
contacts = GitContacts.new gid
[user, contacts] end
|
.request_keys ⇒ Object
21
22
23
|
# File 'lib/gitcontacts/util.rb', line 21
def request_keys
[:uid, :gid, :card_id, :action, :content]
end
|
.revert_to(operator, gid) ⇒ Object
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/gitcontacts.rb', line 155
def revert_to operator, gid
contacts = Gitdb::Contacts.new operator
contacts.access gid
operator = {
:name => operator,
:email => User.new(operator).getemail,
:time => Time.now
}
contacts.revert_to oid, { :author => operator, :committer => operator, :message => "revert to revision #{oid}" }
end
|
.user_exist?(uid) ⇒ Boolean
16
17
18
|
# File 'lib/gitcontacts.rb', line 16
def user_exist? uid
User::exist? uid
end
|
.user_keys ⇒ Object
9
10
11
|
# File 'lib/gitcontacts/util.rb', line 9
def user_keys
[:email, :password, :contacts, :requests]
end
|