Skip to content

Commit

Permalink
Fix up even more violations
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Jul 11, 2018
1 parent d575eda commit fa61c9e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Expand Up @@ -11,5 +11,8 @@
"arrow-parens": [2, "as-needed"],
"comma-dangle": 0,
"quotes": [2, "double"]
},
"globals": {
"CLIENT_VERSION": "0.0.1"
}
}
14 changes: 7 additions & 7 deletions src/api-call.js
@@ -1,9 +1,11 @@
import request from "./request";
import state from "./state";

const { hasOwnProperty } = Object.prototype;

const ensureExpectedParams = (expectedParams, actualParams) => {
expectedParams.forEach(param => {
if (!actualParams.hasOwnProperty(param)) {
if (!hasOwnProperty.call(actualParams, param)) {
throw new Error(`Expected parameter ${param} not given`);
}
});
Expand Down Expand Up @@ -34,17 +36,15 @@ export default (client, options) => {
] = options;

const apiCall = actualParams => {
if (typeof actualParams !== "object") {
actualParams = {};
}
const normalizedParams = typeof actualParams !== "object" ? {} : actualParams;

ensureExpectedParams(expectedParams, actualParams);
const callPath = substitutePath(path, actualParams);
ensureExpectedParams(expectedParams, normalizedParams);
const callPath = substitutePath(path, normalizedParams);

return request(method, new URL(`${client.apiHost}${callPath}`), {
token: state.getToken(),
simulation: state.getSimulationToken(),
params: actualParams,
params: normalizedParams,
multipart
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/auto-paginator.js
Expand Up @@ -47,7 +47,7 @@ class AutoPaginator {
}

Object.keys(calls).forEach(callName => {
AutoPaginator.prototype[callName] = function(options) {
AutoPaginator.prototype[callName] = function (options) {
return this.aggregate(callName, options);
};
});
Expand Down
42 changes: 21 additions & 21 deletions src/index.js
Expand Up @@ -99,34 +99,34 @@ class CultureHQ {

endUserSimulation() {
state.endSimulation();
this._disconnectConsumer();
this.disconnectConsumer();
}

isSignedIn() {
isSignedIn() { /* eslint-disable-line class-methods-use-this */
return state.isSignedIn();
}

isSimulating() {
isSimulating() { /* eslint-disable-line class-methods-use-this */
return state.isSimulating();
}

onLeaderboardUpdated(callback) {
return this._subscribeToChannel("LeaderboardChannel", callback);
return this.subscribeToChannel("LeaderboardChannel", callback);
}

onNotificationReceived(callback) {
return this._subscribeToChannel("NotificationChannel", callback);
return this.subscribeToChannel("NotificationChannel", callback);
}

onRecognitionCreated(callback) {
return this._subscribeToChannel("RecognitionChannel", callback);
return this.subscribeToChannel("RecognitionChannel", callback);
}

onUserActivityCreated(callback) {
return this._subscribeToChannel("UserActivityChannel", callback);
return this.subscribeToChannel("UserActivityChannel", callback);
}

setToken(token) {
setToken(token) { /* eslint-disable-line class-methods-use-this */
state.signIn(token);
}

Expand All @@ -140,7 +140,7 @@ class CultureHQ {
signOut() {
return this.deleteSession().then(response => {
state.signOut();
this._disconnectConsumer();
this.disconnectConsumer();
return response;
});
}
Expand All @@ -152,7 +152,7 @@ class CultureHQ {
startUserSimulation(params) {
return this.createSimulation(params).then(response => {
state.startSimulation(response.apiKey.token);
this._disconnectConsumer();
this.disconnectConsumer();
return response;
});
}
Expand All @@ -161,28 +161,28 @@ class CultureHQ {
return new AutoPaginator(this, dataType);
}

_disconnectConsumer() {
if (this._consumer) {
this._consumer.disconnect();
this._consumer = null;
disconnectConsumer() {
if (this.consumer) {
this.consumer.disconnect();
this.consumer = null;
}
}

_ensureConsumer() {
if (this._consumer) {
return this._consumer;
ensureConsumer() {
if (this.consumer) {
return this.consumer;
}

const [protocol, host] = this.apiHost.split("://");
const wsProtocol = protocol === "https" ? "wss" : "ws";

const endpoint = `${wsProtocol}://${host}/cable/${state.getToken()}`;
this._consumer = ActionCable.createConsumer(endpoint);
return this._consumer;
this.consumer = ActionCable.createConsumer(endpoint);
return this.consumer;
}

_subscribeToChannel(channel, callback) {
return this._ensureConsumer().subscriptions.create(channel, {
subscribeToChannel(channel, callback) {
return this.ensureConsumer().subscriptions.create(channel, {
received: data => callback(camelize(data))
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/request.js
Expand Up @@ -3,7 +3,7 @@ import formData from "./form-data";
import processResponse from "./response";

const buildHeaders = ({ multipart, token, simulation }) => {
let headers = { "X-Client-Version": CLIENT_VERSION };
const headers = { "X-Client-Version": CLIENT_VERSION };

if (!multipart) {
headers["Content-Type"] = "application/json";
Expand Down
1 change: 1 addition & 0 deletions src/response.js
Expand Up @@ -13,6 +13,7 @@ const textResponse = response => text => new Promise((resolve, reject) => {
if (Math.round(status / 100) === 2) {
resolve({ text, response, status });
} else {
/* eslint-disable-next-line prefer-promise-reject-errors */
reject({ error: statusText, response, status });
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/form-data.test.js
@@ -1,6 +1,6 @@
import formData from "../src/form-data";

const serializeFormData = data => {
const serializeFormData = data => { /* eslint-disable no-underscore-dangle */
const serialized = [];

for (let idx = 0; idx < data._streams.length; idx += 3) {
Expand Down

0 comments on commit fa61c9e

Please sign in to comment.