-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
49 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import rp from 'request-promise-native' | ||
const jarRequest = rp.defaults({jar: true}) | ||
|
||
const authenticate = async ({email, password}) => { | ||
const form = { | ||
'login_email': email, | ||
'login_password': password, | ||
'do_login': 'LOGIN' | ||
} | ||
|
||
// Login | ||
await jarRequest.post({ uri: 'http://app.trackpin.com/', form }) | ||
} | ||
|
||
export default authenticate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
import request from 'request' | ||
import cheerio from 'cheerio' | ||
import rp from 'request-promise-native' | ||
import authenticate from './authenticate' | ||
const jarRequest = rp.defaults({jar: true}) | ||
|
||
const jarRequest = request.defaults({jar: true}) | ||
const checkDoorStatus = async (credentials) => { | ||
await authenticate(credentials) | ||
|
||
const checkDoorStatus = ({email, password}) => { | ||
return new Promise(resolve => { | ||
const formData = { | ||
'login_email': email, | ||
'login_password': password, | ||
'do_login': 'LOGIN' | ||
} | ||
const options = { | ||
uri: 'http://app.trackpin.com/index.php/app/main', | ||
transform: body => cheerio.load(body) | ||
} | ||
|
||
jarRequest.post({url: 'http://app.trackpin.com/', form: formData}, | ||
(error, response) => { | ||
if (!error && response.statusCode === 200) { | ||
jarRequest.get('http://app.trackpin.com/index.php/app/main', (e, r, b) => { | ||
const $ = cheerio.load(b) | ||
const status = $('#door_status b').text() | ||
const lastPin = $('td.activity_title').first().contents().get(0).data | ||
resolve({status, lastPin}) | ||
}) | ||
} | ||
}) | ||
}) | ||
// Get data | ||
const $ = await jarRequest.get(options) | ||
const status = $('#door_status b').text() | ||
const lastPin = $('td.activity_title').first().contents().get(0).data | ||
return {status, lastPin} | ||
} | ||
|
||
export default checkDoorStatus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,25 @@ | ||
import request from 'request' | ||
import rp from 'request-promise-native' | ||
import cheerio from 'cheerio' | ||
import authenticate from './authenticate' | ||
|
||
const jarRequest = request.defaults({jar: true}) | ||
const jarRequest = rp.defaults({jar: true}) | ||
|
||
const listPins = ({email, password}) => { | ||
return new Promise(resolve => { | ||
const formData = { | ||
'login_email': email, | ||
'login_password': password, | ||
'do_login': 'LOGIN' | ||
} | ||
const listPins = async (credentials) => { | ||
await authenticate(credentials) | ||
|
||
jarRequest.post({url: 'http://app.trackpin.com/', form: formData}, | ||
(error, response) => { | ||
if (!error && response.statusCode === 200) { | ||
jarRequest.get('http://app.trackpin.com/index.php/app/pins', (e, r, b) => { | ||
const $ = cheerio.load(b) | ||
const result = $('td.pin_title') | ||
.contents() | ||
.map((i, el) => el.data) | ||
.filter((i, pin) => pin !== 'Remotes') | ||
resolve(result) | ||
}) | ||
} | ||
}) | ||
}) | ||
const options = { | ||
uri: 'http://app.trackpin.com/index.php/app/pins', | ||
transform: body => cheerio.load(body) | ||
} | ||
|
||
// Get data | ||
const $ = await jarRequest.get(options) | ||
// parse out the pin titles and remove "Remotes" | ||
const result = $('td.pin_title') | ||
.contents() | ||
.map((i, el) => el.data) | ||
.filter((i, pin) => pin !== 'Remotes') | ||
return result | ||
} | ||
|
||
export default listPins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters