Reputation: 3103
Ive just read the manual(source:http://www-10.lotus.com/ldd/lcwiki.nsf/dx/Updating_a_status_message_ic301) of Lotus Connection API on updating a status message however I did not find a sample script on how to update user status message?
I have made a basic Ruby scripts. See below:
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
I'm using RestClient(rest-client (1.6.7)) in Ruby for HTTP Authentication. However, it didnt work as I expected. The error says "...400 Bad Request (RestClient::BadRequest)"
Is there something I'm missing? Any help/ideas from you guys would greatly be appreciated. Thanks!
Upvotes: 1
Views: 852
Reputation: 3103
Thanks for the help and suggestion guys. After tinkering an hour, I've successfully made it. Heres the updated code that works!
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
Upvotes: 1