text: // Generated by CoffeeScript 1.10.0
  (function() {
    var DomoClient, request;
  
    request = require('request');
  
    DomoClient = (function() {
      function DomoClient(options) {
        var ref, ref1, ref2, ref3;
        if (options == null) {
          options = {};
        }
        this.clientId = (ref = options.clientId) != null ? ref : null;
        this.clientSecret = (ref1 = options.clientSecret) != null ? ref1 : null;
        this.accessToken = (ref2 = options.accessToken) != null ? ref2 : null;
        this.scope = (ref3 = options.scope) != null ? ref3 : null;
      }
  
      DomoClient.prototype.getToken = function(options, callback) {
        var ref, req;
        if (options == null) {
          options = {};
        }
        if (options.clientId != null) {
          this.clientId = clientId;
        }
        if (options.clientSecret != null) {
          this.clientSecret = clientSecret;
        }
        req = {
          method: 'GET',
          uri: 'https://api.domo.com/oauth/token',
          qs: {
            grant_type: 'client_credentials',
            scope: (ref = options.scope) != null ? ref : this.scope
          },
          auth: {
            user: this.clientId,
            pass: this.clientSecret
          }
        };
        return this.request(req, (function(_this) {
          return function(error, response, body) {
            if (error) {
              return callback(error, response, body);
            }
            if ((body != null ? body.access_token : void 0) != null) {
              _this.accessToken = body.access_token;
            } else {
              error = body;
            }
            return callback(error, response, body);
          };
        })(this));
      };
  
      DomoClient.prototype.request = function(options, callback) {
        if (options == null) {
          options = {};
        }
        if (typeof options === 'string') {
          options = {
            method: 'GET',
            uri: options
          };
        }
        if (this.accessToken) {
          if (options.auth == null) {
            options.auth = {
              bearer: this.accessToken
            };
          }
        }
        return request(options, (function(_this) {
          return function(error, response, body) {
            var e, error1, ref;
            if (error) {
              return callback(error, response, body);
            }
            if (((ref = options.headers) != null ? ref.accept : void 0) === 'text/csv') {
  
            } else {
              try {
                body = JSON.parse(body);
                if (body.toe != null) {
                  return callback(body, response, body);
                }
              } catch (error1) {
                e = error1;
              }
            }
            return callback(null, response, body);
          };
        })(this));
      };
  
      return DomoClient;
  
    })();
  
    module.exports = DomoClient;
  
  }).call(this);
  