<?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>Mandarin Soda &#187; datamapper</title>
	<atom:link href="http://mandarinsoda.com/category/datamapper/feed/" rel="self" type="application/rss+xml" />
	<link>http://mandarinsoda.com</link>
	<description>Random Musings, Sometimes Programming.</description>
	<lastBuildDate>Fri, 12 Jun 2009 02:28:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>DataMapper Adapter for Netflix</title>
		<link>http://mandarinsoda.com/2008/10/09/datamapper-adapter-for-netflix/</link>
		<comments>http://mandarinsoda.com/2008/10/09/datamapper-adapter-for-netflix/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 19:03:28 +0000</pubDate>
		<dc:creator>Matt Carlson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[datamapper]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://mandarinsoda.com/?p=202</guid>
		<description><![CDATA[I&#8217;ve apparently caught the DM Adapter bug, as I&#8217;ve decided to write one to access Netflix while I finish up my MailChimp adapter. I&#8217;ll be posting as I go along, as I&#8217;ve been learning quite a bit about the inner workings of DataMapper while going through this process. Cheers.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve apparently caught the <a href="http://datamapper.rubyforge.org/DataMapper/Adapters/">DM Adapter</a> bug, as I&#8217;ve decided to write <a href="http://github.com/mandarinsoda/datamapper-netflix-adapter/tree/master">one to access Netflix</a> while I finish up my MailChimp adapter. </p>
<p>I&#8217;ll be posting as I go along, as I&#8217;ve been learning quite a bit about the inner workings of DataMapper while going through this process.  </p>
<p>Cheers.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F09%2Fdatamapper-adapter-for-netflix%2F&amp;title=DataMapper+Adapter+for+Netflix" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F09%2Fdatamapper-adapter-for-netflix%2F&amp;title=DataMapper+Adapter+for+Netflix" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F09%2Fdatamapper-adapter-for-netflix%2F&amp;title=DataMapper+Adapter+for+Netflix" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F09%2Fdatamapper-adapter-for-netflix%2F&amp;title=DataMapper+Adapter+for+Netflix" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F09%2Fdatamapper-adapter-for-netflix%2F&amp;title=DataMapper+Adapter+for+Netflix', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F09%2Fdatamapper-adapter-for-netflix%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F09%2Fdatamapper-adapter-for-netflix%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F09%2Fdatamapper-adapter-for-netflix%2F&amp;title=DataMapper+Adapter+for+Netflix" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F09%2Fdatamapper-adapter-for-netflix%2F&amp;title=DataMapper+Adapter+for+Netflix" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://mandarinsoda.com/2008/10/09/datamapper-adapter-for-netflix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a DataMapper Adapter to Access MailChimp Web Services From Merb</title>
		<link>http://mandarinsoda.com/2008/10/03/writing-a-datamapper-adapter-to-access-mailchimp-web-services/</link>
		<comments>http://mandarinsoda.com/2008/10/03/writing-a-datamapper-adapter-to-access-mailchimp-web-services/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 20:52:31 +0000</pubDate>
		<dc:creator>Matt Carlson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[datamapper]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[MailChimp]]></category>

		<guid isPermaLink="false">http://mandarinsoda.com/?p=186</guid>
		<description><![CDATA[As I mentioned in my last post, I&#8217;ve started looking into writing DataMapper Adapters, using my MailChimp wrapper as an example. Thus far, I&#8217;ve been pretty impressed with the Adapter layer built into DataMapper and the possibilities this abstraction layer provides. A quick search over at GitHub will show you all the interesting things folks [...]]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my last post, I&#8217;ve started looking into writing DataMapper Adapters, using my <a href="http://github.com/mandarinsoda/datamapper-mailchimp-adapter/tree/master">MailChimp wrapper as an example</a>.  Thus far, I&#8217;ve been pretty impressed with the Adapter layer built into DataMapper and the possibilities this abstraction layer provides.  A <a href="http://github.com/search?q=datamapper+adapter">quick search over at GitHub</a> will show you all the interesting things folks are doing with adapters.   </p>
<p>Anyway, here&#8217;s a synopsis of what I&#8217;ve come across thus far.  As pointed out <a href="http://merbist.com/2008/09/29/write-your-own-custom-datamapper-adapter/">in this post</a> by The Merbist, a custom adapter simply inherits from <a href="http://github.com/sam/dm-core/tree/master/lib/dm-core/adapters/abstract_adapter.rb">Abstract Adapter</a> and as such, can define a number of default Adapter methods such as create, update, delete, read_one and read_many.  You also have access to an initialization method that supplies a hash with important environment information, including any parameters relevant to your adapter that a user may have setup in a database.yml file.  This allowed me to create a MailChimp client and login <a href="http://github.com/mandarinsoda/datamapper-mailchimp-adapter/tree/master/lib/dm-mailchimp-adapter.rb#L15-20">once during class initialization</a> rather than at every request, so I got that going for me.</p>
<p>Once I had a MailChimp client setup with login information, I started getting create working in my adapter.  The create method takes a collection of resources as an option which I simply loop through and call the MailChimp listSubscribe API.  So far, so good.  I now wanted to test whether any of this would work with Merb.</p>
<p>I created a merb app:</p>
<pre>
<code>
 merb-gen app campaign
 cd campaign
</code>
</pre>
<p>and set the :use_orm parameter to datamapper in the Merb init.rb.</p>
<p>Next, I ran <code>rake dm:db:database_yaml</code> in order to generate a database.yml file to specify relevant properties for my adapter.  In my case, I needed to create an entry for my mailchimp adapter:</p>
<pre>
<code>
  adapter:  mailchimp
  database:
  username: user
  password: password
  mailing_list_id: list_id
  host: localhost
</code>
</pre>
<p>.</p>
<p>I next created a resource to test the adapter with by running <code>merb-gen resource mailings</code>.  My thinking was that one could have a User stored in a relational (or other) datastore, and that User can have many mailings or some such thing, bad naming aside.  Anyway, a cool feature of DataMapper is that you can specify any number of repositories in a database.yml with different adapters, and then specify on a resource by resource basis which repository a resource belongs to like so:</p>
<pre>
<code>
 def self.default_repository_name
      :mysql
 end
</code>
</pre>
<p>After generating my resource, I went in to add the properties MailChimp would require for the create method.  </p>
<pre>
<code>
class Mailings
  include DataMapper::Resource

  property :id, String, :serial => true, :key => true, :field => :_id
  property :first_name, String
  property :last_name, String
  property :email, String
  property :mailing_list_id, String

   def build_mail_merge()
      {"EMAIL" => self.email, "FNAME" => self.first_name, "LNAME" => self.last_name }
   end
end
</code>
</pre>
<p>.</p>
<p>I also added a callback method that is used by the adapter in order to pass mail merge arguments to MailChimp.  This seemed like a sane approach given that the MailChimp mail_merge arguments are quite dynamic.</p>
<p>With a resource firmly in place, I fired up the merb console and tested to see whether I could connect to MailChimp with it.</p>
<pre>
<code>
 m = Mailing.new
 m.first_name = 'mandarin'
 m.last_name = 'soda'
 m.email = 'msoda@disney.com'
 m.mailing_list_id = '9'
 m.create
</code>
</pre>
<p>I checked my disney email, and sure enough, I had an opt-in response from MailChimp. Victory Adapter!  I could sign users up to MailChimp via the DataMapper APIs quite quickly&#8230;.not too shabby.</p>
<p>That&#8217;s where I&#8217;m at for now&#8230;still have some things to iron out, one being that DataMapper is returning false after a successful create.  Others, of course being that I need to figure out the rest of the default Adapter methods.  Feel free to follow on GitHub if you feel so inclined.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F03%2Fwriting-a-datamapper-adapter-to-access-mailchimp-web-services%2F&amp;title=Writing+a+DataMapper+Adapter+to+Access+MailChimp+Web+Services+From+Merb" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F03%2Fwriting-a-datamapper-adapter-to-access-mailchimp-web-services%2F&amp;title=Writing+a+DataMapper+Adapter+to+Access+MailChimp+Web+Services+From+Merb" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F03%2Fwriting-a-datamapper-adapter-to-access-mailchimp-web-services%2F&amp;title=Writing+a+DataMapper+Adapter+to+Access+MailChimp+Web+Services+From+Merb" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F03%2Fwriting-a-datamapper-adapter-to-access-mailchimp-web-services%2F&amp;title=Writing+a+DataMapper+Adapter+to+Access+MailChimp+Web+Services+From+Merb" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F03%2Fwriting-a-datamapper-adapter-to-access-mailchimp-web-services%2F&amp;title=Writing+a+DataMapper+Adapter+to+Access+MailChimp+Web+Services+From+Merb', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F03%2Fwriting-a-datamapper-adapter-to-access-mailchimp-web-services%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F03%2Fwriting-a-datamapper-adapter-to-access-mailchimp-web-services%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F03%2Fwriting-a-datamapper-adapter-to-access-mailchimp-web-services%2F&amp;title=Writing+a+DataMapper+Adapter+to+Access+MailChimp+Web+Services+From+Merb" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F03%2Fwriting-a-datamapper-adapter-to-access-mailchimp-web-services%2F&amp;title=Writing+a+DataMapper+Adapter+to+Access+MailChimp+Web+Services+From+Merb" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://mandarinsoda.com/2008/10/03/writing-a-datamapper-adapter-to-access-mailchimp-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
