Snapchat Client

@class
@param {Object} opts (currently unused)
357308
function Snapchat (opts) {
  var self = this
  if (!(self instanceof Snapchat)) return new Snapchat(opts)
  if (!opts) opts = {}

  debug('new snapchat client')

  self._account = new Account(self, opts)
  self._chat = new Chat(self, opts)
  self._device = new Device(self, opts)
  self._friends = new Friends(self, opts)
  self._snaps = new Snaps(self, opts)
  self._stories = new Stories(self, opts)
}
511516
function(opts, callback) {
  if (callback === undefined) {
    throw new Error('callback undefined in $fh.cache. See documentation of $fh.cache for proper usage');
  }

  if (opts.act === undefined) {
    return callback('No cache actions defined!');
  }

  var fullKey = appname + opts.key;

  var client = redisClient();
  if (opts.act === 'save') {
    client.on("connect", function() {
      if (redisPassword) {
        client.auth(redisPassword, function(err) {
          if (err) {
            callback(err);
          }
        });
      }
    });
    client.on("error", function(err) {
      console.error("fh.cache error: %s ", err);
      return callback(err);
    });
    client.on("ready", function(err) {
      if (err) {
        return callback(err);
      }
      if (opts.expire !== undefined) {
        client.setex(fullKey, opts.expire, opts.value, function(err, reply) {
          client.quit();
          return callback(err, reply);
        });
      } else {
        client.set(fullKey, opts.value, function(err, reply) {
          client.quit();
          return callback(err, reply);
        });
      }
    });
  } else if (opts.act === 'load') {
    client.on("connect", function() {
      if (redisPassword) {
        client.auth(redisPassword, function(err) {
          if (err) {
            callback(err);
          }
        });
      }
    });
    client.on("error", function(err) {
      console.error("fh.cache error: %s", err);
      callback(err);
      client.end();
    });
    client.on("ready", function(err) {
      if (err) {
        return callback(err);
      }
      client.get(fullKey, function(err, reply) {
        client.quit();
        return callback(err, reply);
      });
    });
  } else if (opts.act === 'remove') {
    client.on("connect", function() {
      if (redisPassword) {
        client.auth(redisPassword, function(err) {
          if (err) {
            callback(err);
          }
        });
      }
    });
    client.on("error", function(err) {
      console.error("fh.cache error: %s", err);
      return callback(err);
    });
    client.on("ready", function(err) {
      if (err) {
        return callback(err);
      }
      client.del(fullKey, function(err, reply) {
        client.quit();
        return callback(err, reply);
      });
    });
  } else {
    return callback("Unknown cache action: " + opts.act);
  }
}
1139166
function(opts){
  //defaults
  opts = opts || {};
  this.username           = opts.username    || '';
  this.password           = opts.password    || '';
  // oAuth Token
  this.accessToken        = opts.accessToken || '';
  // API Rate Limit Details
  this.rateLimit          = 5000;
  this.rateLimitRemaining = this.rateLimit;  //rateLimitRemaining starts as rateLimit
}
1159944
function (opts, id) {
        let uri = this.classUrl
        if (id) {
          uri += '/' + id
        }

        return new Promise(function (resolve, reject) {
          new Requestor({ api_version: instance.api_version }).request({
            method: 'post',
            url: [Conekta.api_base, uri].join(''),
            data: opts.data || {},
            next: function (error, response) {
              if (!error) {
                response = this.listObjectsToArray(response)
                this._json = response
                this._id = response.id
                this.build_children()
              }
              if (opts.next !== undefined) {
                opts.next(error, this)
              } else {
                if (error) {
                  reject(error)
                } else {
                  resolve(this)
                }
              }
            }.bind(this)
          })
        }.bind(this))
      }
