Class: SoarSr::Contacts

Inherits:
Handler show all
Defined in:
lib/soar_sr/contacts.rb

Instance Attribute Summary

Attributes inherited from Handler

#registry

Instance Method Summary collapse

Methods inherited from Handler

#authorize, #initialize

Methods inherited from Validator

#authorized?, #contact?, #credentials?, #identifier?, #key_provided?, #length_at_least?, #meta?, #one_of, #present?, #provided?, #type?, #uri?, #wadl?

Constructor Details

This class inherits a constructor from SoarSr::Handler

Instance Method Details

#add_contact_to_domain_perspective(domain_perspective, contact) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/soar_sr/contacts.rb', line 3

def add_contact_to_domain_perspective(domain_perspective, contact)_{
  domain_perspective = standardize(domain_perspective)            
  authorize
  provided?(domain_perspective, 'domain perspective') and any_registered?(domain_perspective)
  provided?(contact, 'contact details') and contact?(contact)
  details = {}.merge!(contact)
  details = ensure_required_contact_details(details)

  result = @registry.domain_perspectives.domain_perspective_registered?(domain_perspective)
  result =  @registry.teams.team_registered?(domain_perspective) if result['data']['id'].nil?

  id = result['data']['id']
  domain_perspective = @uddi.get_business(id)['data'].first[1]

  domain_perspective['contacts'] ||= []

  return fail('contact already exists - remove first to update') if contacts_include?(domain_perspective['contacts'], details)

  domain_perspective['contacts'] << details

  @uddi.save_business(id, domain_perspective['name'], domain_perspective['description'], domain_perspective['contacts'])
}end

#contact_details_for_domain(domain_perspective) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/soar_sr/contacts.rb', line 26

def contact_details_for_domain(domain_perspective)_{
  domain_perspective = standardize(domain_perspective)            
  provided?(domain_perspective, 'domain perspective') and any_registered?(domain_perspective)
  result = @registry.domain_perspectives.domain_perspective_registered?(domain_perspective)
  result =  @registry.teams.team_registered?(domain_perspective) if result['data']['id'].nil?
  id = result['data']['id']
  domain_perspective = @uddi.get_business(id)['data'].first[1]
  domain_perspective['contacts'] ||= []
  domain_perspective['contacts'].each do |contact|
    contact['description'] = '' if contact['description'] == 'n/a'
    contact['email'] = '' if contact['email'] == 'n/a'
    contact['phone'] = '' if contact['phone'] == 'n/a'
  end
  success_data('contacts' => domain_perspective['contacts'])
}end

#remove_contact_from_domain_perspective(domain_perspective, contact) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/soar_sr/contacts.rb', line 42

def remove_contact_from_domain_perspective(domain_perspective, contact)_{
  domain_perspective = standardize(domain_perspective)            
  authorize
  provided?(domain_perspective, 'domain perspective') and any_registered?(domain_perspective)
  provided?(contact, 'contact details') and contact?(contact)

  result = @registry.domain_perspectives.domain_perspective_registered?(domain_perspective)
  result =  @registry.teams.team_registered?(domain_perspective) if result['data']['id'].nil?

  id = result['data']['id']
  domain_perspective = @uddi.get_business(id)['data'].first[1]

  domain_perspective['contacts'] ||= []

  return fail('unknown contact') if not contacts_include?(domain_perspective['contacts'], contact)

  domain_perspective['contacts'].delete(contact)
  domain_perspective['contacts'] = nil if domain_perspective['contacts'] == []

  @uddi.save_business(id, domain_perspective['name'], domain_perspective['description'], domain_perspective['contacts'])
}end