Skip to content

Commit

Permalink
Close #2
Browse files Browse the repository at this point in the history
  • Loading branch information
sonufrienko committed Aug 18, 2018
1 parent af17dc3 commit 66c2def
Show file tree
Hide file tree
Showing 45 changed files with 121 additions and 238 deletions.
18 changes: 5 additions & 13 deletions src/ajaxClient.js
@@ -1,15 +1,15 @@
import fetch from 'isomorphic-fetch';
import queryString from 'query-string';

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

getConfig(method, data, cookie) {
let config = {
const config = {
credentials: this.getCredentialsConfig(this.baseUrl),
method: method,
method,
headers: {
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip, deflate'
Expand All @@ -33,21 +33,15 @@ class AjaxClient {
}

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 }))
.then(json => ({ status: response.status, json }))
.catch(() => ({ status: response.status, json: null }));
}

get(endpoint, filter, cookie) {
return fetch(
this.baseUrl + endpoint + '?' + queryString.stringify(filter),
`${this.baseUrl}${endpoint}?${queryString.stringify(filter)}`,
this.getConfig('get', null, cookie)
).then(this.returnStatusAndJson);
}
Expand All @@ -70,5 +64,3 @@ class AjaxClient {
);
}
}

module.exports = AjaxClient;
4 changes: 1 addition & 3 deletions src/api/ajaxCart.js
@@ -1,4 +1,4 @@
class AjaxCart {
export default class AjaxCart {
constructor(client) {
this.client = client;
}
Expand Down Expand Up @@ -35,5 +35,3 @@ class AjaxCart {
return this.client.delete(`/cart/items/${item_id}`);
}
}

module.exports = AjaxCart;
4 changes: 1 addition & 3 deletions src/api/ajaxPaymentFormSettings.js
@@ -1,4 +1,4 @@
class AjaxPaymentFormSettings {
export default class AjaxPaymentFormSettings {
constructor(client) {
this.client = client;
}
Expand All @@ -7,5 +7,3 @@ class AjaxPaymentFormSettings {
return this.client.get('/payment_form_settings');
}
}

module.exports = AjaxPaymentFormSettings;
4 changes: 1 addition & 3 deletions src/api/ajaxPaymentMethods.js
@@ -1,4 +1,4 @@
class AjaxPaymentMethods {
export default class AjaxPaymentMethods {
constructor(client) {
this.client = client;
}
Expand All @@ -7,5 +7,3 @@ class AjaxPaymentMethods {
return this.client.get('/payment_methods');
}
}

module.exports = AjaxPaymentMethods;
4 changes: 1 addition & 3 deletions src/api/ajaxShippingMethods.js
@@ -1,4 +1,4 @@
class AjaxShippingMethods {
export default class AjaxShippingMethods {
constructor(client) {
this.client = client;
}
Expand All @@ -7,5 +7,3 @@ class AjaxShippingMethods {
return this.client.get('/shipping_methods');
}
}

module.exports = AjaxShippingMethods;
4 changes: 1 addition & 3 deletions src/api/apps/settings.js
@@ -1,4 +1,4 @@
class AppSettings {
export default class AppSettings {
constructor(client) {
this.client = client;
}
Expand All @@ -11,5 +11,3 @@ class AppSettings {
return this.client.put(`/apps/${appKey}/settings`, data);
}
}

module.exports = AppSettings;
4 changes: 1 addition & 3 deletions src/api/checkoutFields.js
@@ -1,4 +1,4 @@
class CheckoutFields {
export default class CheckoutFields {
constructor(client) {
this.client = client;
}
Expand All @@ -15,5 +15,3 @@ class CheckoutFields {
return this.client.put(`/settings/checkout/fields/${name}`, data);
}
}

module.exports = CheckoutFields;
6 changes: 2 additions & 4 deletions src/api/countries.js
@@ -1,11 +1,9 @@
class Countries {
export default class Countries {
constructor(client) {
this.client = client;
}

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

module.exports = Countries;
}
4 changes: 1 addition & 3 deletions src/api/currencies.js
@@ -1,4 +1,4 @@
class Currencies {
export default class Currencies {
constructor(client) {
this.client = client;
}
Expand All @@ -7,5 +7,3 @@ class Currencies {
return this.client.get('/currencies');
}
}

module.exports = Currencies;
4 changes: 1 addition & 3 deletions src/api/customerGroups.js
@@ -1,4 +1,4 @@
class CustomerGroups {
export default class CustomerGroups {
constructor(client) {
this.client = client;
}
Expand All @@ -23,5 +23,3 @@ class CustomerGroups {
return this.client.delete(`/customer_groups/${id}`);
}
}

module.exports = CustomerGroups;
4 changes: 1 addition & 3 deletions src/api/customers.js
@@ -1,4 +1,4 @@
class Customers {
export default class Customers {
constructor(client) {
this.client = client;
}
Expand Down Expand Up @@ -51,5 +51,3 @@ class Customers {
);
}
}

module.exports = Customers;
4 changes: 1 addition & 3 deletions src/api/files.js
@@ -1,4 +1,4 @@
class Files {
export default class Files {
constructor(client) {
this.client = client;
}
Expand All @@ -15,5 +15,3 @@ class Files {
return this.client.delete(`/files/${fileName}`);
}
}

module.exports = Files;
4 changes: 1 addition & 3 deletions src/api/orders/discounts.js
@@ -1,4 +1,4 @@
class OrderDiscounts {
export default class OrderDiscounts {
constructor(client) {
this.client = client;
}
Expand All @@ -18,5 +18,3 @@ class OrderDiscounts {
return this.client.delete(`/orders/${order_id}/discounts/${discount_id}`);
}
}

module.exports = OrderDiscounts;
4 changes: 1 addition & 3 deletions src/api/orders/items.js
@@ -1,4 +1,4 @@
class OrderItems {
export default class OrderItems {
constructor(client) {
this.client = client;
}
Expand All @@ -15,5 +15,3 @@ class OrderItems {
return this.client.delete(`/orders/${order_id}/items/${item_id}`);
}
}

module.exports = OrderItems;
4 changes: 1 addition & 3 deletions src/api/orders/orders.js
@@ -1,4 +1,4 @@
class Orders {
export default class Orders {
constructor(client) {
this.client = client;
}
Expand Down Expand Up @@ -51,5 +51,3 @@ class Orders {
return this.client.get(`/orders/${order_id}/payment_form_settings`);
}
}

module.exports = Orders;
4 changes: 1 addition & 3 deletions src/api/orders/statuses.js
@@ -1,4 +1,4 @@
class OrderStatuses {
export default class OrderStatuses {
constructor(client) {
this.client = client;
}
Expand All @@ -23,5 +23,3 @@ class OrderStatuses {
return this.client.delete(`/order_statuses/${id}`);
}
}

module.exports = OrderStatuses;
4 changes: 1 addition & 3 deletions src/api/orders/transactions.js
@@ -1,4 +1,4 @@
class OrderTransactions {
export default class OrderTransactions {
constructor(client) {
this.client = client;
}
Expand All @@ -20,5 +20,3 @@ class OrderTransactions {
);
}
}

module.exports = OrderTransactions;
4 changes: 1 addition & 3 deletions src/api/pages.js
@@ -1,4 +1,4 @@
class Pages {
export default class Pages {
constructor(client) {
this.client = client;
}
Expand All @@ -23,5 +23,3 @@ class Pages {
return this.client.delete(`/pages/${id}`);
}
}

module.exports = Pages;
4 changes: 1 addition & 3 deletions src/api/paymentGateways.js
@@ -1,4 +1,4 @@
class PaymentGateways {
export default class PaymentGateways {
constructor(client) {
this.client = client;
}
Expand All @@ -11,5 +11,3 @@ class PaymentGateways {
return this.client.put(`/payment_gateways/${gatewayName}`, data);
}
}

module.exports = PaymentGateways;
4 changes: 1 addition & 3 deletions src/api/paymentMethods.js
@@ -1,4 +1,4 @@
class PaymentMethods {
export default class PaymentMethods {
constructor(client) {
this.client = client;
}
Expand All @@ -23,5 +23,3 @@ class PaymentMethods {
return this.client.delete(`/payment_methods/${id}`);
}
}

module.exports = PaymentMethods;
4 changes: 1 addition & 3 deletions src/api/productCategories.js
@@ -1,4 +1,4 @@
class ProductCategories {
export default class ProductCategories {
constructor(client) {
this.client = client;
}
Expand Down Expand Up @@ -34,5 +34,3 @@ class ProductCategories {
return this.client.delete(`/product_categories/${id}/image`);
}
}

module.exports = ProductCategories;
4 changes: 1 addition & 3 deletions src/api/products/images.js
@@ -1,4 +1,4 @@
class ProductImages {
export default class ProductImages {
constructor(client) {
this.client = client;
}
Expand All @@ -19,5 +19,3 @@ class ProductImages {
return this.client.delete(`/products/${productId}/images/${imageId}`);
}
}

module.exports = ProductImages;
4 changes: 1 addition & 3 deletions src/api/products/optionValues.js
@@ -1,4 +1,4 @@
class ProductOptionValues {
export default class ProductOptionValues {
constructor(client) {
this.client = client;
}
Expand Down Expand Up @@ -33,5 +33,3 @@ class ProductOptionValues {
);
}
}

module.exports = ProductOptionValues;
4 changes: 1 addition & 3 deletions src/api/products/options.js
@@ -1,4 +1,4 @@
class ProductOptions {
export default class ProductOptions {
constructor(client) {
this.client = client;
}
Expand All @@ -23,5 +23,3 @@ class ProductOptions {
return this.client.delete(`/products/${productId}/options/${optionId}`);
}
}

module.exports = ProductOptions;
4 changes: 1 addition & 3 deletions src/api/products/products.js
@@ -1,4 +1,4 @@
class Products {
export default class Products {
constructor(client) {
this.client = client;
}
Expand Down Expand Up @@ -31,5 +31,3 @@ class Products {
return this.client.get(`/products/${productId}/slug`, { slug: slug });
}
}

module.exports = Products;
4 changes: 1 addition & 3 deletions src/api/products/variants.js
@@ -1,4 +1,4 @@
class ProductVariants {
export default class ProductVariants {
constructor(client) {
this.client = client;
}
Expand Down Expand Up @@ -29,5 +29,3 @@ class ProductVariants {
);
}
}

module.exports = ProductVariants;
4 changes: 1 addition & 3 deletions src/api/redirects.js
@@ -1,4 +1,4 @@
class Redirects {
export default class Redirects {
constructor(client) {
this.client = client;
}
Expand All @@ -23,5 +23,3 @@ class Redirects {
return this.client.delete(`/redirects/${id}`);
}
}

module.exports = Redirects;
4 changes: 1 addition & 3 deletions src/api/settings.js
@@ -1,4 +1,4 @@
class Settings {
export default class Settings {
constructor(client) {
this.client = client;
}
Expand Down Expand Up @@ -35,5 +35,3 @@ class Settings {
return this.client.delete(`/settings/logo`);
}
}

module.exports = Settings;
4 changes: 1 addition & 3 deletions src/api/shippingMethods.js
@@ -1,4 +1,4 @@
class ShippingMethods {
export default class ShippingMethods {
constructor(client) {
this.client = client;
}
Expand All @@ -23,5 +23,3 @@ class ShippingMethods {
return this.client.delete(`/shipping_methods/${id}`);
}
}

module.exports = ShippingMethods;
4 changes: 1 addition & 3 deletions src/api/sitemap.js
@@ -1,4 +1,4 @@
class Sitemap {
export default class Sitemap {
constructor(client) {
this.client = client;
}
Expand All @@ -11,5 +11,3 @@ class Sitemap {
return this.client.get('/sitemap', filter);
}
}

module.exports = Sitemap;

0 comments on commit 66c2def

Please sign in to comment.