GithubHelp home page GithubHelp logo

mobile-backend's Introduction

Mobile-backend

Backend for HTN iOS and Android app.

Usage

There are two ways of interacting with the datastore: issuing an update, and modifying the static datastore.

Issuing Updates

Manual

This is the mechanism for issuing live updates to all users of the application. There is a script set up to do all the required steps; all that you have to do is configure the system and run the script.

Fortunately, we have an amazon EC2 instance set up with all the configuration details (though it is documented below anyways). Contact @srcreigh for information on how to access this machine.

Once you connect to the instance via ssh, you can just go to this repository on the machine and run the script:

cd mobile-backend
python issue-update.py

This will guide you through entering the name (i.e. title), text (i.e. body text), and an optional image url which will be circle-cropped and displayed as an avatar.

Scheduled

Create a json file with the following spec:

[
  {
    "time": "2014-09-19T22:00:00", // 10pm on friday
    "title": "Hacker Life Workshop",
    "body": "Come out to DC 1302 for a talk about how to be a hacker fulltime!",
    "image": "http://foo.bar.com/image.png" // can be null
  } ...
]

Then, you can run /schedule-updates.py [your-json-file] & to start a python process that will issue the updates at the scheduled time. Make sure to run this on the EC2 instance, so that they don't get cancelled.

Updating Firebase

The data from the app is loaded from Firebase, at https://hackthenorth.firebaseio.com/mobile. There is a data point for each of the tabs in each app:

/updates, /schedule, /prizes, /mentors, /team, and /sponsors.

Note: do not interact with the /updates information manually; use the issue-update.py script as explained above.

If you have access to the Firebase Forge for hackthenorth, then you can use that to add data or modify points. There is data in the datastore currently that can serve as examples for required fields, datetime formatting conventions, etc. This is the easiest option for easy editing and adding of data. Otherwise, you will have to use some other API to interact with firebase.

Be careful...

  • Know the difference between post, put, and patch requests when working with firebase.

Interacting with Firebase

For quick and dirty operations, it's easy enough to start a python repl in the root of this repository:

$ cd mobile-backend/
$ python

>>> # note: this is untested
>>> from src.login import *
>>> import requests
>>> import json
>>> FIREBASE_URL
'https://hackthenorth.firebaseio.com/mobile'
>>> FIREBASE_SECRET
[ secret ]
>>> r = requests.patch('%s/team.json', data=json.dumps({'abc123':{'name':'Shane'}}), params={'auth':FIREBASE_SECRET'})

Otherwise, you should write a python script. The requests will be analogous to the repl.

Install

sudo pip install -r requirements.txt

Then, create a file src/login.py, with the following contents:

#!/bin/python

FIREBASE_SECRET="[firebase secret here]"
GCM_API_KEY="[gcm api key here]"

# Not really secret, but these are configuration options too:
FIREBASE_URL="https://your-firebase.firebaseio.com"
CONFIG_PATH="~/.htn-mobile-backend"

Note that you must have your IP address on the whitelist in the Google Developers Console to send updates via GCM.

mobile-backend's People

Contributors

kartiktalwar avatar srcreigh avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mobile-backend's Issues

The GCM whitelist will be annoying if we're making requests locally...

So, the GCM API key that we're given only works for whitelisted IP addresses. So, like, we have to add every admin's IP address to the whitelist, and if they move and get a new IP then it'll break. Depending on how much you value things just working and how many admins we have using these scripts, this can just be a minor annoyance, or something that we have to fix. If we only have one or two people using these scripts it's probably not worth the effort to set something up, they'll just have to log in to the dashboard and add their ip.

In case it's something we have to fix, I'm trying to think of a way to let people use this script without having to add their IP address to the GCM whitelist. If we had a canonical admin computer that is accessible via ssh or something, then we can just have everyone run the scripts via ssh or something. I think we might be able to get something like this from the CSC.

Anyway, if anyone else has any ideas, that'd be great.

Transition to real production backend

@KartikTalwar

Here's a breakdown of the schema as I see it:

/mobile/gcm

  • Just a list of strings:
{
  "abc123": "dummy",
  "def456": "dummy", ...
}
  • Public writes (set it to disallow deleting though)
  • Secret-only reads

/mobile/mentors, /mobile/team, /mobile/updates, /mobile/schedule, /mobile/prizes

  • List of objects as specified here
  • Public reads
  • Secret-only writes

/mobile/test

  • just a string:
"DO NOT DELETE; used for testing"
  • Secret-reads and writes
  • used for testing the scripts

CR for the current updates script

@hackthenorth/commiters @snario

The code I've written to write updates to Firebase and send off notifications to users via GCM is mostly finished, except for a few TODOs for GCM and the fact that we don't have automated tests yet.

It'd be sweet if someone could read it over. Any feedback is welcome, but mostly I just want to make sure that there isn't anything that doesn't make sense, even if you don't know how GCM works.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.