Skip to content

Commit a8ffe71

Browse files
authored
Merge pull request #5 from feliphebueno/Correcoes
Correções diversas
2 parents e6bfa5b + bbe15a6 commit a8ffe71

4 files changed

Lines changed: 102 additions & 14 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Version 1.15.1:
2-
Update v1.15.1
1+
Version 1.15.2:
2+
Update v1.15.2
33
Adição do sistema de log
44

55
Version 1.12.0:

README.md

Lines changed: 97 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Django-based REST Framework
44

5-
# Requires
5+
# Install requires
66

77
```PHP
88
pip install rinzler
@@ -12,30 +12,45 @@ pip install rinzler
1212
```Python
1313

1414
# urls.py
15+
16+
import os
17+
import rinzler
18+
19+
from rinzler.core.main_controller import MainController
1520
from your_controller import Controller
16-
from rinzler.core.url_assembler import UrlAssembler
1721

18-
assembler = UrlAssembler()
22+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
23+
24+
app = rinzler.boot(BASE_DIR)
25+
assembler = app['url_assembler']
1926

2027
urlpatterns = [
21-
assembler.mount('', Controller)
28+
assembler.mount('hello', Controller),
29+
assembler.mount('', MainController),
2230
]
2331

32+
```
2433

34+
```Python
2535
# your_controller.py
36+
from collections import OrderedDict
2637

2738
from django.http.request import HttpRequest
2839
from django.views.generic import TemplateView
2940

3041
from rinzler.core.response import Response
3142

43+
3244
class Controller(TemplateView):
3345

3446
def connect(self, app):
3547

3648
router = app['router']
3749

38-
router.get('/', self.hello_world)
50+
# Definir end-points aqui
51+
router.get('/world/', self.hello_world)
52+
router.get('/{name}/', self.hello_user)
53+
3954
return app
4055

4156
# end-point callbacks here:
@@ -48,10 +63,82 @@ class Controller(TemplateView):
4863
:param params dict url params, if present
4964
:rtype: Response
5065
"""
51-
response = {
52-
"status": True,
53-
"data": "Hello World!"
54-
}
66+
try:
67+
response = OrderedDict()
68+
response["status"] = True
69+
response["data"] = "Hello World!"
70+
71+
return Response(response, content_type="application/json")
72+
except BaseException as e:
73+
response = OrderedDict()
74+
response["status"] = False
75+
response["mensagem"] = str(e)
76+
77+
return Response(response, content_type="application/json", status=500)\
78+
79+
@staticmethod
80+
def hello_user(request: HttpRequest, app: dict(), **params: dict):
81+
"""
82+
Default route callback
83+
:param request HttpRequest
84+
:param app Rinzler's object
85+
:param params dict url params, if present
86+
:rtype: Response
87+
"""
88+
try:
89+
user = params['name']
90+
response = OrderedDict()
91+
response["status"] = True
92+
response["data"] = "Hello {0}!".format(user)
93+
94+
return Response(response, content_type="application/json")
95+
except BaseException as e:
96+
response = OrderedDict()
97+
response["status"] = False
98+
response["mensagem"] = str(e)
99+
100+
return Response(response, content_type="application/json", status=500)
55101

56-
return Response(response, content_type="application/json")
57102
```
103+
### Run django
104+
```shell
105+
python manage.py runserver
106+
August 02, 2017 - 18:48:00
107+
Django version 1.10.4, using settings 'Demo.settings'
108+
Starting development server at http://127.0.0.1:8000/
109+
Quit the server with CONTROL-C.
110+
```
111+
112+
### Sample requests
113+
114+
```shell
115+
curl http://localhost:8000/
116+
<center><h1>HTTP/1.1 200 OK RINZLER FRAMEWORK</h1></center>
117+
118+
curl http://localhost:8000/hello/world/
119+
{
120+
"status": true,
121+
"data": "Hello World!"
122+
}
123+
124+
curl http://localhost:8000/hello/bob/
125+
{
126+
"status": true,
127+
"data": "Hello bob!"
128+
}
129+
130+
curl http://localhost:8000/foo/bar/
131+
{
132+
"status": false,
133+
"exceptions": {
134+
"message": "No route found for GET foo/bar/"
135+
},
136+
"request": {
137+
"content": "",
138+
"method": "GET",
139+
"path_info": "foo/bar/"
140+
},
141+
"message": "We are sorry, but something went terribly wrong."
142+
}
143+
144+
```

rinzler/core/router.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ def authenticate(self, bound_route, actual_params):
140140
auth_route = "{0}_{1}{2}".format(self.__method, self.__route, bound_route)
141141
auth_data = self.__auth_service.authenticate(self.__request, auth_route, actual_params)
142142
self.__app['auth_data'] = auth_data
143-
return True
143+
144+
return True
144145

145146
@staticmethod
146147
def get_callback_pattern(expected_params, actual_params):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# Versions should comply with PEP440. For a discussion on single-sourcing
2424
# the version across setup.py and the project code, see
2525
# https://packaging.python.org/en/latest/single_source_version.html
26-
version='1.15.1',
26+
version='1.15.2',
2727

2828
description='Django-based REST API Framework',
2929
long_description=long_description,

0 commit comments

Comments
 (0)