diff --git a/examples/example_centrifugo.py b/examples/example_centrifugo.py new file mode 100644 index 0000000..9597cab --- /dev/null +++ b/examples/example_centrifugo.py @@ -0,0 +1,26 @@ +from flask import Flask, redirect +from donationalerts_api import DonationAlertsApi, Centrifugo, Scopes, Channels + +app = Flask(__name__) +api = DonationAlertsApi("client id", "client secret", "http://127.0.0.1:5000/login", [Scopes.USER_SHOW, Scopes.DONATION_SUBSCRIBE]) + + +@app.route("/", methods=["get"]) +def index(): + return redirect(api.login()) # Log in your application + + +@app.route("/login", methods=["get"]) +def login(): + code = api.get_code() + access_token = api.get_access_token(code) + user = api.get_user(access_token) + + fugo = Centrifugo(user["socket_connection_token"], access_token, user["id"]) + fugo.connect() + fugo.subscribe(Channels.NEW_DONATION_ALERTS) + + return fugo.listen() + +if __name__ == "__main__": + app.run(debug=True) \ No newline at end of file diff --git a/examples/example_real_time.py b/examples/example_real_time.py new file mode 100644 index 0000000..e53ecda --- /dev/null +++ b/examples/example_real_time.py @@ -0,0 +1,7 @@ +from donationalerts_api import Alert + +alert = Alert("token") + +@alert.event() +def new_donation(event): + print(event) \ No newline at end of file diff --git a/examples/example_sample.py b/examples/example_sample.py new file mode 100644 index 0000000..9b1ba1d --- /dev/null +++ b/examples/example_sample.py @@ -0,0 +1,24 @@ +from flask import Flask, redirect +from donationalerts_api import DonationAlertsApi, Scopes + +app = Flask(__name__) +api = DonationAlertsApi("client id", "client secret", "http://127.0.0.1:5000/login", [Scopes.USER_SHOW, Scopes.DONATION_INDEX]) + + +@app.route("/", methods=["get"]) +def index(): + return redirect(api.login()) # Log in your application + + +@app.route("/login", methods=["get"]) +def login(): + code = api.get_code() + access_token = api.get_access_token(code) + + user = api.get_user(access_token) + donation_list = api.get_donations(access_token) + + return user + +if __name__ == "__main__": + app.run(debug=True) \ No newline at end of file