Class: Soap4juddi::Broker

Inherits:
Object
  • Object
show all
Defined in:
lib/soap4juddi/broker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(urns) ⇒ Broker

Returns a new instance of Broker.



11
12
13
14
15
# File 'lib/soap4juddi/broker.rb', line 11

def initialize(urns)
  @urns = urns
  @soap_connector = Soap4juddi::Connector.new
  @soap_xml = Soap4juddi::XML.new
end

Instance Attribute Details

#base_uriObject

Returns the value of attribute base_uri.



9
10
11
# File 'lib/soap4juddi/broker.rb', line 9

def base_uri
  @base_uri
end

#soap_connectorObject (readonly)

Returns the value of attribute soap_connector.



7
8
9
# File 'lib/soap4juddi/broker.rb', line 7

def soap_connector
  @soap_connector
end

#soap_xmlObject (readonly)

Returns the value of attribute soap_xml.



8
9
10
# File 'lib/soap4juddi/broker.rb', line 8

def soap_xml
  @soap_xml
end

#urnsObject (readonly)

Returns the value of attribute urns.



6
7
8
# File 'lib/soap4juddi/broker.rb', line 6

def urns
  @urns
end

Instance Method Details

#authenticate(auth_user, auth_password) ⇒ Object



137
138
139
# File 'lib/soap4juddi/broker.rb', line 137

def authenticate(auth_user, auth_password)
  @soap_connector.authenticate(auth_user, auth_password)
end

#authorizeObject



141
142
143
# File 'lib/soap4juddi/broker.rb', line 141

def authorize
  @auth_token = @soap_connector.authorize(@base_uri)
end

#delete_binding(binding) ⇒ Object



79
80
81
82
83
84
# File 'lib/soap4juddi/broker.rb', line 79

def delete_binding(binding)
  xml = @soap_xml.element_with_value('bindingKey', binding)
  @soap_connector.request_soap(@base_uri, 'publishv2', 'delete_binding', "#{auth_body} #{xml}") do |res|
    { 'errno' => extract_errno(res.body) }
  end
end

#delete_business(key) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/soap4juddi/broker.rb', line 51

def delete_business(key)
  xml = @soap_xml.element_with_value('businessKey', key)
  @soap_connector.request_soap(@base_uri, 'publishv2', 'delete_business',
  "#{auth_body} #{xml}") do |res|
    { 'errno' => extract_errno(res.body) }
  end
end

#delete_service_element(name, urn) ⇒ Object



124
125
126
127
128
129
# File 'lib/soap4juddi/broker.rb', line 124

def delete_service_element(name, urn)
  service_key = @soap_xml.element_with_value('serviceKey', "#{urn}#{name}")
  @soap_connector.request_soap(@base_uri, 'publishv2', 'delete_service', "#{auth_body} #{service_key}") do |res|
    { 'errno' => extract_errno(res.body) }
  end
end

#extract_service(soap) ⇒ Object



131
132
133
134
135
# File 'lib/soap4juddi/broker.rb', line 131

def extract_service(soap)
  entries = {}
  entries[@soap_xml.extract_value(soap, 'serviceKey')] = extract_name(soap)
  entries
end

#find_business(pattern) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/soap4juddi/broker.rb', line 43

def find_business(pattern)
  qualifiers = @soap_xml.element_with_value('findQualifiers', @soap_xml.element_with_value('findQualifier', 'approximateMatch'))
  xml = @soap_xml.element_with_value('name', pattern)
  @soap_connector.request_soap(@base_uri, 'inquiryv2', 'find_business', "#{qualifiers} #{xml}") do |res|
    extract_business_entries(res.body)
  end
end

#find_element_bindings(name, urn) ⇒ Object



73
74
75
76
77
# File 'lib/soap4juddi/broker.rb', line 73

def find_element_bindings(name, urn)
  @soap_connector.request_soap(@base_uri, 'inquiryv2', 'get_serviceDetail', @soap_xml.element_with_value('serviceKey', "#{urn}#{name}")) do |res|
    extract_bindings(res.body)
  end
