如何在Magento SOAP API中使用savon gem

时间:2011-04-25 13:18:12

标签: ruby magento savon

如何使用Magento SOAP API gem访问savon。我有什么例子可以用来快速前进吗?

由于

2 个答案:

答案 0 :(得分:6)

试试这个让你入门:

require 'rubygems'
require 'savon'

client = Savon::Client.new do
  wsdl.document = "http://your.server.here/index.php/api/?wsdl"
end

response = client.request :login do
  soap.body = { :username => 'soapuser', :apiKey => 'myapikey' }
end

if response.success? == false
  puts "login failed"
  System.exit(0)
end

session =  response[:login_response][:login_return];

response = client.request :call do
  soap.body = {:session => session,:method => 'catalog_product.list' }
end

# fetching all products
if response.success?
  # listing found products
  response[:call_response][:call_return][:item].each do |product|
    puts "-------------------------------------------"
    product = product[:item]
    product.each do |pkey|
        puts "#{pkey[:key]} -> #{pkey[:value]}"
    end
  end
end

#logging out
response = client.request :endSession do
  soap.body = {:session => session}
end
puts response.to_hash

答案 1 :(得分:1)

C# Example of using Magento's API

这同样适用于任何其他语言,包括ruby。显然语法会有所不同,我假设您已经知道Savon syntax

您可能还想结帐:https://github.com/timmatheson/Magento#readme