Class: RubySwift

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-swift.rb

Instance Method Summary collapse

Constructor Details

#initialize(password, namespace = "ns1", http_adapter = :net_http) ⇒ RubySwift

Returns a new instance of RubySwift.



5
6
7
8
9
10
11
12
# File 'lib/ruby-swift.rb', line 5

def initialize(password, namespace="ns1", http_adapter=:net_http)
  HTTPI.adapter = http_adapter 

  @password = password
  @client   = Savon.client(endpoint: "http://suite.peoplelogic.com.au/server/includes/apis/soap.php",
                           namespace: namespace,
                           convert_request_keys_to: :none)
end

Instance Method Details

#add_group_member(email, group_name) ⇒ Object



44
45
46
# File 'lib/ruby-swift.rb', line 44

def add_group_member(email, group_name)
  return_response(soap_request("add_group_member", {email: email, group_name: group_name}))
end

#person_exists?(email) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ruby-swift.rb', line 14

def person_exists?(email)
  read_person(email)[:status] == 0
end

#read_groupsObject



36
37
38
39
40
41
42
# File 'lib/ruby-swift.rb', line 36

def read_groups
  return_response(soap_request("read_groups")) do |sr|
    sr[:item].map do |group|
      group[:item][:value]
    end
  end
end

#read_person(email) ⇒ Object



26
27
28
29
30
# File 'lib/ruby-swift.rb', line 26

def read_person(email)
  return_response(soap_request("read_person", {email: email})) do |sr|
    convert_to_person(sr)
  end
end

#read_persons(group_name) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/ruby-swift.rb', line 52

def read_persons(group_name)
  return_response(soap_request("read_persons", {group_name: group_name})) do |sr|
    sr[:item].map do |person|
      convert_to_person(person)
    end
  end
end

#remove_group(group_name) ⇒ Object



60
61
62
# File 'lib/ruby-swift.rb', line 60

def remove_group(group_name)
  return_response(soap_request("remove_group", {group_name: group_name}))
end

#remove_group_member(email, group_name) ⇒ Object



48
49
50
# File 'lib/ruby-swift.rb', line 48

def remove_group_member(email, group_name)
  return_response(soap_request("remove_group_member", {email: email, group_name: group_name}))
end

#remove_person(email) ⇒ Object



64
65
66
# File 'lib/ruby-swift.rb', line 64

def remove_person(email)
  return_response(soap_request("remove_person", {email: email}))
end

#update_person(old_email, fields) ⇒ Object



68
69
70
# File 'lib/ruby-swift.rb', line 68

def update_person(old_email, fields)
  return_response(soap_request("update_person", {email_old: old_email}.merge(fields)))
end

#write_group(group_name) ⇒ Object



72
73
74
# File 'lib/ruby-swift.rb', line 72

def write_group(group_name)
  return_response(soap_request("write_group", {group_name: group_name}))
end

#write_or_update_person(fields) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/ruby-swift.rb', line 18

def write_or_update_person(fields)
  if person_exists?(fields[:email])
    update_person(fields[:email], fields.reject { |k,v| k == :email})     
  else
    write_person(fields)
  end
end

#write_person(fields) ⇒ Object



32
33
34
# File 'lib/ruby-swift.rb', line 32

def write_person(fields)
  return_response(soap_request("write_person", fields))
end