Skip to content

Commit

Permalink
Changing method calls to be less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
somentelucas committed Apr 16, 2018
1 parent 4b75f82 commit 6e28db8
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 204 deletions.
8 changes: 2 additions & 6 deletions lib/resources/account.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import api from '../client/api'

const create = (opts, account) => {
return api.post(opts, '/accounts', account)
}
const create = (opts, account) => api.post(opts, '/accounts', account)

const getOne = (opts, _id) => {
return api.get(opts, '/accounts', _id)
}
const getOne = (opts, _id) => api.get(opts, '/accounts', _id)

export default {
create,
Expand Down
16 changes: 4 additions & 12 deletions lib/resources/bankAccount.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import api from '../client/api'

const create = (opts, _id, bankAccount) => {
return api.post(opts, `/accounts/${_id}/bankaccounts`, bankAccount)
}
const create = (opts, _id, bankAccount) => api.post(opts, `/accounts/${_id}/bankaccounts`, bankAccount)

const getOne = (opts, _id) => {
return api.get(opts, '/bankaccounts', _id)
}
const getOne = (opts, _id) => api.get(opts, '/bankaccounts', _id)

const getAll = (opts, _id) => {
return api.get(opts, `/accounts/${_id}/bankaccounts`)
}
const getAll = (opts, _id) => api.get(opts, `/accounts/${_id}/bankaccounts`)

const remove = (opts, _id) => {
return api.remove(opts, `/bankaccounts/${_id}`)
}
const remove = (opts, _id) => api.remove(opts, `/bankaccounts/${_id}`)

export default {
create,
Expand Down
4 changes: 1 addition & 3 deletions lib/resources/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ const getAuthorizeUrl = (opts, {clientId, redirectUri, scopes}) => {
})
}

const generateToken = (opts, config) => {
return api.post(opts, null, snakeCaseKeys(config), {customUrl: endpoints[opts.env].v2.generateTokenUrl, form: true})
}
const generateToken = (opts, config) => api.post(opts, null, snakeCaseKeys(config), {customUrl: endpoints[opts.env].v2.generateTokenUrl, form: true})

