Add basic component for calls to traffic disruption API
This commit is contained in:
parent
e35524fa19
commit
c3edd2d74f
60
src/components/Disruption.js
Normal file
60
src/components/Disruption.js
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import axios from 'axios';
|
||||||
|
import AccessToken from '../classes/AccessToken'
|
||||||
|
|
||||||
|
class Diruption extends React.Component {
|
||||||
|
state = {
|
||||||
|
gid: '9022014005700002',
|
||||||
|
disruptions: [],
|
||||||
|
token: undefined,
|
||||||
|
tokenClass: new AccessToken()
|
||||||
|
}
|
||||||
|
|
||||||
|
handleChangeGid = event => {
|
||||||
|
this.setState({ lat: event.target.value});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSubmit = event => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
'Authorization': 'Bearer ' + this.state.tokenClass.token
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('Attempted connection')
|
||||||
|
|
||||||
|
axios.get('https://api.vasttrafik.se/ts/v1/traffic-situations/stoppoint/'+this.state.gid, { headers })
|
||||||
|
//axios.get('https://api.vasttrafik.se/ts/v1/traffic-situations/stoppoint/9022014005700002', { headers })
|
||||||
|
.then(response => {
|
||||||
|
console.log(response)
|
||||||
|
this.setState({
|
||||||
|
disruptions: response.data
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<form onSubmit={this.handleSubmit}>
|
||||||
|
<label>
|
||||||
|
Stoppoint Gid:
|
||||||
|
<input type="text" name="gid" onChange={this.handleChangeGid} />
|
||||||
|
</label>
|
||||||
|
<button type="submit">Find traffic disruptions</button>
|
||||||
|
</form>
|
||||||
|
<h1>
|
||||||
|
{this.state.gid}
|
||||||
|
</h1>
|
||||||
|
{this.state.disruptions.map((item) =>
|
||||||
|
<div>
|
||||||
|
<h1>
|
||||||
|
{item.description}
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default Diruption
|
@ -73,17 +73,3 @@ class NearbyStation extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default NearbyStation
|
export default NearbyStation
|
||||||
|
|
||||||
//https://api.vasttrafik.se/bin/rest.exe/v2/location.nearbystops?originCoordLat=57.5987&originCoordLong=11.9454&maxNo=20&format=json
|
|
||||||
|
|
||||||
//https://api.vasttrafik.se/bin/rest.exe/v2/location.nearbystops
|
|
||||||
|
|
||||||
|
|
||||||
//'https://reqres.in/api/articles'
|
|
||||||
|
|
||||||
//'https://api.vasttrafik.se/token'
|
|
||||||
|
|
||||||
//grant_type=client_credentials&scope=<device_id>
|
|
||||||
|
|
||||||
//BPvMjPidHckBtETZxr3dHP1rptQa
|
|
||||||
//z5MFCS_wwmqprc0s4iLZWBAUJdga
|
|
Loading…
Reference in New Issue
Block a user