ExamplePrivateModeRubyScript

require 'net/http' require 'net/https' require 'rexml/document' include REXML, Net
 * 1) !/usr/bin/ruby -w
 * 2) Script to demonstrate how to determine whether an instance of
 * 3) StatusNet is configured to be &quot;private&quot;.  -- By Zach Copley, CYI
 * 1) StatusNet is configured to be &quot;private&quot;.  -- By Zach Copley, CYI

API_ROOT = 'http://localhost/statusnet/api' PUBLIC_TIMELINE_URL = API_ROOT + '/statuses/public_timeline.xml' NICKNAME = 'nickname' PASSWORD = 'password'

def get_api_data(url, nickname=nil, password=nil) parsed_url = URI.parse(url) request = HTTP::Get.new(parsed_url.path)
 * 1) get data from the API, return XML document

# add basic auth if (nickname &amp;amp;&amp;amp; password) request.basic_auth nickname, password end

http = HTTP.new(parsed_url.host) response = http.request(request) return response.body end

def is_private config_url = API_ROOT + '/statusnet/config.xml' config_xml = HTTP.get_response(URI.parse(config_url)).body; doc = Document.new(config_xml) # &amp;lt;config&amp;gt; #  &amp;lt;site&amp;gt; #   ....  #     &amp;lt;private&amp;gt;true&amp;lt;/private&amp;gt; #   ....  closed = XPath.first(doc, '/config/site/private/text') return closed == 'true' || false end
 * 1) query StatusNet to see whether it's a private instance

def show_statuses(xml) doc = REXML::Document.new(xml) doc.elements.each('statuses/status') do |s| puts s.elements['user/screen_name'].text + ': ' + s.elements['text'].text end end
 * 1) print statuses

unless is_private # request data as you normally would show_statuses(get_api_data(PUBLIC_TIMELINE_URL)) else puts &quot;[Private site]&quot; # site is closed, so everything requires basic auth show_statuses(get_api_data(PUBLIC_TIMELINE_URL, NICKNAME, PASSWORD)) end