1

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

谢谢

4

2 回答 2

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
于 2012-11-12T17:54:59.213 回答
1

使用 Magento API 的 C# 示例

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

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

于 2011-04-25T15:37:04.397 回答