Class: SlingContacts::ContactManager

Inherits:
Object
  • Object
show all
Defined in:
lib/nakamura/contacts.rb

Instance Method Summary collapse

Constructor Details

#initialize(sling) ⇒ ContactManager

Returns a new instance of ContactManager.



7
8
9
# File 'lib/nakamura/contacts.rb', line 7

def initialize(sling)
  @sling = sling
end

Instance Method Details

#accept_contact(name) ⇒ Object



21
22
23
24
# File 'lib/nakamura/contacts.rb', line 21

def accept_contact(name)
  home = @sling.get_user().home_path_for(@sling)
  return @sling.execute_post(@sling.url_for("#{home}/contacts.accept.html"), {"targetUserId" => name})
end

#block_contact(name) ⇒ Object



36
37
38
39
# File 'lib/nakamura/contacts.rb', line 36

def block_contact(name)
  home = @sling.get_user().home_path_for(@sling)
  return @sling.execute_post(@sling.url_for("#{home}/contacts.block.html"), {"targetUserId" => name})
end

#cancel_invitation(name) ⇒ Object



46
47
48
49
# File 'lib/nakamura/contacts.rb', line 46

def cancel_invitation(name)
  home = @sling.get_user().home_path_for(@sling)
  return @sling.execute_post(@sling.url_for("#{home}/contacts.cancel.html"), {"targetUserId" => name})
end

#find_contacts(state) ⇒ Object



76
77
78
79
# File 'lib/nakamura/contacts.rb', line 76

def find_contacts(state)
	result = @sling.execute_get(@sling.url_for("var/contacts/findstate.json?state=#{state}"))
  	return JSON.parse(result.body)
end

#get_acceptedObject



52
53
54
# File 'lib/nakamura/contacts.rb', line 52

def get_accepted()
			return find_contacts("ACCEPTED")
end

#get_allObject



72
73
74
# File 'lib/nakamura/contacts.rb', line 72

def get_all()
return find_contacts("*%3A*")
end

#get_blockedObject



64
65
66
# File 'lib/nakamura/contacts.rb', line 64

def get_blocked()
			return find_contacts("BLOCKED")
end

#get_ignoredObject



68
69
70
# File 'lib/nakamura/contacts.rb', line 68

def get_ignored()
			return find_contacts("IGNORED")
end

#get_invitedObject



60
61
62
# File 'lib/nakamura/contacts.rb', line 60

def get_invited()
			return find_contacts("INVITED")
end

#get_pendingObject



56
57
58
# File 'lib/nakamura/contacts.rb', line 56

def get_pending()
	return find_contacts("PENDING")
end

#ignore_contact(name) ⇒ Object



31
32
33
34
# File 'lib/nakamura/contacts.rb', line 31

def ignore_contact(name)
  home = @sling.get_user().home_path_for(@sling)
  return @sling.execute_post(@sling.url_for("#{home}/contacts.ignore.html"), {"targetUserId" => name})
end

#invite_contact(name, sharedRelationships, fromRelationships = [], toRelationships = []) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/nakamura/contacts.rb', line 11

def invite_contact(name, sharedRelationships, fromRelationships=[], toRelationships=[])
  case sharedRelationships
    when String
    sharedRelationships = [sharedRelationships]
  end
  home = @sling.get_user().home_path_for(@sling)
  return @sling.execute_post(@sling.url_for("#{home}/contacts.invite.html"), "sakai:types" => sharedRelationships,
    "fromRelationships" => fromRelationships, "toRelationships" => toRelationships, "targetUserId" => name)
end

#reject_contact(name) ⇒ Object



26
27
28
29
# File 'lib/nakamura/contacts.rb', line 26

def reject_contact(name)
  home = @sling.get_user().home_path_for(@sling)
  return @sling.execute_post(@sling.url_for("#{home}/contacts.reject.html"), {"targetUserId" => name})
end

#remove_contact(name) ⇒ Object



41
42
43
44
# File 'lib/nakamura/contacts.rb', line 41

def remove_contact(name)
  home = @sling.get_user().home_path_for(@sling)
  return @sling.execute_post(@sling.url_for("#{home}/contacts.remove.html"), {"targetUserId" => name})
end