<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>i shine light &#187; Ruby</title>
	<atom:link href="http://www.ishinelight.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ishinelight.com</link>
	<description>in a digital world</description>
	<lastBuildDate>Mon, 21 Sep 2009 03:29:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>XML feed to Twitter</title>
		<link>http://www.ishinelight.com/2009/05/xml-feed-to-twitter/</link>
		<comments>http://www.ishinelight.com/2009/05/xml-feed-to-twitter/#comments</comments>
		<pubDate>Fri, 08 May 2009 16:28:43 +0000</pubDate>
		<dc:creator>Aaron Reimann</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.ishinelight.com/?p=134</guid>
		<description><![CDATA[Requirements for create the script:

A computer with Ruby, or, if you have good hosting, you can SSH in and run Ruby there
The ability to install a Ruby gem, or maybe it is already installed
A text editor (Vi is what I used)
A Twitter account

First things first, let&#8217;s go into your shell and see if you have [...]]]></description>
			<content:encoded><![CDATA[<p>Requirements for create the script:</p>
<ul>
<li>A computer with Ruby, or, if you have good hosting, you can SSH in and run Ruby there</li>
<li>The ability to install a Ruby gem, or maybe it is already installed</li>
<li>A text editor (Vi is what I used)</li>
<li>A Twitter account</li>
</ul>
<p>First things first, let&#8217;s go into your shell and see if you have the plugins (gems) you need already installed.  Type this in to see if the gems we need are installed:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;color: #ccc; font: 12px Consolas, Lucida Console, Monaco, monospace;">gem list</pre></td></tr></table></div>

<p>If you do not see &#8220;feed-normalizer&#8221; and &#8220;twitter4r&#8221; in the list, do this to install them:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;color: #ccc; font: 12px Consolas, Lucida Console, Monaco, monospace;">gem install feed-normalizer twitter4r</pre></td></tr></table></div>

<p>It probably will take a while to &#8220;Bulk update&#8221; the Gem source, that is normal.  Make sure to say &#8220;Y&#8221; (yes) to install of the dependencies when prompted.  It will install Gems like simple-rss, hoe, rubyforge, rake, json, etc.</p>
<ul>
<b>Side Note:</b> You can make sure the Gems are installed by using IRB.  So, type in &#8220;irb&#8221; (Windows user will probably have to go to c:\ruby\bin if Ruby is not in your path) and type in:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;color: #ccc; font: 12px Consolas, Lucida Console, Monaco, monospace;"><span class="kw3">require</span> <span class="st0">'twitter4r'</span></pre></td></tr></table></div>

<p>and the result should show &#8220;=> true&#8221;.  If you get a &#8220;=> false&#8221;, that means it was not installed.  I don&#8217;t know what could have gone wrong.  I haven&#8217;t had any problems in OSX, Linux or Windows installing Gems.
</ul>
<p>Now that we have the Gems installed we need to find a feed.  Almost any &#8220;normal&#8221; feed will work.  I used the feed for Torah Portions (http://www.torahportions.org/portions_rss.php).</p>
<p>Here is the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;color: #ccc; font: 12px Consolas, Lucida Console, Monaco, monospace;"><span class="co1">#!/usr/bin/ruby</span>
<span class="kw3">require</span> <span class="st0">'rubygems'</span>
<span class="kw3">require</span> <span class="st0">'feed-normalizer'</span>
gem<span class="br0">&#40;</span><span class="st0">'twitter4r'</span>, <span class="st0">'&gt;=0.2.0'</span><span class="br0">&#41;</span>
<span class="kw3">require</span><span class="br0">&#40;</span><span class="st0">'twitter'</span><span class="br0">&#41;</span>
&nbsp;
<span class="co1">#grabbing the url, and setting up the Normilzer</span>
feed_url = <span class="st0">'http://www.torahportions.org/portions_rss.php'</span>
rss = <span class="re2">FeedNormalizer::FeedNormalizer</span>.<span class="me1">parse</span> <span class="kw3">open</span><span class="br0">&#40;</span>feed_url<span class="br0">&#41;</span>
&nbsp;
<span class="co1">#quit if for some reason there isn't a feed</span>
<span class="kw3">exit</span> <span class="kw1">unless</span> rss.<span class="me1">entries</span>.<span class="me1">length</span> <span class="sy0">&gt;</span> <span class="nu0">0</span>
&nbsp;
<span class="co1">#creating the array of the portion</span>
<span class="re1">@ary</span> = <span class="kw3">Array</span>.<span class="me1">new</span>
&nbsp;
<span class="co1">#read entries, push to the array called @ary</span>
rss.<span class="me1">entries</span>.<span class="me1">each</span> <span class="kw1">do</span> <span class="sy0">|</span>entry<span class="sy0">|</span>
        <span class="co1">#replacing &quot; Reading&quot; with just a &quot;:&quot; because tweats are limited to 140 char</span>
        title = entry.<span class="me1">title</span>.<span class="kw3">gsub</span><span class="br0">&#40;</span><span class="st0">' Reading'</span>, <span class="st0">':'</span><span class="br0">&#41;</span>
&nbsp;
        body = entry.<span class="me1">description</span> <span class="sy0">+</span> <span class="st0">&quot;<span class="es0">\r</span>&quot;</span>
&nbsp;
        <span class="co1">#actually adding to the array</span>
        <span class="re1">@ary</span>.<span class="me1">push</span><span class="br0">&#40;</span>title,body<span class="br0">&#41;</span>
<span class="kw1">end</span>
&nbsp;
&nbsp;
<span class="re1">@ary</span>.<span class="me1">delete_at</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span> <span class="co1">#removing the part that says &quot;This Weeks Portion&quot;</span>
<span class="re1">@ary</span>.<span class="me1">push</span><span class="br0">&#40;</span><span class="st0">&quot;...http://short.ie/torah&quot;</span><span class="br0">&#41;</span> <span class="co1">#adding the link to torahportions.org/this-week.html</span>
<span class="kw3">puts</span> <span class="re1">@ary</span>
&nbsp;
login = <span class="st0">'torahportions'</span> <span class="co1"># change this</span>
password = <span class="st0">'NOTMYPASSWORDHERE'</span> <span class="co1"># change this</span>
client = <span class="re2">Twitter::Client</span>.<span class="me1">new</span><span class="br0">&#40;</span><span class="re3">:login</span> <span class="sy0">=&gt;</span> login, <span class="re3">:password</span> <span class="sy0">=&gt;</span> password<span class="br0">&#41;</span>
<span class="co1">#status = client.status(:post, @ary)</span></pre></td></tr></table></div>

&nbsp; ]]></content:encoded>
			<wfw:commentRss>http://www.ishinelight.com/2009/05/xml-feed-to-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
