Showing posts with label practice. Show all posts
Showing posts with label practice. Show all posts

Integrate swagger with Play Framework link /practice in progress

http://swagger.io/playing-with-swagger-using-swagger-and-swagger-ui-with-the-play-framework/

i just read it, yet to check and practice in full

build.sbt
----
"com.wordnik" %% "swagger-play2" % "1.3.12" exclude("org.reflections", "reflections"), "org.reflections" % "reflections" % "0.9.8" notTransitive (), "org.webjars" % "swagger-ui" % "2.1.8-M1"

application.conf :
----
api.version="1.0" swagger.api.basepath="http://localhost:9000"

routes
----
GET / controllers.Assets.at(path="/public", file="index.html")

GET /api-docs controllers.ApiHelpController.getResources

POST /login controllers.SecurityController.login() POST /logout controllers.SecurityController.logout()

GET /api-docs/api/todos controllers.ApiHelpController.getResource(path = "/api/todos")
GET /todos controllers.TodoController.getAllTodos()
POST /todos controllers.TodoController.createTodo()


swagger annotation
--------
@Api(value = "/api/todos", description = "Operations with Todos") @Security.Authenticated(Secured.class)
public class TodoController extends Controller {


@ApiOperation(value = "get All Todos",
     notes = "Returns List of all Todos",
     response = Todo.class,
     httpMethod = "GET")
public static Result getAllTodos() {
     return ok(toJson(models.Todo.findByUser(SecurityController.getUser())));
}
@ApiOperation(
     nickname = "createTodo",
     value = "Create Todo",
     notes = "Create Todo record",
     httpMethod = "POST",
     response = Todo.class
 )
@ApiImplicitParams(
     {
          @ApiImplicitParam(
               name = "body",
               dataType = "Todo",
               required = true,
               paramType = "body",
               value = "Todo"
          )
     }
)
@ApiResponses(
          value = {
                  @com.wordnik.swagger.annotations.ApiResponse(code = 400, message = "Json Processing Exception")
          }
)
public static Result createTodo() {
     Form form = Form.form(models.Todo.class).bindFromRequest(); 
     if (form.hasErrors()) {
         return badRequest(form.errorsAsJson());
     }
     else {
          models.Todo todo = form.get();
          todo.user = SecurityController.getUser();
          todo.save();
          return ok(toJson(todo));
     }
}


Pythob practice

Type "help", "copyright", "credits" or "license" for more information.
>>> print "Hello Word!"
Hello Word!
>>> if(foo)
  File "", line 1
    if(foo)
          ^
SyntaxError: invalid syntax
>>> f=true
Traceback (most recent call last):
  File "", line 1, in
NameError: name 'true' is not defined
>>> f=1
>>> if f:
...     print "f is 1"
... 
f is 1
>>> if f:
...     print "f is 1"
... else:
...     print "i don't know"
... 
f is 1
>>> """
... multi
... line
... comment
... """
'\nmulti\nline\ncomment\n'
>>> d = None
>>> numbers = [1,2,3,4]
>>> len(numbers)
4
>>> numbers[0]
1
>>> person={}
>>> person["name"]="ikbhal"
>>> person.update({
...     "favourites":[42,"food"],
...     "gender":"male"
... })
>>> person
{'gender': 'male', 'favourites': [42, 'food'], 'name': 'ikbhal'}
>>> person[(44.47, -73)]= "coordinates"
>>> person
{'gender': 'male', 'favourites': [42, 'food'], 'name': 'ikbhal', (44.47, -73): 'coordinates'}
>>> p2= {"name":'Ikbhal', 'gender':'Male'}
>>> p2
{'gender': 'Male', 'name': 'Ikbhal'}
>>> p2.get('name','Anonymous')
'Ikbhal'
>>> p2.values()
['Male', 'Ikbhal']
>>> p2.items()
[('gender', 'Male'), ('name', 'Ikbhal')]
>>> is_python=True
>>> is_python=bool("any object")
>>> is_python
True
>>> animals = "Cats " + "Dogs"
>>> animals += "Rabbits"
>>> name = '%(first)s %(last)s' % {
...     'first':'Ikbhal',
...     'last':'Shaik'}
>>> name
'Ikbhal Shaik'
>>> grade = 82
>>> if grade >= 90:
...     print "A or A+"
... elif grade >= 80:
...     print "B"
... else:
...     print "F"
... 
B
>>> class User(object):
...     pass
... 
>>> class Student(object):
...     def __init__(self, name='Anyonmous')
  File "", line 2
    def __init__(self, name='Anyonmous')
                                       ^

SyntaxError: invalid syntax

try to be better person by practice good habbits

Practice good habbits
Try to better person by actions, by thought
say sorry, forgive other, help other, clean teeth, go to bed early
teach yourself, your children, your family with softly