export default {
getAuthorizeUrl,
Expand Down
24 changes: 6 additions & 18 deletions lib/resources/coupon.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import api from '../client/api_assinaturas'

const getOne = (opts, _code) => {
return api.get(opts, `/coupons/${_code}`)
}
const getOne = (opts, _code) => api.get(opts, `/coupons/${_code}`)

const getAll = (opts) => {
return api.get(opts, '/coupons')
}
const getAll = (opts) => api.get(opts, '/coupons')

const create = (opts, coupon) => {
return api.post(opts, '/coupons', coupon)
}
const create = (opts, coupon) => api.post(opts, '/coupons', coupon)

const associate = (opts, _code, coupon) => {
return api.put(opts, `/subscriptions/${_code}`, coupon)
}
const associate = (opts, _code, coupon) => api.put(opts, `/subscriptions/${_code}`, coupon)

const activate = (opts, _code) => {
return api.put(opts, `/coupons/${_code}/active`)
}
const activate = (opts, _code) => api.put(opts, `/coupons/${_code}/active`)

const inactivate = (opts, _code) => {
return api.put(opts, `/coupons/${_code}/inactive`)
}
const inactivate = (opts, _code) => api.put(opts, `/coupons/${_code}/inactive`)

export default {
getOne,
Expand Down
20 changes: 5 additions & 15 deletions lib/resources/customer.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import api from '../client/api'

const getOne = (opts, _id) => {
return api.get(opts, '/customers', _id)
}
const getOne = (opts, _id) => api.get(opts, '/customers', _id)

const getAll = (opts) => {
return api.get(opts, '/customers')
}
const getAll = (opts) => api.get(opts, '/customers')

const create = (opts, customer) => {
return api.post(opts, '/customers', customer)
}
const create = (opts, customer) => api.post(opts, '/customers', customer)

const createCreditCard = (opts, _id, creditCard) => {
return api.post(opts, `/customers/${_id}/fundinginstruments`, creditCard)
}
const createCreditCard = (opts, _id, creditCard) => api.post(opts, `/customers/${_id}/fundinginstruments`, creditCard)

const removeCreditCard = (opts, _id) => {
return api.remove(opts, `/fundinginstruments/${_id}`)
}
const removeCreditCard = (opts, _id) => api.remove(opts, `/fundinginstruments/${_id}`)

export default {
getOne,
Expand Down
4 changes: 1 addition & 3 deletions lib/resources/escrow.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import api from '../client/api'

const release = (opts, _id) => {
return api.post(opts, `/escrows/${_id}/release`, null)
}
const release = (opts, _id) => api.post(opts, `/escrows/${_id}/release`, null)

export default {
release
Expand Down
8 changes: 2 additions & 6 deletions lib/resources/multiorder.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import api from '../client/api'

const getOne = (opts, _id) => {
return api.get(opts, '/multiorders', _id)
}
const getOne = (opts, _id) => api.get(opts, '/multiorders', _id)

const create = (opts, multiorder) => {
return api.post(opts, '/multiorders', multiorder)
}
const create = (opts, multiorder) => api.post(opts, '/multiorders', multiorder)

export default {
getOne,
Expand Down
16 changes: 4 additions & 12 deletions lib/resources/multipayment.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import api from '../client/api'

const getOne = (opts, _id) => {
return api.get(opts, '/multipayments', _id)
}
const getOne = (opts, _id) => api.get(opts, '/multipayments', _id)

const create = (opts, multiorderId, multipayment) => {
return api.post(opts, `/multiorders/${multiorderId}/multipayments`, multipayment)
}
const create = (opts, multiorderId, multipayment) => api.post(opts, `/multiorders/${multiorderId}/multipayments`, multipayment)

const preAuthorizationCapture = (opts, _id) => {
return api.post(opts, `/multipayments/${_id}/capture`)
}
const preAuthorizationCapture = (opts, _id) => api.post(opts, `/multipayments/${_id}/capture`)

const preAuthorizationCancel = (opts, _id) => {
return api.post(opts, `/multipayments/${_id}/void`)
}
const preAuthorizationCancel = (opts, _id) => api.post(opts, `/multipayments/${_id}/void`)

export default {
getOne,
Expand Down
16 changes: 4 additions & 12 deletions lib/resources/notification.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import api from '../client/api'

const getOne = (opts, _id) => {
return api.get(opts, '/preferences/notifications', _id)
}
const getOne = (opts, _id) => api.get(opts, '/preferences/notifications', _id)

const getAll = (opts) => {
return api.get(opts, '/preferences/notifications')
}
const getAll = (opts) => api.get(opts, '/preferences/notifications')

const create = (opts, preferences) => {
return api.post(opts, '/preferences/notifications', preferences)
}
const create = (opts, preferences) => api.post(opts, '/preferences/notifications', preferences)

const remove = (opts, _id) => {
return api.remove(opts, `/preferences/notifications/${_id}`)
}
const remove = (opts, _id) => api.remove(opts, `/preferences/notifications/${_id}`)

export default {
getOne,
Expand Down
20 changes: 5 additions & 15 deletions lib/resources/order.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import api from '../client/api'

const getOne = (opts, _id) => {
return api.get(opts, '/orders', _id)
}
const getOne = (opts, _id) => api.get(opts, '/orders', _id)

const getAll = (opts) => {
return api.get(opts, '/orders')
}
const getAll = (opts) => api.get(opts, '/orders')

const create = (opts, order) => {
return api.post(opts, '/orders', order)
}
const create = (opts, order) => api.post(opts, '/orders', order)

const refund = (opts, _id, method) => {
return api.post(opts, `/orders/${_id}/refunds`, method || null)
}
const refund = (opts, _id, method) => api.post(opts, `/orders/${_id}/refunds`, method || null)

const getRefunds = (opts, _id) => {
return api.get(opts, `/orders/${_id}/refunds`)
}
const getRefunds = (opts, _id) => api.get(opts, `/orders/${_id}/refunds`)

export default {
getOne,
Expand Down
28 changes: 7 additions & 21 deletions lib/resources/payment.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
import api from '../client/api'
import endpoints from '../client/endpoints'

const getOne = (opts, _id) => {
return api.get(opts, '/payments', _id)
}
const getOne = (opts, _id) => api.get(opts, '/payments', _id)

const create = (opts, orderId, payment) => {
return api.post(opts, `/orders/${orderId}/payments`, payment)
}
const create = (opts, orderId, payment) => api.post(opts, `/orders/${orderId}/payments`, payment)

const preAuthorizationCapture = (opts, _id) => {
return api.post(opts, `/payments/${_id}/capture`)
}
const preAuthorizationCapture = (opts, _id) => api.post(opts, `/payments/${_id}/capture`)

const preAuthorizationCancel = (opts, _id) => {
return api.post(opts, `/payments/${_id}/void`)
}
const preAuthorizationCancel = (opts, _id) => api.post(opts, `/payments/${_id}/void`)

const _authorize = function (opts, _id, amount) {
return api.get(opts, null, null, {customUrl: `${endpoints.sandbox.v2.authorizePaymentSimulationUrl}?payment_id=${_id}&amount${amount}`})
}
const _authorize = (opts, _id, amount) => api.get(opts, null, null, {customUrl: `${endpoints.sandbox.v2.authorizePaymentSimulationUrl}?payment_id=${_id}&amount${amount}`})

const refund = (opts, _id) => {
return api.post(opts, `/payments/${_id}/refunds`)
}
const refund = (opts, _id) => api.post(opts, `/payments/${_id}/refunds`)

const getRefunds = (opts, _id) => {
return api.get(opts, `/payments/${_id}/refunds`)
}
const getRefunds = (opts, _id) => api.get(opts, `/payments/${_id}/refunds`)

export default {
getOne,
Expand Down
24 changes: 6 additions & 18 deletions lib/resources/plan.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import api from '../client/api_assinaturas'

const getOne = (opts, _code) => {
return api.get(opts, `/plans/${_code}`)
}
const getOne = (opts, _code) => api.get(opts, `/plans/${_code}`)

const getAll = (opts) => {
return api.get(opts, '/plans')
}
const getAll = (opts) => api.get(opts, '/plans')

const create = (opts, plan) => {
return api.post(opts, '/plans', plan)
}
const create = (opts, plan) => api.post(opts, '/plans', plan)

const activate = (opts, _code) => {
return api.put(opts, `/plans/${_code}/activate`)
}
const activate = (opts, _code) => api.put(opts, `/plans/${_code}/activate`)

const inactivate = (opts, _code) => {
return api.put(opts, `/plans/${_code}/inactivate`)
}
const inactivate = (opts, _code) => api.put(opts, `/plans/${_code}/inactivate`)

const update = (opts, _code, plan) => {
return api.put(opts, `/plans/${_code}`, plan)
}
const update = (opts, _code, plan) => api.put(opts, `/plans/${_code}`, plan)

export default {
getOne,
Expand Down
4 changes: 1 addition & 3 deletions lib/resources/refund.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import api from '../client/api'

const get = (opts, _id) => {
return api.get(opts, '/refunds', _id)
}
const get = (opts, _id) => api.get(opts, '/refunds', _id)

export default {
get
Expand Down
20 changes: 5 additions & 15 deletions lib/resources/subscriber.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import api from '../client/api_assinaturas'

const getOne = (opts, _code) => {
return api.get(opts, `/customers/${_code}`)
}
const getOne = (opts, _code) => api.get(opts, `/customers/${_code}`)

const getAll = (opts) => {
return api.get(opts, '/customers')
}
const getAll = (opts) => api.get(opts, '/customers')

const create = (opts, subscriber, config) => {
return api.post(opts, '/customers', subscriber, config)
}
const create = (opts, subscriber, config) => api.post(opts, '/customers', subscriber, config)

const update = (opts, _code, subscriber) => {
return api.put(opts, `/customers/${_code}`, subscriber)
}
const update = (opts, _code, subscriber) => api.put(opts, `/customers/${_code}`, subscriber)

const updateBilling = (opts, _code, billingInfo) => {
return api.put(opts, `/customers/${_code}/billing_infos`, billingInfo)
}
const updateBilling = (opts, _code, billingInfo) => api.put(opts, `/customers/${_code}/billing_infos`, billingInfo)

export default {
getOne,
Expand Down
Loading

0 comments on commit 6e28db8

Please sign in to comment.