<!DOCTYPE html>
<html lang="en-US">
<head profile="http://gmpg.org/xfn/11">
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>March, 2011 | SpiffyJr's Blogaroo</title>
  <link rel="stylesheet" href="/wp-content/themes/default/style.css" type="text/css" media="screen">
  <link rel="pingback" href="/xmlrpc.php">
  <style type="text/css" media="screen">

        #page { background: url("/wp-content/themes/default/images/kubrickbg-ltr.jpg") repeat-y top; border: none; }

  </style>
  <link rel="alternate" type="application/rss+xml" title="SpiffyJr's Blogaroo » Feed" href="/feed/">
  <link rel="alternate" type="application/rss+xml" title="SpiffyJr's Blogaroo » Comments Feed" href="/comments/feed/">
  <script type="text/javascript" src="/wp-includes/js/jquery/jquery.js?ver=1.10.2"></script>
  <script type="text/javascript" src="/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1"></script>
  <script type="text/javascript" src="/wp-content/plugins/google-analyticator/external-tracking.min.js?ver=6.4.5"></script>
  <link rel="EditURI" type="application/rsd+xml" title="RSD" href="/xmlrpc.php?rsd">
  <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="/wp-includes/wlwmanifest.xml">
  <script type="text/javascript" src="/wp-content/plugins/ald-transpose-email/ald-transpose-email.js"></script>
  <link rel="canonical" href="/2011/03/">
  <style type="text/css" id="syntaxhighlighteranchor"></style>
  
