Ruby on rails 如何将用户状态消息更新到IBM Connections(Lotus connection API)?

Ruby on rails 如何将用户状态消息更新到IBM Connections(Lotus connection API)?,ruby-on-rails,ruby,lotus,ibm-connections,Ruby On Rails,Ruby,Lotus,Ibm Connections,我刚刚阅读了LotusConnectionAPI关于更新状态消息的手册(源代码:),但是我没有找到 关于如何更新用户状态消息的示例脚本 我已经做了一个基本的Ruby脚本。见下文: url = "https://w3-connections.ibm.com/profiles/atom/mv/theboard/entry/status.do?userid=#{username}" auth = 'Basic ' + Base64.encode64( "#{username}:#{password}"

我刚刚阅读了LotusConnectionAPI关于更新状态消息的手册(源代码:),但是我没有找到 关于如何更新用户状态消息的示例脚本

我已经做了一个基本的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
url=”https://w3-connections.ibm.com/profiles/atom/mv/theboard/entry/status.do?userid=#{username}”
auth='Basic'+Base64.encode64(“#{username}:#{password}”).chomp
消息='
你好
早晨!祝你有愉快的一天!
'
resource=RestClient::resource.new(url,{:headers=>{'Authorization'=>auth})
response=resource.put消息,:content\u type=>'application/atom+xml'
把答案放进去
我在Ruby中使用RestClient(RestClient(1.6.7))进行HTTP身份验证。 然而,它并没有像我预期的那样起作用。错误显示为“…400错误请求(RestClient::BadRequest)”

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

谢谢大家的帮助和建议。经过一个小时的努力,我终于成功了。这是最新的代码

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
类IbmConnections
def初始化(用户名、密码)
@用户名=用户名
@密码=密码
结束
def post_状态_消息
需要“休息\客户”
原子=”
你好
早上好!祝你有愉快的一天!
"
开始
url=”https://w3-connections.ibm.com/profiles/atom/mv/theboard/entry/status.do"
资源=验证url、@username、@password
response=resource.put atom,:content\u type=>'application/atom+xml'
如果response.empty?
返回{:success=>'true',:message=>“成功更新您的状态!”,:data=>atom}
其他的
return{:success=>'false',:message=>“发布到连接时出错!
请与管理员联系。”,:data=>atom} 结束 rescue=>错误 logger.debug“错误:IbmConnections.post_it_连接(2)” logger.debug error.inspect return{:success=>'false',:message=>“发布到连接时出错!
请与管理员联系。”,:data=>Error.inspect} 结束 结束 def验证url、用户名、密码 auth='Basic'+Base64.strict_encode64(“#{username}:#{password}”) RestClient::Resource.new(url,{:headers=>{'Authorization'=>auth}) 结束 结束
谢谢大家的帮助和建议。经过一个小时的努力,我终于成功了。这是最新的代码

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
类IbmConnections
def初始化(用户名、密码)
@用户名=用户名
@密码=密码
结束
def post_状态_消息
需要“休息\客户”
原子=”
你好
早上好!祝你有愉快的一天!
"
开始
url=”https://w3-connections.ibm.com/profiles/atom/mv/theboard/entry/status.do"
资源=验证url、@username、@password
response=resource.put atom,:content\u type=>'application/atom+xml'
如果response.empty?
返回{:success=>'true',:message=>“成功更新您的状态!”,:data=>atom}
其他的
return{:success=>'false',:message=>“发布到连接时出错!
请与管理员联系。”,:data=>atom} 结束 rescue=>错误 logger.debug“错误:IbmConnections.post_it_连接(2)” logger.debug error.inspect return{:success=>'false',:message=>“发布到连接时出错!
请与管理员联系。”,:data=>Error.inspect} 结束 结束 def验证url、用户名、密码 auth='Basic'+Base64.strict_encode64(“#{username}:#{password}”) RestClient::Resource.new(url,{:headers=>{'Authorization'=>auth}) 结束 结束
您是否尝试过使用基于浏览器的rest客户端?这将允许您在发送请求之前确认浏览器中的身份验证是否成功?这将允许您在发送请求之前确认浏览器中的身份验证是否成功。请查看IBM Social Business Toolkit: