Created
July 2, 2012 08:14
-
-
Save vparihar01/3031822 to your computer and use it in GitHub Desktop.
My Service look Model i am trying to create ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Webservice Class which call all api like a REST | |
class UserWebservice | |
#include Mongoid::Document | |
def self.client(wsdl_location) | |
@@client ||= Savon::Client.new(wsdl_location) do |wsdl, http| | |
#to make sure savon dont try to have certificate and key | |
http.auth.ssl.verify_mode = :none | |
#wsdl document location | |
wsdl.document = wsdl_location.to_s | |
#to specify the wsdl endpoint | |
wsdl.endpoint = "https://qaservices.bamnetworks.com/ws/services/IdentityPointService" | |
#to specify the SOAP action and they should be in single inverted comma else request not completed | |
http.headers['SOAPAction'] = '"http://services.bamnetworks.com/registration/identityPoint/create"' | |
#to specify http header in request type ,content length ,time out time etc | |
http.headers = { "content-type"=> "text/xml","charset"=>"UTF-8", "Connection" => "Keep-Alive" } | |
end | |
end | |
# to fetch all list of soap actions listed in particular document | |
def self.soap_actions(wsdl_location) | |
return client(wsdl_location).wsdl.soap_actions | |
end | |
# Add invoke soap client request | |
def self.invoke(wsdl_location,action, parameters) | |
response = client(wsdl_location).request(:ns ,action) do |soap, wsdl, http| | |
add_http_header http | |
add_soap_header soap | |
soap.body = parameters | |
end | |
if response.success? | |
return response.to_hash | |
else | |
logger.info("response.soap_fault.to_s=>>>#{response.soap_fault.to_s}") if response.soap_fault.present? | |
logger.info("response.soap_fault.to_s=>>>#{response.http_error.to_s}") if response.http_error.present? | |
end | |
end | |
# Add soap header like app name and password | |
def self.add_soap_header(soap) | |
soap.namespaces["xmlns:ns0"]="http://services.bamnetworks.com/application/types/1.0" | |
soap.header = '<ns0:appCredentials xmlns:ns0="http://services.bamnetworks.com/application/types/1.0" ns0:name="mlb-academy" ns0:password="SD32sExf1Xg" />' | |
end | |
def self.add_http_header(http) | |
http.headers['SOAPAction'] = '"http://services.bamnetworks.com/registration/identityPoint/create"' | |
end | |
end | |
# We will be mostly using it for invoking methods. The kind of methods we will be able to invoke depends on the | |
# services that "MLB" provides. Let's imagine that 3 actions are available - :identityPoint_create_reques, :create & | |
# :find_identity_points. We can confirm that the list is correct by doing this on the rails console: | |
# MyWebservice.soap_actions | |
# => [:identityPoint_create_request, :create, :find_identity_points] | |
# Now imagine that you want to invoke :identityPoint_create_request. First we need to know which parameters are needed for that call. | |
parameter = {:identification => {:email => {:address => "vivek@yopmail.com"},:password =>"12345678"},:profileProperty => {:name => "birthDay",:value => "17"},:profileProperty => {:name => "birthMonth",:value => "8"},:profileProperty => {:name => "birthYear",:value => "1986"},:attributes! => { :identification => { :type => "email-password" } }} | |
UserWebservice.invoke("https://qaservices.bamnetworks.com/ws/services/IdentityPointService?wsdl","identityPoint_create_request",parameter) | |
# => {:status => 'ok'} | |
# We will get a hash as a response. In this case I got an 'ok' status, but it could be far more complex. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment