Skip to content

Commit

Permalink
moved oauth to app.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan Leopold committed Jun 3, 2021
1 parent 40a8309 commit a1910bd
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 23 deletions.
4 changes: 1 addition & 3 deletions src/AirportInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class AirportInput extends Component {
},
})
.then(function (response) {

thisCom.setState({
airport: response.data.data[0]
}, () => {
Expand Down Expand Up @@ -70,10 +69,9 @@ class AirportInput extends Component {

}
}

handleOptionClick(event) {
event.target.parentNode.previousSibling.value = event.target.name;

this.setState({
airport: event.target.value
}, () => {
Expand Down
30 changes: 28 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import React, { Component } from "react";
import {Route, Link} from "react-router-dom"
import "./App.css";
import FlightForm from "./FlightForm";
import TestCall from './TestCall'
// import Login from "./Login"
// import CreateUser from "./CreateUser";
// import axios from "axios";
import axios from "axios";


class App extends Component {
Expand All @@ -14,6 +15,30 @@ class App extends Component {
airports: [],
markets: []
};
this.componentDidMount = this.componentDidMount.bind(this)
}


componentDidMount() {
// Begin API Access - Retrieving Token
let body = `grant_type=client_credentials&client_id=${process.env.REACT_APP_AMADEUS_KEY}&client_secret=${process.env.REACT_APP_AMADEUS_SECRET}`;
// let form = this

let app = this

axios({
method: 'post',
url: 'https://test.api.amadeus.com/v1/security/oauth2/token',
headers: {
"Content-Type":"application/x-www-form-urlencoded",
},
data: body
}).then( function(response) {
let token = response.data.access_token
app.setState({
oAuth: token
})
}).catch( err => console.log(err))
}

render() {
Expand All @@ -32,7 +57,8 @@ class App extends Component {
</div>
</header>
<div>
<Route path="/" exact render={ (routerProps) => <FlightForm {...routerProps}{...this.props}{...this.state}/> }></Route>
<Route path="/tester" exact render={ (routerProps) => <TestCall {...routerProps} {...this.props} {...this.state} />} ></Route>
<Route path="/" exact render={ (routerProps) => <FlightForm {...routerProps}{...this.props}{...this.state}/> } ></Route>
</div>
</div>
);
Expand Down
38 changes: 20 additions & 18 deletions src/FlightForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FlightForm extends Component {
locale: "en-US",
livePrice: "",
status: "",
oAuth: '',
// oAuth: '',
};

this.componentDidMount = this.componentDidMount.bind(this);
Expand Down Expand Up @@ -60,23 +60,23 @@ class FlightForm extends Component {
outboundDate: today
})

// Begin API Access - Retrieving Token
let body = `grant_type=client_credentials&client_id=${process.env.REACT_APP_AMADEUS_KEY}&client_secret=${process.env.REACT_APP_AMADEUS_SECRET}`;
let form = this

axios({
method: 'post',
url: 'https://test.api.amadeus.com/v1/security/oauth2/token',
headers: {
"Content-Type":"application/x-www-form-urlencoded",
},
data: body
}).then( function(response) {
let token = response.data.access_token
form.setState({
oAuth: token
})
}).catch( err => console.log(err))
// // Begin API Access - Retrieving Token
// let body = `grant_type=client_credentials&client_id=${process.env.REACT_APP_AMADEUS_KEY}&client_secret=${process.env.REACT_APP_AMADEUS_SECRET}`;
// let form = this

// axios({
// method: 'post',
// url: 'https://test.api.amadeus.com/v1/security/oauth2/token',
// headers: {
// "Content-Type":"application/x-www-form-urlencoded",
// },
// data: body
// }).then( function(response) {
// let token = response.data.access_token
// form.setState({
// oAuth: token
// })
// }).catch( err => console.log(err))

}

Expand Down Expand Up @@ -187,6 +187,7 @@ class FlightForm extends Component {
<AirportInput
name="originPlace"
className="inputBox dport"
{...this.props}
{...this.state}
handleAirportChange={this.handleAirportChange}
/>
Expand All @@ -196,6 +197,7 @@ class FlightForm extends Component {
<AirportInput
name="destinationPlace"
className="inputBox aport"
{...this.props}
{...this.state}
handleAirportChange={this.handleAirportChange}
/>
Expand Down
24 changes: 24 additions & 0 deletions src/TestCall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { useState } from "react";
import axios from "axios"

const TestCall = async () => {

// let testFlights = await axios({
// method: "get",
// url: `https://test.api.amadeus.com/v1/reference-data/locations?subType=AIRPORT&keyword=${event.target.value}`,
// headers: {
// "Content-Type": "application/x-www-form-urlencoded",
// Authorization: `Bearer ${this.props.oAuth}`,
// },
// })

return (
<div>

</div>
)

}


export default TestCall

0 comments on commit a1910bd

Please sign in to comment.