如何将用户状态消息更新到IBM Connections(Lotus连接API)?

时间:2013-04-26 07:18:53

标签: ruby-on-rails ruby lotus ibm-connections

我刚刚在更新状态消息时阅读了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身份验证。 但是,它没有像我预期的那样工作。错误显示&#34; ... 400 Bad Request(RestClient :: BadRequest)&#34;

我有什么遗失的东西吗? 非常感谢你们的任何帮助/想法。谢谢!

1 个答案:

答案 0 :(得分: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