end

#find_service_components(pattern) ⇒ Object



69
70
71
# File 'lib/soap4juddi/broker.rb', line 69

def find_service_components(pattern)
  find_services(pattern, 'service-components')
end

#find_services(pattern, type = 'services') ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/soap4juddi/broker.rb', line 59

def find_services(pattern, type = 'services')
  qualifier1 = @soap_xml.element_with_value('findQualifier', 'approximateMatch')
  qualifier2 = @soap_xml.element_with_value('findQualifier', 'orAllKeys')
  qualifiers = @soap_xml.element_with_value('findQualifiers', "#{qualifier1}#{qualifier2}")
  xml = @soap_xml.element_with_value('name', pattern)
  @soap_connector.request_soap(@base_uri, 'inquiryv2', 'find_service', "#{qualifiers} #{xml}") do |res|
    extract_service_entries_elements(res.body, @urns[type])
  end
end

#get_business(key) ⇒ Object



37
38
39
40
41
# File 'lib/soap4juddi/broker.rb', line 37

def get_business(key)
  @soap_connector.request_soap(@base_uri, 'inquiryv2', 'get_businessDetail', @soap_xml.element_with_value('businessKey', key)) do |res|
    extract_business(res.body)
  end
end

#get_service_element(name, urn) ⇒ Object



86
87
88
89
90
91
92
93
94
# File 'lib/soap4juddi/broker.rb', line 86

def get_service_element(name, urn)
  key = name.include?(urn) ? name : "#{urn}#{name}"
  xml = @soap_xml.element_with_value('serviceKey', key)
  @soap_connector.request_soap(@base_uri, 'inquiryv2', 'get_serviceDetail', "#{xml}") do |res|
    { 'name' => extract_name(res.body),
      'description' => extract_descriptions(res.body),
      'definition' => extract_service_definition(res.body) }
  end
end

#save_business(key, name, descriptions, contacts) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/soap4juddi/broker.rb', line 26

def save_business(key, name, descriptions, contacts)
  validate_elements(contacts, 'contacts')
  validate_elements(descriptions, 'descriptions')
  body = build_business_entity(key, name, descriptions, contacts)
  @soap_connector.request_soap(@base_uri,
               'publishv2', 'save_business',
               "#{auth_body} #{body}") do | res|
    extract_business(res.body)
  end
end

#save_element_bindings(service, bindings, urn, description) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/soap4juddi/broker.rb', line 17

def save_element_bindings(service, bindings, urn, description)
  validate_elements(bindings, 'bindings')
  body = auth_body
  body = add_bindings(body, service, bindings, urn, description)
  @soap_connector.request_soap(@base_uri, 'publishv2', 'save_binding', body) do | res|
    res.body
  end
end

#save_service_element(name, description, definition, urn, business_key) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/soap4juddi/broker.rb', line 96

def save_service_element(name, description, definition, urn, business_key)
  # preserve bindings
  bindings = find_element_bindings_access_points(name, urn)['data']['result']

  service_details = @soap_xml.element_with_value('name', name)
  if description
    description.each do |desc|
      service_details = service_details + @soap_xml.element_with_value('description', desc, { 'xml:lang' => 'en' }) if desc and not (desc == "")
    end
  end
  if definition and not (definition.strip == "")
    keyedReference = @soap_xml.element_with_value('keyedReference', '', {'tModelKey' => 'uddi:uddi.org:wadl:types', 'keyName' => 'service-definition', 'keyValue' => definition})
    service_details = service_details + @soap_xml.element_with_value('categoryBag', keyedReference)
  end
  xml = @soap_xml.element_with_value('businessService', service_details, {'businessKey' => business_key, 'serviceKey' => "#{urn}#{name}"})

  body = "#{auth_body} #{xml}"

  result = @soap_connector.request_soap(@base_uri, 'publishv2', 'save_service', body) do | res|
    extract_service(res.body)
  end

  #restore bindings
  save_element_bindings(name, bindings, urn, '')

  result
end