1

我刚刚阅读了关于更新状态消息的 Lotus Connection API 手册(来源:http ://www-10.lotus.com/ldd/lcwiki.nsf/dx/Updating_a_status_message_ic301 )但是我没有找到关于如何更新用户状态信息?

我已经制作了一个基本的 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 Bad Request (RestClient::BadRequest)”

有什么我想念的吗?你们的任何帮助/想法将不胜感激。谢谢!

4

1 回答 1

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
于 2013-04-30T05:22:39.300 回答