Skip to content

Commit

Permalink
🔥 Major Refactoring 💀
Browse files Browse the repository at this point in the history
  • Loading branch information
simov committed Apr 14, 2018
1 parent 783e1d0 commit 447f13d
Show file tree
Hide file tree
Showing 17 changed files with 650 additions and 299 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

language: node_js

node_js:
- 8

after_script:
- npm run test:cov
- cat ./coverage/lcov.info | coveralls

sudo: false
174 changes: 118 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,16 @@

# varnalab-notifier

```bash
node varnalab-notifier/bin/ \
--config /path/to/config.json \
--auth /path/to/auth.json \
--events /path/to/events.json \
--ids /path/to/ids.json \
--env environment \
--notify calendar,googlegroups,slack,twitter
```

## config.json
[![travis-ci]][travis] [![coveralls-status]][coveralls]

```json
{
"production": [
{
"notify": "calendar",
"target": "[email protected]",
"auth": "VarnaLab's Google Account",
"location": "VarnaLab, ul. \"Pencho Slaveykov\" 50, 9000 Varna Center, Varna, Bulgaria"
},
{
"notify": "calendar",
"target": "[email protected]",
"auth": "ITClubsBG Calendar",
"location": "VarnaLab, ul. \"Pencho Slaveykov\" 50, 9000 Varna Center, Varna, Bulgaria"
},
{
"notify": "googlegroups",
"target": "[email protected]",
"auth": "VarnaLab's Google Account",
"from": "VarnaLab <[email protected]>"
},
{
"notify": "slack",
"target": "[Incoming Webhook URL]"
},
{
"notify": "twitter",
"target": "varnalab",
"auth": "VarnaLab's Twitter Account"
}
]
}
```bash
node varnalab-notifier/bin/cli.js \
--auth /path/to/auth.json \
--targets /path/to/targets.json \
--events /path/to/events.json \
--ids /path/to/ids.json \
--env environment \
--notify calendar,googlegroups,slack,twitter
```

## auth.json
Expand All @@ -53,40 +19,53 @@ node varnalab-notifier/bin/ \
{
"production": [
{
"provider": "google",
"key": "",
"secret": "",
"app": {
"id": "39756e31-4ee4-49fa-9df6-12284fa2ed20",
"provider": "google",
"name": "",
"owner": "",
"url": "",
"key": "",
"secret": "",
"refresh": "https://accounts.google.com/o/oauth2/token"
},
"users": [
{
"id": "VarnaLab's Google Account",
"account": "[email protected]",
"id": "ce40dbf7-a519-488b-a817-84e0bc707c17",
"account": "",
"scope": [
"calendar",
"gmail.send"
],
"token": "",
"refresh": "",
"expires": 0
"expires": 1523279703510
},
{
"id": "ITClubsBG Calendar",
"account": "[email protected]",
"id": "0aee86db-ea01-4c03-b1ad-2de2f0028f78",
"account": "",
"scope": [
"calendar"
],
"token": "",
"refresh": "",
"expires": 0
"expires": 1523279703521
}
]
},
{
"provider": "twitter",
"key": "",
"secret": "",
"app": {
"id": "e8f1a920-a26c-466e-8538-9018c0f613c5",
"provider": "twitter",
"name": "",
"owner": "",
"url": "",
"key": "",
"secret": ""
},
"users": [
{
"id": "VarnaLab's Twitter Account",
"id": "fd8f7527-e980-4ebb-a316-73955b910308",
"account": "varnalab",
"token": "",
"secret": ""
Expand All @@ -97,6 +76,89 @@ node varnalab-notifier/bin/ \
}
```

## targets.json

