2013-04-26 29 views
1

我剛剛閱讀了關於更新狀態消息的Lotus Connection API手冊(來源:http://www-10.lotus.com/ldd/lcwiki.nsf/dx/Updating_a_status_message_ic301),但是我沒有找到 關於如何更新用戶狀態消息的示例腳本?如何將用戶狀態消息更新到IBM Connections(Lotus連接API)?

我做了一個基本的Ruby腳本。見下:

url = "https://w3-connections.ibm.com/profiles/atom/mv/theboard/entry/status.do?userid=#{username}" 
auth = 'Basic ' + Base64.encode64("#{username}:#{password}").chomp 
message = '<entry xmlns="http://www.w3.org/2005/Atom"> 
<title type="text">Hi!</title> 
<category term="entry" scheme="http://www.ibm.com/xmlns/prod/sn/type" /> 
<category term="status" scheme="http://www.ibm.com/xmlns/prod/sn/message-type" /> 
<content type="text">Morning! Have a nice day ahead!</content> 
</entry>' 
resource = RestClient::Resource.new(url, { :headers => { 'Authorization' => auth } }) 
response = resource.put message, :content_type => 'application/atom+xml' 
puts response.inspect 

我在Ruby中使用RestClient(rest-client(1.6.7))進行HTTP身份驗證。 但是,它沒有按照我的預期工作。錯誤說「... 400錯誤請求(RestClient :: BadRequest)」

有什麼我失蹤了嗎? 從你們任何幫助/想法將不勝感激。謝謝!

+0

您是否嘗試過使用基於瀏覽器的休息客戶端?這將允許您在發送請求之前確認瀏覽器中的身份驗證成功。 – 2013-04-26 08:59:39

+0

查看IBM Social Business Toolkit:http://www-10.lotus.com/ldd/appdevwiki.nsf/xpViewCategories.xsp?lookupName=IBM%20Social%20Business%20Toolkit%20SDK%20documentation – 2013-04-26 16:21:41

回答

1

感謝您的幫助和建議傢伙。經過一個小時的修補後,我已經成功了。下面是更新後的代碼!

class IbmConnections 

    def initialize(username, password) 
    @username = username 
    @password = password 
    end 

    def post_status_message 
    require 'rest_client' 
    atom = " 
    <entry xmlns='http://www.w3.org/2005/Atom'> 
    <title type='text'>Hi</title> 
    <category term='entry' scheme='http://www.ibm.com/xmlns/prod/sn/type' /> 
    <category term='status' scheme='http://www.ibm.com/xmlns/prod/sn/message-type' /> 
    <content type='text'>Morning! Have a nice day ahead!</content> 
    </entry>" 

    begin 
     url = "https://w3-connections.ibm.com/profiles/atom/mv/theboard/entry/status.do" 
     resource = authenticate url, @username, @password 
     response = resource.put atom, :content_type => 'application/atom+xml' 
     if response.empty? 
     return {:success => 'true', :message => "Successfully update your status!", :data => atom} 
     else 
     return {:success => 'false', :message => "Error occurred while posting to Connections! <br /> Please contact the administrator.", :data => atom} 
     end 
    rescue => error 
     logger.debug "Error: IbmConnections.post_it_connections(2)" 
     logger.debug error.inspect 
     return {:success => 'false', :message => "Error occurred while posting to Connections! <br /> Please contact the administrator.", :data => error.inspect} 
    end 
    end 

    def authenticate url, username, password 
    auth = 'Basic ' + Base64.strict_encode64("#{username}:#{password}") 
    RestClient::Resource.new(url, { :headers => { 'Authorization' => auth } }) 
    end 
end