lib/identity_linker/linker.rb in identity_linker-0.0.2 vs lib/identity_linker/linker.rb in identity_linker-0.0.3
- old
+ new
@@ -1,6 +1,7 @@
require 'savon'
+require 'identity_linker/error'
module IdentityLinker
class Linker
extend Savon::Model
@@ -13,122 +14,141 @@
@server_id = server_id || IdentityLinker.config.server_id
@server_secret = server_secret || IdentityLinker.config.server_secret
end
def find_linked_identity(id_type, id_value, target)
- response = client.request(:wsdl, :find_linked_identity) do
- xml = <<-END
- <serverId>#{server_id}</serverId>
- <serverSecret>#{server_secret}</serverSecret>
- <identity>
- <idType>#{id_type}</idType>
- <idValue>#{id_value}</idValue>
- </identity>
- <target>#{target}</target>
- END
- soap.body = xml
- end
+ begin
+ response = client.request(:wsdl, :find_linked_identity) do
+ xml = <<-END
+ <serverId>#{server_id}</serverId>
+ <serverSecret>#{server_secret}</serverSecret>
+ <identity>
+ <idType>#{id_type}</idType>
+ <idValue>#{id_value}</idValue>
+ </identity>
+ <target>#{target}</target>
+ END
+ soap.body = xml
+ end
- if response.success?
- return response.to_hash[:find_linked_identity_response][:linked_identity]
+ if response.success?
+ return response.to_hash[:find_linked_identity_response][:linked_identity]
+ end
+ rescue Savon::SOAP::Fault => e
+ raise Error.new(e)
end
nil
end
def self.find_linked_identity(id_type, id_value, target)
new.find_linked_identity(id_type, id_value, target)
end
def find_linked_identity_with_details(id_type, id_value, target)
- response = client.request(:wsdl, :find_linked_identity_with_details) do
- xml = <<-END
- <serverId>#{server_id}</serverId>
- <serverSecret>#{server_secret}</serverSecret>
- <identity>
- <idType>#{id_type}</idType>
- <idValue>#{id_value}</idValue>
- </identity>
- <target>#{target}</target>
- END
- soap.body = xml
- end
+ begin
+ response = client.request(:wsdl, :find_linked_identity_with_details) do
+ xml = <<-END
+ <serverId>#{server_id}</serverId>
+ <serverSecret>#{server_secret}</serverSecret>
+ <identity>
+ <idType>#{id_type}</idType>
+ <idValue>#{id_value}</idValue>
+ </identity>
+ <target>#{target}</target>
+ END
+ soap.body = xml
+ end
- if response.success?
- return response.to_hash[:find_linked_identity_with_details_response][:linked_identity]
+ if response.success?
+ return response.to_hash[:find_linked_identity_with_details_response][:linked_identity]
+ end
+ rescue Savon::SOAP::Fault => e
+ raise Error.new(e)
end
-
nil
end
def self.find_linked_identity_with_details(id_type, id_value, target)
new.find_linked_identity_with_details(id_type, id_value, target)
end
def find_all_linked_identities(id_type, id_value)
- response = client.request(:wsdl, :find_all_linked_identities) do
- xml = <<-END
+ begin
+ response = client.request(:wsdl, :find_all_linked_identities) do
+ xml = <<-END
<serverId>#{server_id}</serverId>
<serverSecret>#{server_secret}</serverSecret>
<identity>
<idType>#{id_type}</idType>
<idValue>#{id_value}</idValue>
</identity>
- END
- soap.body = xml
- end
+ END
+ soap.body = xml
+ end
- if response.success?
- return response.to_hash[:find_all_linked_identities_response][:linked_identity]
+ if response.success?
+ return response.to_hash[:find_all_linked_identities_response][:linked_identity]
+ end
+ rescue Savon::SOAP::Fault => e
+ raise Error.new(e)
end
nil
end
def self.find_all_linked_identities(id_type, id_value)
new.find_all_linked_identities(id_type, id_value)
end
def find_all_linked_identities_with_details(id_type, id_value)
- response = client.request(:wsdl, :find_all_linked_identities_with_details) do
- xml = <<-END
+ begin
+ response = client.request(:wsdl, :find_all_linked_identities_with_details) do
+ xml = <<-END
<serverId>#{server_id}</serverId>
<serverSecret>#{server_secret}</serverSecret>
<identity>
<idType>#{id_type}</idType>
<idValue>#{id_value}</idValue>
</identity>
- END
- soap.body = xml
- end
+ END
+ soap.body = xml
+ end
- if response.success?
- return response.to_hash[:find_all_linked_identities_with_details_response][:linked_identity]
+ if response.success?
+ return response.to_hash[:find_all_linked_identities_with_details_response][:linked_identity]
+ end
+ rescue Savon::SOAP::Fault => e
+ raise Error.new(e)
end
nil
end
def self.find_all_linked_identities_with_details(id_type, id_value)
new.find_all_linked_identities_with_details(id_type, id_value)
end
def find_linked_identities_of_type(id_type, id_value, target)
- response = client.request(:wsdl, :find_linked_identities_of_type) do
- xml = <<-END
+ begin
+ response = client.request(:wsdl, :find_linked_identities_of_type) do
+ xml = <<-END
<serverId>#{server_id}</serverId>
<serverSecret>#{server_secret}</serverSecret>
<identity>
<idType>#{id_type}</idType>
<idValue>#{id_value}</idValue>
</identity>
<target>#{target}</target>
- END
- soap.body = xml
- end
+ END
+ soap.body = xml
+ end
- if response.success?
- return [response.to_hash[:find_linked_identities_of_type_response][:linked_identity]].flatten.compact
+ if response.success?
+ return [response.to_hash[:find_linked_identities_of_type_response][:linked_identity]].flatten.compact
+ end
+ rescue Savon::SOAP::Fault => e
+ raise Error.new(e)
end
nil
end