```json
{
"production": [
{
"id": "495f1581-b299-40ae-92ef-6649e4247153",
"auth": "ce40dbf7-a519-488b-a817-84e0bc707c17",
"name": "calendar",
"url": "",
"options": {
"location": "VarnaLab, ul. \"Pencho Slaveykov\" 50, 9000 Varna Center, Varna, Bulgaria"
}
},
{
"id": "4173500f-8f2d-4705-acfd-882a35d6aa81",
"auth": "0aee86db-ea01-4c03-b1ad-2de2f0028f78",
"name": "calendar",
"url": "",
"options": {
"location": "VarnaLab, ul. \"Pencho Slaveykov\" 50, 9000 Varna Center, Varna, Bulgaria"
}
},
{
"id": "dbf7bf60-cb11-4d8e-a2b0-a3c245e76157",
"auth": "ce40dbf7-a519-488b-a817-84e0bc707c17",
"name": "googlegroups",
"url": "https://www.googleapis.com/gmail/v1/users/me/messages/send",
"options": {
"from": "VarnaLab <[email protected]>",
"to": ""
}
},
{
"id": "77d00ec9-2de7-4e3a-8093-c26c8d9d97b2",
"name": "slack",
"url": ""
},
{
"id": "55e5167a-210f-47e8-9f61-5c869af36e8a",
"name": "slack",
"url": ""
},
{
"id": "b563ee64-c937-4642-b93a-1d28203eff9c",
"auth": "fd8f7527-e980-4ebb-a316-73955b910308",
"name": "twitter",
"url": "https://api.twitter.com/1.1/statuses/update.json"
}
]
}
```

## events.json

```json
[
{
"id": "279858379218043",
"name": "Rails Girls Varna Study Group",
"description": "Поредната сбирка, на която ще решим и последните интересни задачи и започваме раотата с файлове.",
"cover_desktop": "https://scontent.xx.fbcdn.net/v/t1.0-9/30531162_10216131483541683_2327689505201371390_n.jpg?_nc_cat=0&oh=922fd2eb593791f37a699561d7895ce6&oe=5B66BD41",
"cover_mobile": "https://scontent.xx.fbcdn.net/v/t1.0-0/p320x320/30531162_10216131483541683_2327689505201371390_n.jpg?_nc_cat=0&oh=48411aa88bd88a84b17fda2d7afb1a7e&oe=5B5DF0F6",
"start_time": "2018-04-11T19:45:00+0300",
"end_time": "2018-04-11T21:45:00+0300",
"updated_time": "2018-04-09T11:58:57+0000"
}
]
```

## ids.json

```json
[
"1772476899717149",
"129396144458257",
"282498435569265"
]
```


[travis-ci]: https://img.shields.io/travis/VarnaLab/varnalab-notifier/master.svg?style=flat-square (Build Status - Travis CI)
[coveralls-status]: https://img.shields.io/coveralls/VarnaLab/varnalab-notifier.svg?style=flat-square (Test Coverage - Coveralls)

[travis]: https://travis-ci.org/VarnaLab/varnalab-notifier
[coveralls]: https://coveralls.io/github/VarnaLab/varnalab-notifier
73 changes: 73 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env node

var argv = require('minimist')(process.argv.slice(2))

if (argv.help) {
console.log(`
--auth /path/to/auth.json
--targets /path/to/targets.json
--events /path/to/events.json
--ids /path/to/ids.json
--env environment
--notify calendar,googlegroups,slack,twitter
`)
process.exit()
}

;['auth', 'targets', 'events', 'ids'].forEach((arg) => {
if (!argv[arg]) {
console.log(`Specify --${arg} /path/to/${arg}.json`)
process.exit()
}
})


var events = require(argv.events)
var ids = require(argv.ids)
var upcoming = events.filter((event) => !ids.includes(event.id))

if (!upcoming.length) {
process.exit()
}


// modified in auth.refresh
var auth = require(argv.auth)


var env = process.env.NODE_ENV || argv.env || 'development'

var targets = require(argv.targets)[env]
if (argv.notify) {
var input = argv.notify.split(',')
targets = targets.filter((target) => input.includes(target.notify))
}


var users = require('../utils/auth').users

require('../')({
auth: users({auth: auth[env]}),
targets,
events: upcoming,
})
.then((results) => {

var err = require('../utils/error')
var errors = err.filter(results)

errors.map((error) => console.error(err.message(error)))

var fs = require('fs')

if (results.length > errors.length) {
fs.writeFileSync(
argv.ids,
JSON.stringify(ids.concat(upcoming.map((event) => event.id)), null, 2),
'utf8'
)
}

fs.writeFileSync(argv.auth, JSON.stringify(auth, null, 2), 'utf8')
})
.catch(console.error)
83 changes: 0 additions & 83 deletions bin/index.js

This file was deleted.

Loading

0 comments on commit 447f13d

Please sign in to comment.