</head>
<body class="archive date">
  <div id="page">
    <div id="header" role="banner">
      <div id="headerimg">
        <h1><a href="/">SpiffyJr's Blogaroo</a></h1>
        <div class="description">
          Happenings of the man known as SpiffyJr
        </div>
      </div>
    </div>
    <hr>
    <div id="content" class="narrowcolumn" role="main">
      <h2 class="pagetitle">Archive for March, 2011</h2>
      <div class="navigation">
        <div class="alignleft"></div>
        <div class="alignright"></div>
      </div>
      <div class="post-393 post type-post status-publish format-standard hentry category-zend-framework">
        <h3 id="post-393">Formatting your API to work with dojox.data.JsonRestStore (#dojo)</h3>
<small>Wednesday, March 30th, 2011</small>
        <div class="entry">
          <p>Greetings! Long time no post, I know. I’ve been busy with <a title="PetWise" href="http://www.petwisewebsites.com/" target="_blank">PetWise</a> and  as well as the occasional game of Heroes of Newerth and/or WoW arenas. This little post will attempt to help those working with JsonRestStore (JRS) when their API doesn’t output exactly what JRS is expecting. What we’re going to be doing is extending dojox.data.JsonRestStore and creating our own store in its place while overriding the _processResults() method.</p>
          <p>The first thing you will want to do is <a title="Registering a Dojo ModulePath." href="http://dojotoolkit.org/reference-guide/dojo/registerModulePath.html" target="_blank">register a Dojo module path</a> so that Dojo knows exactly where to find your custom store. In my example, I’m going to be using Zend Framework so in my application.ini file I simply include a line like <em>resources.dojo.modulePaths.blitz = “/js/dojo/blitz”</em>. We’ll also want to be sure that we require the appropriate class when working with our new store. You can do this globally in the application.ini by adding <em>resources.dojo.requireModules[] = “blitz.data.JsonRestStore”</em> or by adding it to whatever page the store will be used in.</p>
          <p>Next, you’ll need to declare the class by creating the file. In my example, I create a file called <em>JsonRestStore.js</em> in <em>/js/dojo/blitz/data</em>.</p>
          <pre class="brush: jscript; title: ; notranslate" title="">
// /js/dojo/blitz/data/JsonRestStore.js

dojo.provide("blitz.data.JsonRestStore");
dojo.require("dojox.data.JsonRestStore");

// declare the store extending from JsonRestStore
dojo.declare("blitz.data.JsonRestStore", dojox.data.JsonRestStore, {
        // process results takes the results from getQuery and turns them into something the store can handle
        _processResults:function(results, deferred) {
                // custom format for blitz api
                results = results.result; // this simple line causes JsonRestStore to work with my own API implementation
                // index the results
                var count = results.length;
                // if we don't know the length, and it is partial result, we will guess that it is twice as big, that will work for most widgets
                return {totalCount:deferred.fullLength || (deferred.request.count == count ? (deferred.request.start || 0) + count * 2 : count), items: results};
        }
});
</pre>
          <p>Here’s a dump of my profiles API inside of Blitzaroo to show why this works. Notice that all the data comes from the result key which is why I have the line results = results.result. This allows me to include extra information about the request whenever the API is hit.</p>
          <pre class="brush: jscript; title: ; notranslate" title="">
{
  -request: {
    uri: "/api/profiles"
    format: "json"
    action: "list"
  }
  -result: [
    -{
      id: 1
      userId: 1
      name: "Igatchew"
      private: false
      -created: {
        date: "2011-03-25 15:50:20"
        timezone_type: 3
        timezone: "America/Chicago"
      }
    -updated: {
        date: "2011-03-25 15:50:22"
        timezone_type: 3
        timezone: "America/Chicago"
      }
    }
   -{
      id: 2
      userId: 1
      name: "Snaggins"
      private: true
      -created: {
        date: "2011-03-25 20:32:34"
        timezone_type: 3
        timezone: "America/Chicago"
      }
      -updated: {
        date: "2011-03-25 20:32:36"
        timezone_type: 3
        timezone: "America/Chicago"
      }
    }
  ]
}
</pre>
          <p>Hope that’s helpful!</p>
        </div>
        <p class="postmetadata">Posted in <a href="/category/technologies/zend-framework/" title="View all posts in Zend Framework" rel="category tag">Zend Framework</a> | No Comments »</p>
      </div>
      <div class="navigation">
        <div class="alignleft"></div>
        <div class="alignright"></div>
      </div>
    </div>
    <div id="sidebar" role="complementary">
      <ul>
        <li>
          
        </li>
        <li>
          <p>You are currently browsing the <a href="/">SpiffyJr's Blogaroo</a> blog archives for March, 2011.</p>
        </li>
      </ul>
      <ul role="navigation">
        <li class="pagenav">
          <h2>Pages</h2>
          <ul>
            <li class="page_item page-item-280 page_item_has_children">
              <a href="/about-2/">About</a>
              <ul class="children">
                <li class="page_item page-item-282">
                  <a href="/about-2/inspiration/">Inspiration</a>
                </li>
                <li class="page_item page-item-2">
                  <a href="/about-2/about/">Resume</a>
                </li>
              </ul>
            </li>
            <li class="page_item page-item-298 page_item_has_children">
              <a href="/projects/">Projects</a>
              <ul class="children">
                <li class="page_item page-item-299">
                  <a href="/projects/blitzaroo/">Blitzaroo</a>
                </li>
                <li class="page_item page-item-301">
                  <a href="/projects/phpraider/">phpRaider</a>
                </li>
                <li class="page_item page-item-303">
                  <a href="/projects/zend-calendar/">Zend Calendar</a>
                </li>
              </ul>
            </li>
            <li class="page_item page-item-267 page_item_has_children">
              <a href="/docs/">Docs</a>
              <ul class="children">
                <li class="page_item page-item-162">
                  <a href="/docs/b-api/">Blitzaroo API</a>
                </li>
                <li class="page_item page-item-103">
                  <a href="/docs/sc-docs/">SpiffyCalendar Docs</a>
                </li>
                <li class="page_item page-item-122">
                  <a href="/docs/sd-docs/">SpiffyDb Docs</a>
                </li>
              </ul>
            </li>
            <li class="page_item page-item-94">
              <a href="/downloads/">Downloads</a>
            </li>
            <li class="page_item page-item-260 page_item_has_children">
              <a href="/technologies/">Technologies</a>
              <ul class="children">
                <li class="page_item page-item-277">
                  <a href="/technologies/doctrine-orm/">Doctrine ORM</a>
                </li>
                <li class="page_item page-item-262">
                  <a href="/technologies/dojo/">Dojo</a>
                </li>
                <li class="page_item page-item-264">
                  <a href="/technologies/php/">PHP</a>
                </li>
                <li class="page_item page-item-275">
                  <a href="/technologies/zend-framework/">Zend Framework</a>
                </li>
              </ul>
            </li>
            <li class="page_item page-item-295 page_item_has_children">
              <a href="/other/">Other</a>
              <ul class="children">
                <li class="page_item page-item-96">
                  <a href="/other/license/">License</a>
                </li>
              </ul>
            </li>
          </ul>
        </li>
        <li>
          <h2>Archives</h2>
          <ul>
            <li>
              <a href="/2013/08/">August 2013</a>
            </li>
            <li>
              <a href="/2012/06/">June 2012</a>
            </li>
            <li>
              <a href="/2011/12/">December 2011</a>
            </li>
            <li>
              <a href="/2011/11/">November 2011</a>
            </li>
            <li>
              <a href="/2011/07/">July 2011</a>
            </li>
            <li>
              <a href="/2011/04/">April 2011</a>
            </li>
            <li>
              <a href="/2011/03/">March 2011</a>
            </li>
            <li>
              <a href="/2010/12/">December 2010</a>
            </li>
            <li>
              <a href="/2010/11/">November 2010</a>
            </li>
            <li>
              <a href="/2010/10/">October 2010</a>
            </li>
            <li>
              <a href="/2010/03/">March 2010</a>
            </li>
            <li>
              <a href="/2010/02/">February 2010</a>
            </li>
            <li>
              <a href="/2009/11/">November 2009</a>
            </li>
            <li>
              <a href="/2009/10/">October 2009</a>
            </li>
            <li>
              <a href="/2009/09/">September 2009</a>
            </li>
          </ul>
        </li>
        <li class="categories">
          <h2>Categories</h2>
          <ul>
            <li class="cat-item cat-item-36">
              <a href="/category/other/" title="Blogs that don't really fit anywhere else.">Other</a> (11)
              <ul class="children">
                <li class="cat-item cat-item-1">
                  <a href="/category/other/random/" title="View all posts filed under Random">Random</a> (11)
                </li>
              </ul>
            </li>
            <li class="cat-item cat-item-4">
              <a href="/category/projects/" title="View all posts filed under Projects">Projects</a> (25)
              <ul class="children">
                <li class="cat-item cat-item-5">
                  <a href="/category/projects/blitzaroo/" title="View all posts filed under Blitzaroo">Blitzaroo</a> (15)
                </li>
                <li class="cat-item cat-item-3">
                  <a href="/category/projects/phpraider/" title="View all posts filed under phpRaider">phpRaider</a> (1)
                </li>
                <li class="cat-item cat-item-11">
                  <a href="/category/projects/spiffydb/" title="View all posts filed under SpiffyDb">SpiffyDb</a> (3)
                </li>
                <li class="cat-item cat-item-46">
                  <a href="/category/projects/view-helpers/" title="View all posts filed under View Helpers">View Helpers</a> (3)
                </li>
                <li class="cat-item cat-item-10">
                  <a href="/category/projects/zend-calendar/" title="Progress on the former Spiffy Calendar and the proposal of Zend Calendar.">Zend Calendar</a> (5)
                </li>
              </ul>
            </li>
            <li class="cat-item cat-item-37">
              <a href="/category/spiffyjr/" title="Blogs about and pertaining to SpiffyJr.">SpiffyJr</a> (1)
            </li>
            <li class="cat-item cat-item-35">
              <a href="/category/technologies/" title="Blogs on the technologies I use everyday.">Technologies</a> (16)
              <ul class="children">
                <li class="cat-item cat-item-21">
                  <a href="/category/technologies/dojo/" title="View all posts filed under Dojo">Dojo</a> (6)
                </li>
                <li class="cat-item cat-item-38">
                  <a href="/category/technologies/php-technologies/" title="View all posts filed under PHP">PHP</a> (3)
                </li>
                <li class="cat-item cat-item-6">
                  <a href="/category/technologies/zend-framework/" title="View all posts filed under Zend Framework">Zend Framework</a> (12)
                </li>
              </ul>
            </li>
          </ul>
        </li>
      </ul>
      <ul></ul>
    </div>
    <hr>
    <div id="footer" role="contentinfo">
      <p>SpiffyJr's Blogaroo is proudly powered by <a href="http://wordpress.org/">WordPress</a>. .<br>
      Entries (RSS) and Comments (RSS).</p>
    </div>
  </div>
  <script type="text/javascript" src="/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shCore.js?ver=3.0.83c"></script> 
  <script type="text/javascript" src="/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shBrushJScript.js?ver=3.0.83c"></script> 
  <script type="text/javascript">


        (function(){
                var corecss = document.createElement('link');
                var themecss = document.createElement('link');
                var corecssurl = "https://spiffyjr.me/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shCore.css?ver=3.0.83c";
                if ( corecss.setAttribute ) {
                                corecss.setAttribute( "rel", "stylesheet" );
                                corecss.setAttribute( "type", "text/css" );
                                corecss.setAttribute( "href", corecssurl );
                } else {
                                corecss.rel = "stylesheet";
                                corecss.href = corecssurl;
                }
                document.getElementsByTagName("head")[0].insertBefore( corecss, document.getElementById("syntaxhighlighteranchor") );
                var themecssurl = "https://spiffyjr.me/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shThemeDefault.css?ver=3.0.83c";
                if ( themecss.setAttribute ) {
                                themecss.setAttribute( "rel", "stylesheet" );
                                themecss.setAttribute( "type", "text/css" );
                                themecss.setAttribute( "href", themecssurl );
                } else {
                                themecss.rel = "stylesheet";
                                themecss.href = themecssurl;
                }
                //document.getElementById("syntaxhighlighteranchor").appendChild(themecss);
                document.getElementsByTagName("head")[0].insertBefore( themecss, document.getElementById("syntaxhighlighteranchor") );
        })();
        SyntaxHighlighter.config.strings.expandSource = '+ expand source';
        SyntaxHighlighter.config.strings.help = '?';
        SyntaxHighlighter.config.strings.alert = 'SyntaxHighlighter\n\n';
        SyntaxHighlighter.config.strings.noBrush = 'Can\'t find brush for: ';
        SyntaxHighlighter.config.strings.brushNotHtmlScript = 'Brush wasn\'t configured for html-script option: ';
        SyntaxHighlighter.defaults['pad-line-numbers'] = false;
        SyntaxHighlighter.defaults['tab-size'] = 2;
        SyntaxHighlighter.all();
  </script>
</body>
</html>
