-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
303 lines (191 loc) · 12.2 KB
/
index.html
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>My First Ruby Gem - Garbled</title>
<meta name="author" content="Ben Hamill">
<meta name="description" content="I just released my first ruby gem, Twitter Alert. It's intended to be a component of the side project I mentioned forever ago, HeyGoVote. It …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://garbled.benhamill.com/2010/05/07/my-first-ruby-gem">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<link href="/atom.xml" rel="alternate" title="Garbled" type="application/atom+xml">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="./javascripts/lib/jquery.min.js"%3E%3C/script%3E'))</script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
</head>
<body >
<header role="banner"><hgroup>
<h1><a href="/">Garbled</a></h1>
</hgroup>
</header>
<nav role="navigation"><div>
<ul class="subscription" data-subscription="rss">
<li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:garbled.benhamill.com" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/blog/archives">Archives</a></li>
<li><a href="/about">About</a></li>
</ul>
<div>
</nav>
<div id="main-wrapper">
<div id="main">
<div id="content">
<div>
<article class="hentry" role="article">
<header>
<h1 class="entry-title">My First Ruby Gem</h1>
<p class="meta">
<time datetime="2010-05-07T00:00:00-05:00" pubdate data-updated="true">May 7<span>th</span>, 2010</time>
</p>
</header>
<div class="entry-content"><p>I just released my first ruby gem, <a href="http://rubygems.org/gems/twitter_alert">Twitter Alert</a>. It's intended to be a component of the side project <a href="http://garbled.benhamill.com/2009/09/new-side-project-heygovote/">I mentioned</a> forever ago, HeyGoVote. It grabs all the followers for a Twitter account and DMs them a message. The messages have dates on them because their intended to be schedule ahead of time. I'll crib from the readme near the end, but if you want, you can <a href="http://github.com/BenHamill/twitter_alert">go read the whole thing for yourself</a>. First, I'm going to talk a bit about my experience writing my first gem.</p>
<h2>Jeweler</h2>
<p>I used the <a href="http://github.com/technicalpickles/jeweler">jeweler</a> gem to create a gem template for this guy. It's very simple and was a huge boon considering this was my first time. It scaffolds out the directory structure for you, sets up some handy rake tasks and generally gives you guidance on how to structure your gem. The readme for jeweler is very helpful. I won't bother to restate what it says, but seriously, new to gems or not, you should have a look at jeweler if you haven't already. One of the nicest things is that it'll generate your gemspec file for you and also handle version bumping in a <a href="http://semver.org/">semantic versioning</a> compatible way. It also integrates with git and <a href="http://github.com">GitHub</a> in some interesting ways.</p>
<h2>Gemcutter</h2>
<p>Jeweler will also handle publishing your gem to "gemcutter" for you, which is nice. I say that in quotes because, of course, gemcutter.org is no longer a thing and their stuff all got officially adopted by <a href="http://rubygems.org">rubygems.org</a>, so it actually publishes to there. The jeweler documentation, though, all acts as if gemcutter were still a separate thing. This could be potentially confusing, I guess, but it ends up working right, so it's fine. It does use the gemcutter gem to manage the publishing, so you'll have to have that installed, and make sure you have a rubygems.org account and api key set up. The api key goes in ~/.gem/credentials as you'll learn on your rubgems profile.</p>
<h2>twitter_alert</h2>
<p>I'll crib from my readme example to show the most basic setup:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="nb">require</span> <span class="s1">'twitter_alert'</span>
</span><span class='line'>
</span><span class='line'><span class="n">account</span> <span class="o">=</span> <span class="ss">TwitterAlert</span><span class="p">:</span><span class="ss">:Account</span><span class="o">.</span><span class="n">new</span> <span class="ss">:user_name</span> <span class="o">=></span> <span class="s1">'benhamill'</span><span class="p">,</span> <span class="ss">:password</span> <span class="o">=></span> <span class="s1">'thisisnotmyrealpassword'</span>
</span><span class='line'>
</span><span class='line'><span class="k">class</span> <span class="nc">Alert</span>
</span><span class='line'> <span class="kp">include</span> <span class="ss">TiwtterAlert</span><span class="p">:</span><span class="ss">:Alert</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="n">alert</span> <span class="o">=</span> <span class="no">Alert</span><span class="o">.</span><span class="n">new</span> <span class="s1">'Very important message.'</span><span class="p">,</span> <span class="no">DateTime</span><span class="o">.</span><span class="n">now</span>
</span><span class='line'>
</span><span class='line'><span class="n">account</span><span class="o">.</span><span class="n">announce</span> <span class="n">alert</span>
</span></code></pre></td></tr></table></div></figure>
<p>In the wild, I don't imagine that your Alert class will be so simple. For instance, when I plug this into HeyGoVote, it'll be included in an ActiveRecord model so I can run a cron job that pulls out tweets that should go out today (based on the date) and sends them all.</p>
<p>I haven't plugged this into code yet, and note the version number 0.1. The tests pass, but they may not be comprehensive and I might have botched something up in my publishing, but it looks like everything's working to me. My next step is to start building up HeyGoVote and using twitter alert in it, which might reveal some needed features. In the meantime, I welcome feedback. Leave a comment here, or <a href="http://github.com/BenHamill/twitter_alert">fork it</a> and issue me a pull request, if you have an idea.</p>
</div>
<footer>
<p class="meta">
<span class="byline author vcard">Posted by <span class="fn">Ben Hamill</span></span>
<time datetime="2010-05-07T00:00:00-05:00" pubdate data-updated="true">May 7<span>th</span>, 2010</time>
</p>
<p class="no-comments meta">
There's not a comments section on this blog any more. If you<br>
want, tweet at me or write your own post and send me the link.
</p>
<div class="sharing">
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://garbled.benhamill.com/2010/05/07/my-first-ruby-gem/" data-via="benhamill" data-counturl="http://garbled.benhamill.com/2010/05/07/my-first-ruby-gem/" >Tweet</a>
</div>
<p class="meta">
<a class="basic-alignment left" href="/2010/05/06/final-post/" title="Previous Post: Final Post">« Final Post</a>
<a class="basic-alignment right" href="/2010/06/10/how-do-you-make-a-gem/" title="Next Post: How Do You Make a Gem?">How Do You Make a Gem? »</a>
</p>
</footer>
</article>
</div>
<aside class="sidebar">
<section>
<h1>About Me</h1>
<div id="twitter-profile">
<div id="author-card">
<img src="http://www.gravatar.com/avatar/4938b4569f1366168b705ce9c774ea5e" alt="Gravatar of Ben Hamill " title="Gravatar of Ben Hamill" />
<p id="name">Ben Hamill</p>
<p id="handle">@<a href="http://twitter.com/benhamill">benhamill</a></p>
<p id="liame">
<span id="obf"><script>document.getElementById("obf").innerHTML="<n uers=\"znvygb:ora@oraunzvyy.pbz\" gnetrg=\"_oynax\">ora@oraunzvyy.pbz</n>".replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});</script>
<noscript><span style="unicode-bidi:bidi-override;direction:rtl;">moc.llimahneb@neb</span></noscript></span>
</p>
</div>
<p>Rubyist, hacker, gamer (video, board, role-playing), fanboy (Linux, git, vim, Firefly, Dr Pepper), language pedant. Nerd.</p>
</div>
</section>
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/2013/11/12/hal-client-update-cetacean/">HAL Client Update: Cetacean</a>
</li>
<li class="post">
<a href="/2013/11/05/thinking-about-hal-clients/">Thinking About HAL Clients</a>
</li>
<li class="post">
<a href="/2013/09/18/bens-gem-maintainer-handbook/">Ben's Gem Maintainer Handbook</a>
</li>
<li class="post">
<a href="/2013/09/03/never-type-bundle-exec-again/">Never Type bundle exec Again</a>
</li>
<li class="post">
<a href="/2013/04/28/social-justice-is-made-of-empathy/">Social Justice is Made of Empathy</a>
</li>
</ul>
</section>
<section>
<h1>GitHub Repos</h1>
<ul id="gh_repos">
<li class="loading">Status updating...</li>
</ul>
<a href="https://github.com/benhamill">@benhamill</a> on GitHub
<script type="text/javascript">
$(document).ready(function(){
if (!window.jXHR){
var jxhr = document.createElement('script');
jxhr.type = 'text/javascript';
jxhr.src = '/javascripts/libs/jXHR.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(jxhr, s);
}
github.showRepos({
user: 'benhamill',
count: 5,
skip_forks: true,
target: '#gh_repos'
});
});
</script>
<script src="/javascripts/github.js" type="text/javascript"> </script>
</section>
</aside>
</div>
</div>
</div>
<footer role="contentinfo"><p>
Copyright © 2013 - Ben Hamill -
<span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
</p>
</footer>
<script type="text/javascript">
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>
</body>
</html>