382174
function Device (client, opts) {
  var self = this
  if (!(self instanceof Device)) return new Device(client, opts)
  if (!opts) opts = {}

  self.client = client
}
147346
function IndexService(opts) {
  util.applyProperties(this, opts);
  if (this.project) {
    this.metadataHelper = new MetadataHelper({ sfdcClient : this.project.sfdcClient });
    this.sfdcClient = this.project.sfdcClient;
  } else if (this.sfdcClient) {
    this.metadataHelper = new MetadataHelper({ sfdcClient : this.sfdcClient });
  }
}
989060
function Client(opts) {
  var self = this;
  opts = opts || {};

  events.EventEmitter.call(this);

  this._endpoint = opts.oauth.instance_url + '/cometd/' + opts.apiVersion.substring(1);
  this._fayeClient = new faye.Client(this._endpoint, {
    timeout: opts.timeout,
    retry: opts.retry
  });
  this._fayeClient.setHeader('Authorization', 'Bearer ' + opts.oauth.access_token);

  this._fayeClient.on('transport:up', function() {
    self.emit('connect');
  });

  this._fayeClient.on('transport:down', function() {
    self.emit('disconnect');
  });

  this._replayFromMap = {};

  var client = this;
  var replayExtension = {
    outgoing: function(message, callback) {
      if (message.channel === '/meta/subscribe') {
        if (!message.ext) { message.ext = {}; }
        message.ext['replay'] = client._replayFromMap;
      }
      callback(message);
    }
  };
  this._fayeClient.addExtension(replayExtension);
}
1158712
function(server, opts) {
  EventEmitter.call(this);
  this.server = server;
  this.wsprocessor = new WSProcessor();
  this.tcpprocessor = new TCPProcessor(opts.closeMethod);
  this.id = 1;
  this.timeout = (opts.timeout || DEFAULT_TIMEOUT) * 1000;
  this.setNoDelay = opts.setNoDelay;

  if (!opts.ssl) {
    this.server.on('connection', this.newSocket.bind(this));
  } else {
    this.server.on('secureConnection', this.newSocket.bind(this));
    this.server.on('clientError', function(e, tlsSo) {
      logger.warn('an ssl error occured before handshake established: ', e);
      tlsSo.destroy();
    });
  }

  this.wsprocessor.on('connection', this.emit.bind(this, 'connection'));
  this.tcpprocessor.on('connection', this.emit.bind(this, 'connection'));

  this.state = ST_STARTED;
}
329302
function CallFunc (opts) {
    CallFunc.superclass.constructor.call(this, opts)

    // Save target & method so that copy() can recreate callback
    this.target = opts.target
    this.method = (typeof opts.method == 'function') ? opts.method : this.target[opts.method]
    this.callback = this.method.bind(this.target)
}
635246
function polling$1(opts) {
  var xhr;
  var xd = false;
  var xs = false;
  var jsonp = false !== opts.jsonp;

  if (commonjsGlobal.location) {
    var isSSL = "https:" === location.protocol;
    var port = location.port;

    // some user agents have empty `location.port`
    if (!port) {
      port = isSSL ? 443 : 80;
    }

    xd = opts.hostname !== location.hostname || port !== opts.port;
    xs = opts.secure !== isSSL;
  }

  opts.xdomain = xd;
  opts.xscheme = xs;
  xhr = new xmlhttprequest(opts);

  if ("open" in xhr && !opts.forceJSONP) {
    return new pollingXhr(opts);
  } else {
    if (!jsonp) throw new Error("JSONP disabled");
    return new pollingJsonp(opts);
  }
}
827566
function OAuth(opts) {
    if(!(this instanceof OAuth)) {
        return new OAuth(opts);
    }

    if(!opts) {
        opts = {};
    }

    if(!opts.consumer) {
        throw new Error('consumer option is required');
    }

    this.consumer            = opts.consumer;
    this.nonce_length        = opts.nonce_length || 32;
    this.version             = opts.version || '1.0';
    this.parameter_seperator = opts.parameter_seperator || ', ';
    this.realm               = opts.realm;

    if(typeof opts.last_ampersand === 'undefined') {
        this.last_ampersand = true;
    } else {
        this.last_ampersand = opts.last_ampersand;
    }

    // default signature_method is 'PLAINTEXT'
    this.signature_method = opts.signature_method || 'PLAINTEXT';

    if(this.signature_method == 'PLAINTEXT' && !opts.hash_function) {
        opts.hash_function = function(base_string, key) {
            return key;
        }
    }

    if(!opts.hash_function) {
        throw new Error('hash_function option is required');
    }

    this.hash_function = opts.hash_function;
    this.body_hash_function = opts.body_hash_function || this.hash_function;
}
802437
function Client(options) {
  var self = this;

  // Filers
  this.__filters_in__ = [];
  this.__filters_out__ = [];

  // Subscriptions
  this.__subscriptions__ = [];

  // Current node id
  this.__node_id__ = Math.floor(Math.random() * 1e10) + 1;

  // Message incremental counter
  this.__last_message_cnt__ = 0;

  // List of ignoring messages
  this.__ignore_list__ = {};

  // Router
  this.__router__ = options.router;

  this.__router__.onmessage(function (channel, message) {
    self.__onmessage__(channel, message);
  });

  // Lock handlers
  this.__lock_handlers__ = {};

  // If client make lock request - store handler and remove it from message
  this.filterOut(function (channel, message, callback) {
    if (channel === '!sys.lock.request') {
      var fn = message.data.fn;
      var lockId = message.data.id;

      delete message.data.fn;

      // Wrap handler to pass unlock function into it
      self.__lock_handlers__[message.id] = function () {
        fn(function unlock() {
          self.emit('!sys.lock.release', { id: lockId });
        });
      };
    }

    callback(channel, message);
  });

  // If lock acquired - execute handler
  this.filterIn(function (channel, message, callback) {
    if (channel === '!sys.lock.acquired' && self.__lock_handlers__[message.data.request_id]) {
      self.__lock_handlers__[message.data.request_id]();
      delete self.__lock_handlers__[message.data.request_id];
    }

    callback(channel, message);
  });
}
1040504
function Socket (io, nsp, opts) {
  this.io = io;
  this.nsp = nsp;
  this.json = this; // compat
  this.ids = 0;
  this.acks = {};
  this.receiveBuffer = [];
  this.sendBuffer = [];
  this.connected = false;
  this.disconnected = true;
  if (opts && opts.query) {
    this.query = opts.query;
  }
  if (this.io.autoConnect) this.open();
}
956881
function createClient(url, opts) {
  // Attempt to get Url from this instance.
  url = url || this.url || (this.opts || {}).url || (opts || {}).url;
  if (! url) {
    throw 'No url specified for ActiveDirectory client.';
  }
  log.trace('createClient(%s)', url);

  var opts = getLdapClientOpts(_.defaults({}, { url: url }, opts, this.opts));
  log.debug('Creating ldapjs client for %s. Opts: %j', opts.url, _.omit(opts, 'url', 'bindDN', 'bindCredentials'));
  var client = ldap.createClient(opts);
  return(client);
}
708067
function(opts) {
      opts = opts || {};
      var path = opts.path || this.path,
          callback = opts.callback,
          method = opts.method || this.method,
          ws = getWebsocketPlugin(),
          transports = app.config.transports,
          self = this,
          i = 0,
          error,
          response;

      if (ws) {
        if (transports && transports.length > 0) {
          async.whilst(
            function () {
              return (i < transports.length);
            },
            function (done) {
              self.doConnect(transports[i], method, path, function (err, res) {
                error = err;
                response = res;
                if (!err && res) {
                  i = transports.length;
                } else {
                  i++;
                  if (i < transports.length) {
                    delete self.request;
                  }
                }
                done();
              });
            },
            function (err) {
              callback(err || error, response);
            }
          );
        } else {
          error = 'no transport available';
          log.error('%s %s', app.name, error);
          callback(error);
        }
      } else {
        this.doConnect('http', method, path, callback);
      }
      return this;
    }
1345475
function(app, opts) {
  opts = opts || {};
  this.app = app;
  this.service = new SessionService(opts);

  let getFun = function(m) {
    return (function() {
          return function() {
            return self.service[m].apply(self.service, arguments);
          };
    })();
  };
  // proxy the service methods except the lifecycle interfaces of component
  let method, self = this;
  for(let m in this.service) {
    if(m !== 'start' && m !== 'stop') {
      method = this.service[m];
      if(typeof method === 'function') {
        this[m] = getFun(m);
      }
    }
  }
}
1274812
function XHR(opts){
  Polling.call(this, opts);

  if (global.location) {
    var isSSL = 'https:' == location.protocol;
    var port = location.port;

    // some user agents have empty `location.port`
    if (Number(port) !== port) {
      port = isSSL ? 443 : 80;
    }

    this.xd = opts.hostname != global.location.hostname ||
      port != opts.port;
  }
}