vumi_ureport.api = function() {
    var _ = require('underscore');

    var vumigo = require('vumigo_v02');
    var utils = vumigo.utils;
    var Extendable = utils.Extendable;

    var JsonApi = vumigo.http.api.JsonApi;
    var HttpResponseError = vumigo.http.api.HttpResponseError;

    var UReportApi = Extendable.extend(function(self, im, url, backend, opts) {
        opts = opts || {};

        self.im = im;
        self.http = new JsonApi(im, {auth: opts.auth});
        self.base_url = url;
        self.backend = backend;

        self.url = function(path) {
            return join_paths(self.base_url, path);
        };

        self.ureporters = function(user_addr) {
            var rel_path = join_paths('ureporters', self.backend, user_addr);
            return new UReportersApi(self, rel_path);
        };
    });

    var UReportersApi = Extendable.extend(function(self, api, rel_path) {
        self.api = api;
        self.rel_path = rel_path;

        self.url = function(path) {
            return self.api.url(join_paths(self.rel_path, path));
        };

        self.get = function() {
            return self
                .api.http.get(self.url())
                .get('data')
                .get('user')
                .catch(catch_code(404, null));
        };

        self.polls = {};

        self.polls._current = function() {
            return self
                .api.http.get(self.url('polls/current'))
                .get('data')
                .get('poll');
        };

        self.polls._concat = function(poll_a, poll_b) {
            poll_b.question = [poll_a.question, poll_b.question].join(' ');
            return poll_b;
        };

        self.polls.current = function(options) {
            options = _(options || {}).defaults({
                nones: {
                    limit: 1,
                    use: false,
                    concat: false
                }
            });

            var n = options.nones.limit;
            var nones = [];

            function next() {
                return self.polls._current().then(function(poll) {
                    if (!n-- || poll.type !== 'none' || options.nones.use) {
                        return options.nones.concat
                            ? nones.concat([poll]).reduce(self.polls._concat)
                            : poll;
                    }
                    else {
                        nones.push(poll);
                        return next();
                    }
                });
            }

            return next();
        };

        self.polls.topics = function() {
            return self
                .api.http.get(self.url('polls/topics'))
                .get('data')
                .get('poll_topics');
        };

        self.poll = function(id) {
            return new PollApi(self, join_paths('poll', id));
        };

        self.reports = {};
        self.reports.submit = function(report) {
            return self
                .api.http.post(self.url('reports/'), {
                    data: {report: report}
                })
                .get('data')
                .get('result');
        };
    });

    var PollApi = Extendable.extend(function(self, ureporter, rel_path) {
        self.api = ureporter.api;
        self.ureporter = ureporter;
        self.rel_path = rel_path;

        self.url = function(path) {
            return self.ureporter.url(join_paths(self.rel_path, path));
        };

        self.responses = {};

        self.responses.submit = function(response) {
            return self
                .api.http.post(self.url('responses/'), {
                    data: {response: response}
                })
                .get('data')
                .get('result');
        };

        self.summary = function() {
            return self
                .api.http.get(self.url('summary'))
                .get('data')
                .get('poll_result');
        };
    });

    function catch_code(code, result) {
        return function(e) {
            var match = e instanceof HttpResponseError
                     && e.response.code === code;

            if (!match) {
                throw e;
            }

            return utils.maybe_call(result);
        };
    }

    function join_paths() {
        return Array.prototype.filter.call(arguments, function(path) {
            return !!path;
        }).join('/');
    }

    return {
        UReportApi: UReportApi,
        UReportersApi: UReportersApi,
        PollApi: PollApi
    };
}();

@@ -1721,19 +1721,16 @@
 tion(opt
-ion
 s) %7B%0A   
@@ -1741,19 +1741,16 @@
      opt
-ion
 s = _(op
@@ -1750,19 +1750,16 @@
  = _(opt
-ion
 s %7C%7C %7B%7D)
@@ -1769,16 +1769,28 @@
 faults(%7B
+nones: %7B%7D%7D);
 %0A       
@@ -1798,25 +1798,33 @@
     
-    nones: %7B%0A    
+_(opts.nones).defaults(%7B%0A
     
@@ -1861,20 +1861,16 @@
         
-    
 use: fal
@@ -1873,20 +1873,16 @@
  false,%0A
-    
         
@@ -1903,34 +1903,16 @@
 : false%0A
-                %7D%0A
         
@@ -1939,27 +1939,24 @@
  var n = opt
-ion
 s.nones.limi
@@ -2113,11 +2113,13 @@
 f (!
+(
 n--
+)
  %7C%7C 
@@ -2141,27 +2141,24 @@
 none' %7C%7C opt
-ion
 s.nones.use)
@@ -2194,19 +2194,16 @@
 turn opt
-ion
 s.nones.

Rename options -> opts in UReportApi.polls.current