Skip to content
Permalink
Browse files

Use secure cloud retrieval for coupon code

  • Loading branch information...
bkimminich committed Feb 20, 2019
1 parent d961ca3 commit fde2003535598ad3c4edc17ad9ffcdc9c589d3c5
Showing with 462 additions and 216 deletions.
  1. +0 −1 index.js
  2. +9 −12 lib/couponCode.js
  3. +3 −3 lib/statusText.js
  4. +442 −146 package-lock.json
  5. +2 −2 package.json
  6. +0 −28 test/couponCode-spec.js
  7. 0 test/index-spec.js
  8. +6 −24 test/statusText-spec.js
@@ -9,7 +9,6 @@ const T = new Twitter({
const statusText = require('./lib/statusText')

module.exports = (status = statusText()) => {
console.log()
console.log(`[${colors.green('')}] Status prepared: ${colors.cyan(status)}`)
if (process.env.TRAVIS_EVENT_TYPE === 'cron') {
T.post('statuses/update', { status })
@@ -1,14 +1,11 @@
const z85 = require('z85')
const request = require('sync-request')

const months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']

function toMMMYY (date) {
const month = date.getMonth()
const year = date.getFullYear()
return months[month] + year.toString().substring(2, 4)
}

module.exports = (discount, date = new Date()) => {
const coupon = toMMMYY(date) + '-' + discount
return z85.encode(coupon)
module.exports = (discount) => {
var res = request('GET', 'https://5j4d1u7jhf.execute-api.eu-west-1.amazonaws.com/default/JuicyCouponFunc')
if (res.statusCode > 200) {
throw new Error(`AWS lookup failed with HTTP error ${res.statusCode}`)
} else {
const coupons = JSON.parse(res.body)
return coupons[(discount / 10) - 1]
}
}
@@ -2,9 +2,9 @@ const couponCode = require('./couponCode')
const expirationDate = require('./expirationDate')
const randomDiscount = require('./randomDiscount')

module.exports = (discount = randomDiscount(), date = new Date()) => {
const coupon = couponCode(discount, date)
const expiration = expirationDate(date)
module.exports = (discount = randomDiscount()) => {
const coupon = couponCode(discount)
const expiration = expirationDate(new Date())

const texts = [
`[🤖] Enjoy ${discount}% off all our juicy products with this #coupon code: ${coupon} (valid until ${expiration})`,
Oops, something went wrong.

0 comments on commit fde2003

Please sign in to comment.
You can’t perform that action at this time.