Skip to content

Instantly share code, notes, and snippets.

View nfarah86's full-sized avatar

nadine farah nfarah86

View GitHub Profile
@nfarah86
nfarah86 / rescue.py
Created May 6, 2016 22:05
Triggering the login()
@app.route("/")
def login():
#@"http://rescue-nfh.herokuapp.com/update_run"
return render_template("login.html")
@nfarah86
nfarah86 / rescue.py
Created May 6, 2016 22:10
Processing Login Information
// omitted code
@app.route("/process_login", methods=["POST"])
def process_login():
#user should be in db, so .get
user_name = request.form.get("user_name")
password = request.form.get("password")
email = request.form.get("email")
#going to search db for user_name and password
user = db_session.query(User).filter_by(
@nfarah86
nfarah86 / rescue.py
Last active May 7, 2016 00:38
iOS App Makes an API Call to /update_run
// omitted code
@app.route("/update_run", methods = ['POST'])
def update_run():
if not request.json["user_name"]:
return json.dumps({ 'error': True })
user_name = request.json['user_name'] #getting from iphone
password = request.json['password'] #getting from iphone
email = request.json['email'] #getting from iphone
@nfarah86
nfarah86 / BeanDetailViewController.m
Created May 7, 2016 01:34
Store GPS coordinates in the Database
// omitted code
-(void)timerDidFire: (id)sender {
NFHLocationManager *locationManager = [NFHLocationManager sharedLocationManager];
if(locationManager.updating) {
CLLocation *location = [locationManager lastLocation];
[self updateInterfaceWithLocation:location];
// BELOW - we send the coordinates to /update_run to the database in the web app
[[NFHWebServiceManager sharedWebServiceManager]sendUpdateRunRequestWithLocation:location];
@nfarah86
nfarah86 / BeanDetailViewController.m
Created May 7, 2016 01:34
Store GPS coordinates in the Database
// omitted code
-(void)timerDidFire: (id)sender {
NFHLocationManager *locationManager = [NFHLocationManager sharedLocationManager];
if(locationManager.updating) {
CLLocation *location = [locationManager lastLocation];
[self updateInterfaceWithLocation:location];
// BELOW - we send the coordinates to /update_run to the database in the web app
[[NFHWebServiceManager sharedWebServiceManager]sendUpdateRunRequestWithLocation:location];
@nfarah86
nfarah86 / NFHWebServiceManager.m
Created May 7, 2016 01:38
Send Coordinates to \update_run
// omitted code
- (void)sendUpdateRunRequestWithLocation:(CLLocation *)location
{
CLLocationCoordinate2D coordinate = [location coordinate];
//accuracy is important
CLLocationAccuracy accuracy = location.horizontalAccuracy;
//my database in server has a created (timestamp)
// invert time b/c comes out to (-)
//distinguish between bad and good cordinates by setting parameters
if(location!=nil&&accuracy>0
@nfarah86
nfarah86 / rescue.py
Last active May 7, 2016 01:54
Get User's GPS Location
// omitted code
@app.route("/contact_map_display/<user_id>", methods = ['GET'])
def contact_map_display():
user_object = db_session.query(GPS_Location).filter_by(user_id=user_id).order_by(GPS_Location.created.desc()).first()
return render_template("contact_map.html", user_id = user_object.user_id)
// omitted code
@nfarah86
nfarah86 / BeanDetailViewController.m
Created May 7, 2016 03:46
Pushing the Button Triggers Different End Points
// omitted code
-(void)bean:(PTDBean*)bean serialDataReceived:(NSData*)data
{
NSString *receivedMessage=[[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding];
NSLog (@"%@ this works", receivedMessage);
NFHLocationManager *locationManager = [NFHLocationManager sharedLocationManager];
NFHWebServiceManager *webServiceManager = [NFHWebServiceManager sharedWebServiceManager];
@nfarah86
nfarah86 / NFHWebServiceManager.m
Created May 7, 2016 03:49
iOS App Makes a Request to the Server
// omitted code
-(void)sendEmergencyRequest;
{
NSMutableDictionary * dictOfCredentials = [[NSMutableDictionary alloc]init];
NSURL *url = [NSURL URLWithString:@"http://rescue-nfh.herokuapp.com/emergency_run"]; //URL refer to hostName
[self sendRequestToURL:url requestBody:dictOfCredentials];
}
// omitted code
@nfarah86
nfarah86 / rescue.py
Created May 7, 2016 03:52
Emergency Run End Point
// omitted code
@app.route("/emergency_run", methods = ['POST'])
def emergency_message():
textMessage("I have an emergency and need help. Please find me here: http://rescue-nfh.herokuapp.com/contact_map_display")
return json.dumps({ 'success': True })
// omitted code