2010-08-25 60 views
1

我想實現調用紅寶石https://zferral.com/api-docs/affiliate#aff-create-usage-example此API方法,它預計這一對象:如何消耗,使用複雜的對象REST API Httparty和Ruby

{ "affiliate" : { 
    "email"   : "[email protected]", 
    "send_user_email" : "1" }} 

使用Httparty類,我稱之爲:

result = self.class.post("/api/#{@apikey}/affiliate/create.xml", :body => {:affiliate => {:email => email}}) 

不幸的是,API不斷髮送給我「需要電子郵件」。我試圖切換到JSON,我改變了:身體與:查詢等...

任何人都可以告訴我如何正確地調用聯盟/創建方法?

謝謝。

回答

2

這是我固定我的問題:

url = URI.parse('https://xxxx.zferral.com/api/xxx/affiliate/create.xml') 
    http = Net::HTTP.new(url.host, url.port) 
    http.use_ssl = true 
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE 
    request = Net::HTTP::Post.new(url.path) 
    request.body = "<?xml version='1.0' encoding='UTF-8'?><affiliate><email>#{email}</email><send_user_email>0</send_user_email></affiliate>" 
    request.content_type = 'text/xml' 
    response = http.request(request) 
+1

接受這個答案即可。 – Simpleton 2011-09-03 11:26:38