Skip to content

Commit

Permalink
Code formatted with Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
sonufrienko committed Aug 18, 2018
1 parent 5a2757a commit af17dc3
Show file tree
Hide file tree
Showing 45 changed files with 1,003 additions and 923 deletions.
87 changes: 49 additions & 38 deletions src/ajaxClient.js
@@ -1,62 +1,73 @@
import fetch from 'isomorphic-fetch'
import queryString from 'query-string'
import fetch from 'isomorphic-fetch';
import queryString from 'query-string';

class AjaxClient {
constructor(options) {
this.baseUrl = options.baseUrl;
}
constructor(options) {
this.baseUrl = options.baseUrl;
}

getConfig(method, data, cookie) {
let config = {
credentials: this.getCredentialsConfig(this.baseUrl),
method: method,
let config = {
credentials: this.getCredentialsConfig(this.baseUrl),
method: method,
headers: {
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip, deflate'
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip, deflate'
}
};

if(cookie) {
config.headers.Cookie = cookie;
}
if (cookie) {
config.headers.Cookie = cookie;
}

if(data) {
config.body = JSON.stringify(data);
}
return config;
if (data) {
config.body = JSON.stringify(data);
}
return config;
}

getCredentialsConfig(baseUrl) {
const includePrefix = baseUrl.includes('http://') || baseUrl.includes('https://');
return includePrefix ? 'include' : 'same-origin';
}
getCredentialsConfig(baseUrl) {
const includePrefix =
baseUrl.includes('http://') || baseUrl.includes('https://');
return includePrefix ? 'include' : 'same-origin';
}

returnStatusAndJson(response) {
// response.status (number) - HTTP response code in the 100–599 range
// response.statusText (String) - Status text as reported by the server, e.g. "Unauthorized"
// response.ok (boolean) - True if status is HTTP 2xx
// response.headers (Headers)
// response.url (String)
returnStatusAndJson(response) {
// response.status (number) - HTTP response code in the 100–599 range
// response.statusText (String) - Status text as reported by the server, e.g. "Unauthorized"
// response.ok (boolean) - True if status is HTTP 2xx
// response.headers (Headers)
// response.url (String)

return response.json()
.then(json => ({status: response.status, json: json}))
.catch(() => ({status: response.status, json: null}));
}
return response
.json()
.then(json => ({ status: response.status, json: json }))
.catch(() => ({ status: response.status, json: null }));
}

get(endpoint, filter, cookie) {
return fetch(this.baseUrl + endpoint + "?" + queryString.stringify(filter), this.getConfig('get', null, cookie)).then(this.returnStatusAndJson);
return fetch(
this.baseUrl + endpoint + '?' + queryString.stringify(filter),
this.getConfig('get', null, cookie)
).then(this.returnStatusAndJson);
}

post(endpoint, data) {
return fetch(this.baseUrl + endpoint, this.getConfig('post', data)).then(this.returnStatusAndJson);
post(endpoint, data) {
return fetch(this.baseUrl + endpoint, this.getConfig('post', data)).then(
this.returnStatusAndJson
);
}

put(endpoint, data) {
return fetch(this.baseUrl + endpoint, this.getConfig('put', data)).then(this.returnStatusAndJson);
put(endpoint, data) {
return fetch(this.baseUrl + endpoint, this.getConfig('put', data)).then(
this.returnStatusAndJson
);
}

delete(endpoint) {
return fetch(this.baseUrl + endpoint, this.getConfig('delete')).then(this.returnStatusAndJson);
delete(endpoint) {
return fetch(this.baseUrl + endpoint, this.getConfig('delete')).then(
this.returnStatusAndJson
);
}
}

Expand Down
56 changes: 28 additions & 28 deletions src/api/ajaxCart.js
@@ -1,39 +1,39 @@
class AjaxCart {
constructor(client) {
this.client = client;
}
constructor(client) {
this.client = client;
}

retrieve(cookie) {
return this.client.get(`/cart`, null, cookie);
}
retrieve(cookie) {
return this.client.get(`/cart`, null, cookie);
}

update(data) {
return this.client.put(`/cart`, data);
}
update(data) {
return this.client.put(`/cart`, data);
}

checkout() {
return this.client.put(`/cart/checkout`);
}
checkout() {
return this.client.put(`/cart/checkout`);
}

updateBillingAddress(address) {
return this.client.put(`/cart/billing_address`, address);
}
updateBillingAddress(address) {
return this.client.put(`/cart/billing_address`, address);
}

updateShippingAddress(address) {
return this.client.put(`/cart/shipping_address`, address);
}
updateShippingAddress(address) {
return this.client.put(`/cart/shipping_address`, address);
}

addItem(data) {
return this.client.post(`/cart/items`, data);
}
addItem(data) {
return this.client.post(`/cart/items`, data);
}

updateItem(item_id, data) {
return this.client.put(`/cart/items/${item_id}`, data);
}
updateItem(item_id, data) {
return this.client.put(`/cart/items/${item_id}`, data);
}

deleteItem(item_id) {
return this.client.delete(`/cart/items/${item_id}`);
}
deleteItem(item_id) {
return this.client.delete(`/cart/items/${item_id}`);
}
}

module.exports = AjaxCart
module.exports = AjaxCart;
12 changes: 6 additions & 6 deletions src/api/ajaxPaymentFormSettings.js
@@ -1,11 +1,11 @@
class AjaxPaymentFormSettings {
constructor(client) {
this.client = client;
}
constructor(client) {
this.client = client;
}

retrieve() {
return this.client.get('/payment_form_settings');
}
retrieve() {
return this.client.get('/payment_form_settings');
}
}

module.exports = AjaxPaymentFormSettings;
14 changes: 7 additions & 7 deletions src/api/ajaxPaymentMethods.js
@@ -1,11 +1,11 @@
class AjaxPaymentMethods {
constructor(client) {
this.client = client;
}
constructor(client) {
this.client = client;
}

list() {
return this.client.get('/payment_methods');
}
list() {
return this.client.get('/payment_methods');
}
}

module.exports = AjaxPaymentMethods
module.exports = AjaxPaymentMethods;
14 changes: 7 additions & 7 deletions src/api/ajaxShippingMethods.js
@@ -1,11 +1,11 @@
class AjaxShippingMethods {
constructor(client) {
this.client = client;
}
constructor(client) {
this.client = client;
}

list() {
return this.client.get('/shipping_methods');
}
list() {
return this.client.get('/shipping_methods');
}
}

module.exports = AjaxShippingMethods
module.exports = AjaxShippingMethods;
20 changes: 10 additions & 10 deletions src/api/apps/settings.js
@@ -1,15 +1,15 @@
class AppSettings {
constructor(client) {
this.client = client;
}
constructor(client) {
this.client = client;
}

retrieve(appKey) {
return this.client.get(`/apps/${appKey}/settings`);
}
retrieve(appKey) {
return this.client.get(`/apps/${appKey}/settings`);
}

update(appKey, data) {
return this.client.put(`/apps/${appKey}/settings`, data);
}
update(appKey, data) {
return this.client.put(`/apps/${appKey}/settings`, data);
}
}

module.exports = AppSettings
module.exports = AppSettings;
26 changes: 13 additions & 13 deletions src/api/checkoutFields.js
@@ -1,19 +1,19 @@
class CheckoutFields {
constructor(client) {
this.client = client;
}
constructor(client) {
this.client = client;
}

list() {
return this.client.get('/settings/checkout/fields');
}
list() {
return this.client.get('/settings/checkout/fields');
}

retrieve(name) {
return this.client.get(`/settings/checkout/fields/${name}`);
}
retrieve(name) {
return this.client.get(`/settings/checkout/fields/${name}`);
}

update(name, data) {
return this.client.put(`/settings/checkout/fields/${name}`, data);
}
update(name, data) {
return this.client.put(`/settings/checkout/fields/${name}`, data);
}
}

module.exports = CheckoutFields
module.exports = CheckoutFields;
14 changes: 7 additions & 7 deletions src/api/countries.js
@@ -1,11 +1,11 @@
class Countries {
constructor(client) {
this.client = client;
}
constructor(client) {
this.client = client;
}

list() {
return this.client.get('/countries');
}
list() {
return this.client.get('/countries');
}
}

module.exports = Countries
module.exports = Countries;
14 changes: 7 additions & 7 deletions src/api/currencies.js
@@ -1,11 +1,11 @@
class Currencies {
constructor(client) {
this.client = client;
}
constructor(client) {
this.client = client;
}

list() {
return this.client.get('/currencies');
}
list() {
return this.client.get('/currencies');
}
}

module.exports = Currencies
module.exports = Currencies;
38 changes: 19 additions & 19 deletions src/api/customerGroups.js
@@ -1,27 +1,27 @@
class CustomerGroups {
constructor(client) {
this.client = client;
}
constructor(client) {
this.client = client;
}

list(filter) {
return this.client.get('/customer_groups', filter);
}
list(filter) {
return this.client.get('/customer_groups', filter);
}

retrieve(id, filter) {
return this.client.get(`/customer_groups/${id}`, filter);
}
retrieve(id, filter) {
return this.client.get(`/customer_groups/${id}`, filter);
}

create(data) {
return this.client.post(`/customer_groups`, data);
}
create(data) {
return this.client.post(`/customer_groups`, data);
}

update(id, data) {
return this.client.put(`/customer_groups/${id}`, data);
}
update(id, data) {
return this.client.put(`/customer_groups/${id}`, data);
}

delete(id) {
return this.client.delete(`/customer_groups/${id}`);
}
delete(id) {
return this.client.delete(`/customer_groups/${id}`);
}
}

module.exports = CustomerGroups
module.exports = CustomerGroups;

0 comments on commit af17dc3

Please sign in to comment.