Created
July 9, 2011 01:31
-
-
Save j4y/1073197 to your computer and use it in GitHub Desktop.
connecting to Landslide CRM's SOAP api using savon 0.9.1 without WDSL introspection
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'savon' | |
require 'httpclient' | |
require 'digest/md5' | |
# TODO: these variables belong in config files | |
LS_INSTANCE_NAME = 'vip' | |
LS_USERNAME = 'vip@landslide.com' | |
LS_PASSWORD = Digest::MD5.hexdigest('vip' + LS_INSTANCE_NAME) | |
LS_API_ENDPOINT_HOST = "#{ENV['RAILS_ENV'] == 'Development' ? 'alt.corp.landslide.com:5196' : 'api.landslide.com' }" | |
LS_API_ENDPOINT_HOST = "api.landslide.com" | |
LS_API_ENDPOINT_URL = "https://#{LS_INSTANCE_NAME}.#{LS_API_ENDPOINT_HOST}/webservices/SoapService" | |
LS_API_NAMESPACE = "http://www.landslide.com/webservices/SoapService" | |
#LS_API_WSDL_URL = "#{LS_API_ENDPOINT_URL}?wsdl" | |
puts "Endpoint: #{LS_API_ENDPOINT_URL}" | |
# Client instance with a SOAP endpoint (for using Savon without a WSDL) | |
client = Savon::Client.new do |wsdl| | |
wsdl.endpoint = LS_API_ENDPOINT_URL | |
wsdl.namespace = LS_API_NAMESPACE | |
end | |
# Explicit login | |
response = client.request :login do |soap| | |
soap.namespaces["xmlns:urn"] = LS_API_NAMESPACE | |
soap.header = { "urn:SessionHeader" => {"urn:sessionId" => "LOGINTOKEN=#{LS_INSTANCE_NAME}" } } | |
soap.body = { "wsUser" => { :username => LS_USERNAME, :password => LS_PASSWORD } } | |
end | |
if response.success? | |
puts "/n/n/nResponse without wsdl inspection:\n" | |
@sid = response.to_hash[:login_response][:login_response][:session_id] | |
end | |
# Implicit login | |
response = client.request :get_accounts do |soap| | |
soap.namespaces["xmlns:urn"] = LS_API_NAMESPACE | |
soap.header = { "urn:SessionHeader" => {"urn:sessionId" => @sid } } | |
soap.body = { :accountsRequest => { :search_criteria => | |
{ :field_id => "MainAddressCity", | |
:operator => "NotEmpty" | |
}, | |
:first_result_position => 1, | |
:total_results_requested => 10 | |
} | |
} | |
end | |
if response.success? | |
puts response.to_hash | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment