Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

criacao de nomes mais rest flavored #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions application-dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# coding: utf-8
from __future__ import absolute_import

from flask import current_app, Flask

import postmon_correios

app = Flask(__name__)
app.debug = True
postmon_correios.init_app(app)

@app.route('/crossdomain.xml')
def crossdomain():
return current_app.send_static_file('crossdomain.xml')
return app
2 changes: 1 addition & 1 deletion application.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def create_app():
def crossdomain():
return current_app.send_static_file('crossdomain.xml')

return app
return app
28 changes: 28 additions & 0 deletions postmon_correios/rastreamento.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import absolute_import

from flask import Blueprint, render_template
from flask import jsonify,request

from .correios import correios_client
from .utils import get_objetos
Expand All @@ -27,6 +28,33 @@ def index():

return render_template(template, objeto=objeto), status_code

@bp.route("/objeto/<codigo>")
def getObjeto(codigo):
codigoObjeto = codigo
objetos, _redirect = get_objetos()
if _redirect:
return _redirect

response = correios_client.buscaEventos(codigoObjeto)
objeto = response["objeto"][0]
objetoVO = {}
if objeto.get("evento"):
status_code = 200
else:
status_code = 404
return jsonify(objeto), status_code
#return render_template(template, objeto=objeto), status_code

@bp.route('/objetos', methods=['POST'])
def getObjetos():
data = request.get_json()
objetos = []
for item in data:
print item['codigo']
response = correios_client.buscaEventos(item['codigo'])
objeto = response["objeto"][0]
objetos.append(objeto)
return jsonify(objetos)

def init_app(app, url_prefix=None):
app.register_blueprint(bp, url_prefix=url_prefix)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==0.12.3
Flask==0.12.4
Flask-Cors==3.0.2
zeep==2.5.0