Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sonufrienko committed Aug 18, 2018
1 parent 66c2def commit 196a06e
Show file tree
Hide file tree
Showing 27 changed files with 181 additions and 151 deletions.
8 changes: 4 additions & 4 deletions src/api/ajaxCart.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export default class AjaxCart {
return this.client.post(`/cart/items`, data);
}

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

deleteItem(item_id) {
return this.client.delete(`/cart/items/${item_id}`);
deleteItem(id) {
return this.client.delete(`/cart/items/${id}`);
}
}
5 changes: 3 additions & 2 deletions src/api/apps/settings.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
export default class AppSettings {
constructor(client) {
this.client = client;
this.resourceUrl = '/apps';
}

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

update(appKey, data) {
return this.client.put(`/apps/${appKey}/settings`, data);
return this.client.put(`${this.resourceUrl}/${appKey}/settings`, data);
}
}
7 changes: 4 additions & 3 deletions src/api/checkoutFields.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
export default class CheckoutFields {
constructor(client) {
this.client = client;
this.resourceUrl = '/settings/checkout/fields';
}

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

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

update(name, data) {
return this.client.put(`/settings/checkout/fields/${name}`, data);
return this.client.put(`${this.resourceUrl}/${name}`, data);
}
}
2 changes: 1 addition & 1 deletion src/api/countries.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export default class Countries {
list() {
return this.client.get('/countries');
}
}
}
11 changes: 6 additions & 5 deletions src/api/customerGroups.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
export default class CustomerGroups {
constructor(client) {
this.client = client;
this.resourceUrl = '/customer_groups';
}

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

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

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

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

delete(id) {
return this.client.delete(`/customer_groups/${id}`);
return this.client.delete(`${this.resourceUrl}/${id}`);
}
}
34 changes: 19 additions & 15 deletions src/api/customers.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
export default class Customers {
constructor(client) {
this.client = client;
this.resourceUrl = '/customers';
}

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

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

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

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

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

createAddress(customer_id, data) {
return this.client.post(`/customers/${customer_id}`, data);
createAddress(customerId, data) {
return this.client.post(`${this.resourceUrl}/${customerId}`, data);
}

updateAddress(customer_id, address_id, data) {
updateAddress(customerId, addressId, data) {
return this.client.put(
`/customers/${customer_id}/addresses/${address_id}`,
`${this.resourceUrl}/${customerId}/addresses/${addressId}`,
data
);
}

deleteAddress(customer_id, address_id) {
deleteAddress(customerId, addressId) {
return this.client.delete(
`/customers/${customer_id}/addresses/${address_id}`
`${this.resourceUrl}/${customerId}/addresses/${addressId}`
);
}

setDefaultBillingAddress(customer_id, address_id) {
setDefaultBillingAddress(customerId, addressId) {
return this.client.post(
`/customers/${customer_id}/addresses/${address_id}/default_billing`
`${this.resourceUrl}/${customerId}/addresses/${addressId}/default_billing`
);
}
setDefaultShippingAddress(customer_id, address_id) {

setDefaultShippingAddress(customerId, addressId) {
return this.client.post(
`/customers/${customer_id}/addresses/${address_id}/default_shipping`
`${
this.resourceUrl
}/${customerId}/addresses/${addressId}/default_shipping`
);
}
}
7 changes: 4 additions & 3 deletions src/api/files.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
export default class Files {
constructor(client) {
this.client = client;
this.resourceUrl = '/files';
}

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

upload(formData) {
return this.client.postFormData('/files', formData);
return this.client.postFormData(this.resourceUrl, formData);
}

delete(fileName) {
return this.client.delete(`/files/${fileName}`);
return this.client.delete(`${this.resourceUrl}/${fileName}`);
}
}
15 changes: 6 additions & 9 deletions src/api/orders/discounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ export default class OrderDiscounts {
this.client = client;
}

create(order_id, data) {
return this.client.post(`/orders/${order_id}/discounts`, data);
create(orderId, data) {
return this.client.post(`/orders/${orderId}/discounts`, data);
}

update(order_id, discount_id, data) {
return this.client.put(
`/orders/${order_id}/discounts/${discount_id}`,
data
);
update(orderId, discountId, data) {
return this.client.put(`/orders/${orderId}/discounts/${discountId}`, data);
}

delete(order_id, discount_id) {
return this.client.delete(`/orders/${order_id}/discounts/${discount_id}`);
delete(orderId, discountId) {
return this.client.delete(`/orders/${orderId}/discounts/${discountId}`);
}
}
12 changes: 6 additions & 6 deletions src/api/orders/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ export default class OrderItems {
this.client = client;
}

create(order_id, data) {
return this.client.post(`/orders/${order_id}/items`, data);
create(orderId, data) {
return this.client.post(`/orders/${orderId}/items`, data);
}

update(order_id, item_id, data) {
return this.client.put(`/orders/${order_id}/items/${item_id}`, data);
update(orderId, itemId, data) {
return this.client.put(`/orders/${orderId}/items/${itemId}`, data);
}

delete(order_id, item_id) {
return this.client.delete(`/orders/${order_id}/items/${item_id}`);
delete(orderId, itemId) {
return this.client.delete(`/orders/${orderId}/items/${itemId}`);
}
}
53 changes: 31 additions & 22 deletions src/api/orders/orders.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,62 @@
export default class Orders {
constructor(client) {
this.client = client;
this.resourceUrl = '/orders';
}

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

retrieve(order_id, filter) {
return this.client.get(`/orders/${order_id}`, filter);
retrieve(orderId, filter) {
return this.client.get(`${this.resourceUrl}/${orderId}`, filter);
}

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

update(order_id, data) {
return this.client.put(`/orders/${order_id}`, data);
update(orderId, data) {
return this.client.put(`${this.resourceUrl}/${orderId}`, data);
}

delete(order_id) {
return this.client.delete(`/orders/${order_id}`);
delete(orderId) {
return this.client.delete(`${this.resourceUrl}/${orderId}`);
}

recalculate(order_id) {
return this.client.put(`/orders/${order_id}/recalculate`);
recalculate(orderId) {
return this.client.put(`${this.resourceUrl}/${orderId}/recalculate`);
}

checkout(order_id) {
return this.client.put(`/orders/${order_id}/checkout`);
checkout(orderId) {
return this.client.put(`${this.resourceUrl}/${orderId}/checkout`);
}

cancel(order_id) {
return this.client.put(`/orders/${order_id}/cancel`);
cancel(orderId) {
return this.client.put(`${this.resourceUrl}/${orderId}/cancel`);
}

close(order_id) {
return this.client.put(`/orders/${order_id}/close`);
close(orderId) {
return this.client.put(`${this.resourceUrl}/${orderId}/close`);
}

updateBillingAddress(order_id, address) {
return this.client.put(`/orders/${order_id}/billing_address`, address);
updateBillingAddress(orderId, address) {
return this.client.put(
`${this.resourceUrl}/${orderId}/billing_address`,
address
);
}

updateShippingAddress(order_id, address) {
return this.client.put(`/orders/${order_id}/shipping_address`, address);
updateShippingAddress(orderId, address) {
return this.client.put(
`${this.resourceUrl}/${orderId}/shipping_address`,
address
);
}

getPaymentFormSettings(order_id) {
return this.client.get(`/orders/${order_id}/payment_form_settings`);
getPaymentFormSettings(orderId) {
return this.client.get(
`${this.resourceUrl}/${orderId}/payment_form_settings`
);
}
}
11 changes: 6 additions & 5 deletions src/api/orders/statuses.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
export default class OrderStatuses {
constructor(client) {
this.client = client;
this.resourceUrl = '/order_statuses';
}

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

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

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

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

delete(id) {
return this.client.delete(`/order_statuses/${id}`);
return this.client.delete(`${this.resourceUrl}/${id}`);
}
}
12 changes: 6 additions & 6 deletions src/api/orders/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ export default class OrderTransactions {
this.client = client;
}

create(order_id, data) {
return this.client.post(`/orders/${order_id}/transactions`, data);
create(orderId, data) {
return this.client.post(`/orders/${orderId}/transactions`, data);
}

update(customer_id, transaction_id, data) {
update(orderId, transactionId, data) {
return this.client.put(
`/orders/${order_id}/transactions/${transaction_id}`,
`/orders/${orderId}/transactions/${transactionId}`,
data
);
}

delete(order_id, transaction_id) {
delete(orderId, transactionId) {
return this.client.delete(
`/orders/${order_id}/transactions/${transaction_id}`
`/orders/${orderId}/transactions/${transactionId}`
);
}
}

0 comments on commit 196a06e

Please sign in to comment.