<?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; ruby</title>
	<atom:link href="http://mandarinsoda.com/category/ruby/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>Accessing FedEx Web Services From Ruby/Rails</title>
		<link>http://mandarinsoda.com/2009/02/09/accessing-fedex-web-services-from-rubyrails/</link>
		<comments>http://mandarinsoda.com/2009/02/09/accessing-fedex-web-services-from-rubyrails/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 21:45:17 +0000</pubDate>
		<dc:creator>Matt Carlson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[miscellaneous]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Shipping]]></category>

		<guid isPermaLink="false">http://mandarinsoda.com/?p=224</guid>
		<description><![CDATA[I recently played around with adding FedEx shipping services to the active_shipping plugin and found a bit of confusion online in regards to how to hit FedEx depending upon the style of service being exposed. Somewhat confusingly, FedEx has non-SOAP services as well as SOAP services that you can hit restfully in an HTTPS Post. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently played around with adding FedEx shipping services to the <a href="http://github.com/Shopify/active_shipping/tree/master">active_shipping</a> plugin and found a bit of confusion online in regards to how to hit FedEx depending upon the style of service being exposed.  Somewhat confusingly, FedEx has non-SOAP services as well as SOAP services that you can hit restfully in an HTTPS Post.  For the SOAP service, FedEx has very specific requirements about how to formulate the payload and HTTP headers that took a bit of tinkering to get working.  Non-SOAP FedEx support was recently added to active_shipping prior to the completion of my work, but I figured I would post if for those who want to use what I think are newer SOAP services.</p>
<p>Without much further ado, here are the basics for creating a tracking request:</p>
<pre>
<code>
TEST_DOMAIN = 'gatewaybeta.fedex.com'

def find_tracking_info(tracking_number, options={})
        options = @options.update(options)
        tracking_request = build_tracking_request(tracking_number, options)
        response = commit(:track, save_request(tracking_request),
                          (options[:test] || false))
        parse_tracking_response(response, options)
  end

protected
   def build_access_request
        xml_request = XmlNode.new('ns:WebAuthenticationDetail') do |access|
          access << XmlNode.new('ns:UserCredential') do |user|
             user << XmlNode.new('ns:Key', @options[:key])
             user << XmlNode.new('ns:Password', @options[:password])
          end
        end
        xml_request
      end

      def build_client_detail
        xml_request = XmlNode.new('ns:ClientDetail') do |client_detail|
          client_detail << XmlNode.new('ns:AccountNumber', @options[:account])
          client_detail << XmlNode.new('ns:MeterNumber', @options[:meter])
        end
        xml_request
      end

     def build_tracking_request(tracking_number, options={})
        xml_request = XmlNode.new('ns:TrackRequest',
                         :'xmlns:ns'=>"http://fedex.com/ws/track/v2",
                         :'xmlns:xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
                         :'xsi:schemaLocation'=>"http://fedex.com/ws/track/v2") do |root_node|
          root_node << build_access_request
          root_node << build_client_detail
          root_node << XmlNode.new('ns:TransactionDetail') do |detail|
            detail << XmlNode.new('ns:CustomerTransactionId', 'Ground Track')
          end
          root_node <<  XmlNode.new('ns:Version') do |version|
            version << XmlNode.new('ns:ServiceId', 'trck')
            version << XmlNode.new('ns:Major', '2')
            version << XmlNode.new('ns:Intermediate', '0')
            version << XmlNode.new('ns:Minor', '0')
          end
           root_node <<  XmlNode.new('ns:PackageIdentifier') do |package|
              package << XmlNode.new('ns:Value', tracking_number.to_s)
              package << XmlNode.new('ns:Type', "TRACKING_NUMBER_OR_DOORTAG")
          end
        end
        xml_request.to_xml
      end

     def commit(action, request, test = false)
        http = Net::HTTP.new((test ? TEST_DOMAIN : LIVE_DOMAIN),
                                (USE_SSL[action] ? 443 : 80 ))
        http.use_ssl = USE_SSL[action]

        headers = {
          'Referer' => 'me',
          'Port' => '443',
          'Accept' => "image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */*",
          'Content-Type' => 'image/gif'
        }

        http.verify_mode = OpenSSL::SSL::VERIFY_NONE if USE_SSL[action]
        response = http.start do |http|
          http.request_post ('/xml', request, headers)
        end
        response.body
      end
</pre>
<p></code></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fmandarinsoda.com%2F2009%2F02%2F09%2Faccessing-fedex-web-services-from-rubyrails%2F&amp;title=Accessing+FedEx+Web+Services+From+Ruby%2FRails" 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%2F2009%2F02%2F09%2Faccessing-fedex-web-services-from-rubyrails%2F&amp;title=Accessing+FedEx+Web+Services+From+Ruby%2FRails" 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%2F2009%2F02%2F09%2Faccessing-fedex-web-services-from-rubyrails%2F&amp;title=Accessing+FedEx+Web+Services+From+Ruby%2FRails" 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%2F2009%2F02%2F09%2Faccessing-fedex-web-services-from-rubyrails%2F&amp;title=Accessing+FedEx+Web+Services+From+Ruby%2FRails" 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%2F2009%2F02%2F09%2Faccessing-fedex-web-services-from-rubyrails%2F&amp;title=Accessing+FedEx+Web+Services+From+Ruby%2FRails', '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%2F2009%2F02%2F09%2Faccessing-fedex-web-services-from-rubyrails%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%2F2009%2F02%2F09%2Faccessing-fedex-web-services-from-rubyrails%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%2F2009%2F02%2F09%2Faccessing-fedex-web-services-from-rubyrails%2F&amp;title=Accessing+FedEx+Web+Services+From+Ruby%2FRails" 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%2F2009%2F02%2F09%2Faccessing-fedex-web-services-from-rubyrails%2F&amp;title=Accessing+FedEx+Web+Services+From+Ruby%2FRails" 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/2009/02/09/accessing-fedex-web-services-from-rubyrails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lightweight Ruby Web Services</title>
		<link>http://mandarinsoda.com/2008/12/09/lightweight-ruby-web-services/</link>
		<comments>http://mandarinsoda.com/2008/12/09/lightweight-ruby-web-services/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 02:04:43 +0000</pubDate>
		<dc:creator>Matt Carlson</dc:creator>
				<category><![CDATA[Book Reviews]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[miscellaneous]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://mandarinsoda.com/?p=220</guid>
		<description><![CDATA[The recent Oreilly book Enterprise Rails has a few chapters on SOA and the entire time I was reading those chapters I kept thinking to myself that Rails is sorta overkill for most services implementations, unless you plan on bundling APIs and applications together. I was going to write something about translating the services discussed [...]]]></description>
			<content:encoded><![CDATA[<p>The recent Oreilly book <a href="http://oreilly.com/catalog/9780596515201/">Enterprise Rails</a> has a few chapters on SOA and the entire time I was reading those chapters I kept thinking to myself that Rails is sorta overkill for most services implementations, unless you plan on bundling APIs and applications together.  I was going to write something about translating the services discussed in that book to <a href="http://merbivore.com/">Merb</a> micro apps or something similar, but a few recent posts beat me to the punch.  Enjoy:</p>
<p><a href="http://www.slideshare.net/adamwiggins/lightweight-webservices-with-sinatra-and-restclient-presentation?type=powerpoint ">Web Services With Sinatra</a>.</p>
<p><a href="http://advent2008.hackruby.com/past/2008/12/6/soa_with_merb/">SOA with Merb?</a>.</p>
<p>Throw in a little <a href="http://railstips.org/2008/11/17/happymapper-making-xml-fun-again">Happy Mapper</a> and you sort of have the equivalent of Restlet/Jersey and Castor/Jibx in the Java world.  Enterprise indeed.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F12%2F09%2Flightweight-ruby-web-services%2F&amp;title=Lightweight+Ruby+Web+Services" 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%2F12%2F09%2Flightweight-ruby-web-services%2F&amp;title=Lightweight+Ruby+Web+Services" 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%2F12%2F09%2Flightweight-ruby-web-services%2F&amp;title=Lightweight+Ruby+Web+Services" 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%2F12%2F09%2Flightweight-ruby-web-services%2F&amp;title=Lightweight+Ruby+Web+Services" 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%2F12%2F09%2Flightweight-ruby-web-services%2F&amp;title=Lightweight+Ruby+Web+Services', '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%2F12%2F09%2Flightweight-ruby-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%2F12%2F09%2Flightweight-ruby-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%2F12%2F09%2Flightweight-ruby-web-services%2F&amp;title=Lightweight+Ruby+Web+Services" 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%2F12%2F09%2Flightweight-ruby-web-services%2F&amp;title=Lightweight+Ruby+Web+Services" 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/12/09/lightweight-ruby-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Netflix API Authentication with the Ruby Oauth Gem</title>
		<link>http://mandarinsoda.com/2008/10/19/netflix-authentication-with-ruby-oauth/</link>
		<comments>http://mandarinsoda.com/2008/10/19/netflix-authentication-with-ruby-oauth/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 00:24:16 +0000</pubDate>
		<dc:creator>Matt Carlson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://mandarinsoda.com/?p=204</guid>
		<description><![CDATA[For any folks out there struggling to get the Ruby OAuth gem working with Netflix authentication, here&#8217;s a quick run down on how to get started. The 0.2.7 version of Ruby OAuth isn&#8217;t totally compatible with the Netflix authentication APIs. However, thanks to the grooviness that it is GitHub, Rob Ares graciously forked the OAuth [...]]]></description>
			<content:encoded><![CDATA[<p>For any folks out there struggling to get the Ruby OAuth gem working with Netflix authentication, here&#8217;s a quick run down on how to get started.</p>
<p>The 0.2.7 version of Ruby OAuth isn&#8217;t totally compatible with the Netflix authentication APIs.  However, thanks to the grooviness that it is <a href="http://github.com/">GitHub</a>, <a href="http://github.com/rares/oauth/tree/master">Rob Ares</a> graciously forked the OAuth gem in order to get it working.  So clone his repository and get cracking!  </p>
<p>Here&#8217;s a start:</p>
<pre>
<code>
require "oauth/consumer"
consumer = OAuth::Consumer.new(
      "developer api key",
      "developer api secret",
      {
        :site => "http://api.netflix.com",
        :request_token_url => "https://api-user.netflix.com/oauth/request_token",
        :access_token_url => "http://api.netflix.com/oauth/access_token",
        :authorize_url => "https://api-user.netflix.com/oauth/login"
      })

    request_token = consumer.get_request_token  

 request_token.authorize_url({
      <img src='http://mandarinsoda.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> auth_consumer_key => "you developer api key",
      :application_name => "application name",
      <img src='http://mandarinsoda.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> auth_callback => "optional"
    })

    access_token = request_token.get_access_token

    response = consumer.request(
      :get,
      "/users/#{access_token.response[:user_id]}",
      access_token,
      {:scheme => :query_string})
</pre>
<p></code></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F10%2F19%2Fnetflix-authentication-with-ruby-oauth%2F&amp;title=Netflix+API+Authentication+with+the+Ruby+Oauth+Gem" 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%2F19%2Fnetflix-authentication-with-ruby-oauth%2F&amp;title=Netflix+API+Authentication+with+the+Ruby+Oauth+Gem" 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%2F19%2Fnetflix-authentication-with-ruby-oauth%2F&amp;title=Netflix+API+Authentication+with+the+Ruby+Oauth+Gem" 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%2F19%2Fnetflix-authentication-with-ruby-oauth%2F&amp;title=Netflix+API+Authentication+with+the+Ruby+Oauth+Gem" 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%2F19%2Fnetflix-authentication-with-ruby-oauth%2F&amp;title=Netflix+API+Authentication+with+the+Ruby+Oauth+Gem', '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%2F19%2Fnetflix-authentication-with-ruby-oauth%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%2F19%2Fnetflix-authentication-with-ruby-oauth%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%2F19%2Fnetflix-authentication-with-ruby-oauth%2F&amp;title=Netflix+API+Authentication+with+the+Ruby+Oauth+Gem" 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%2F19%2Fnetflix-authentication-with-ruby-oauth%2F&amp;title=Netflix+API+Authentication+with+the+Ruby+Oauth+Gem" 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/19/netflix-authentication-with-ruby-oauth/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>
		<item>
		<title>DataMapper Adapter for MailChimp</title>
		<link>http://mandarinsoda.com/2008/09/29/datamapper-adapter-for-mailchimp/</link>
		<comments>http://mandarinsoda.com/2008/09/29/datamapper-adapter-for-mailchimp/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 00:53:38 +0000</pubDate>
		<dc:creator>Matt Carlson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[datamapper]]></category>
		<category><![CDATA[MailChimp]]></category>

		<guid isPermaLink="false">http://mandarinsoda.com/?p=181</guid>
		<description><![CDATA[Inspired by this post by The Merbist, I&#8217;ve decided to begin writing a Datamapper Adapter for MailChimp as a follow up to my post about creating a Merb web service. Look here for updates. Just an empty shell at the moment, but I&#8217;ll remedy that shortly.]]></description>
			<content:encoded><![CDATA[<p>Inspired by <a href="http://merbist.com/2008/09/29/write-your-own-custom-datamapper-adapter/">this post</a> by <a href="http://merbist.com/">The Merbist</a>, I&#8217;ve decided to begin writing a Datamapper Adapter for MailChimp as a follow up to my post about creating a Merb web service.  Look <a href="http://github.com/mandarinsoda/datamapper-mailchimp-adapter/tree/master">here</a> for updates.  Just an empty shell at the moment, but I&#8217;ll remedy that shortly.  </p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fmandarinsoda.com%2F2008%2F09%2F29%2Fdatamapper-adapter-for-mailchimp%2F&amp;title=DataMapper+Adapter+for+MailChimp" 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%2F09%2F29%2Fdatamapper-adapter-for-mailchimp%2F&amp;title=DataMapper+Adapter+for+MailChimp" 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%2F09%2F29%2Fdatamapper-adapter-for-mailchimp%2F&amp;title=DataMapper+Adapter+for+MailChimp" 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%2F09%2F29%2Fdatamapper-adapter-for-mailchimp%2F&amp;title=DataMapper+Adapter+for+MailChimp" 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%2F09%2F29%2Fdatamapper-adapter-for-mailchimp%2F&amp;title=DataMapper+Adapter+for+MailChimp', '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%2F09%2F29%2Fdatamapper-adapter-for-mailchimp%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%2F09%2F29%2Fdatamapper-adapter-for-mailchimp%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%2F09%2F29%2Fdatamapper-adapter-for-mailchimp%2F&amp;title=DataMapper+Adapter+for+MailChimp" 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%2F09%2F29%2Fdatamapper-adapter-for-mailchimp%2F&amp;title=DataMapper+Adapter+for+MailChimp" 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/09/29/datamapper-adapter-for-mailchimp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
