Everyone wrote them back.
So in the previous video we saw that we finished the classification and the registration of the API.
So the final thing that we need to do is to do the refill of the API.
OK.
So we're going to go go back here.
So we're going to come back here and then we're going to finally write the Rayfield class which we did
it in a similar video before so it shouldn't be something new.
Right.
So we're going to go through it fairly quickly OK.
So that's a good start.
So the first thing is we need to write a class which is called refill.
Right.
As the resource and we inherit from the resource class and then we said we discussed that it's going
to be a post right.
So we're going to see a post of self.
And then first of all the first step in post is usually to get the post to do us or we're going to say
a posted up equal to a request not get Jaisalmer.
Once we have the posted data then we need to get the username password and the amount that is to be
added right and be careful that the password here is not the user's password but rather the administrators
password right.
So we're going to say a user name username is equal to the posted data and then username password is
equal to posted data.
And then inside of it we're going to call it admin underscore P.W. and password.
And then finally the amount is equal to the posted data.
At the same amount.
OK so it's going to send it in the field amount.
OK so we have the username password and amount so the first thing is we need to check that this user
exists.
So I'm going to say if not user exists.
Ok so if this username doesn't exist then what do I do.
Well I return an error as I say return.
Jason if I and then we're going to use the function that we wrote generate return dictionaries and when
I say return.
So here generate return Dictionnaire gate and then the error code is going to be 301 because there is
an invalid username and for the message it might tell the user.
Well you know what invalid you don't want to see invalid username username.
OK.
And that's it.
So that's for the existence of the user.
We also said that the administrator password might be incorrect.
I'm going to say the correct administrative password should be no ABC 1 2 3.
Ok so maybe that's the administrative password that we choose.
So I'm going to say if not password is equal to correct password then in that case I'm going to return
3 0 2 which is an incorrect password.
So I'm going to say return Jason if I generate or actually it should be I think three or four.
Right.
Because it's it's the invalid administrator password so it's invalid.
Adman's traitor password might have misspelled it it's fine.
OK.
So once we have that then the next step is to update our users or our users database so that he has
the new amount right.
So how am I going to do that.
Well I'm going to do users that update.
OK.
And then in here choose the user which has the corresponding user name.
And what I'm going to update them is I'm going to set his number off tokens so I'm going to do a dollar
set and then I'm going to have changed the number of tokens he has to the amount.
OK.
So the amount here is whatever I sent.
And that's should be.
So the final thing is to return a success to the user.
So I don't say congratulations you have your AP You know you've added refilled the correct amount of
stuff.
So I'm going to see a return on I and then generate return dictionary inside of it.
I'm gonna give 200.
So it's a success and I'm going to give them a message.
I want to refill.
So refill maybe successfully.
OK.
All right.
So now that should be it.
So we're done with the refill.
We're done with the classify glass and we're done with the registration.
OK.
So we're done with all of the resources.
Now we need to add them to the API.
So I do.
AP I got to add resource and resource.
And then I'm going to add.
First of all register.
And if you remember from the image we said or from the chart we said we're going to do it at slash register.
Okay.
And then we're going to do API to add resource Rumana at the classify glass and we're going to put it
at slash classified slash classify finally resigned you add the last resource which is the real.
And we're going to add it as Slash free.
Great.
Finally the last step is as usual if name is equal to main.
So if it's main then we do at Dharan and then host is equal to and this is the most important piece
of the code.
Zero point zero point zero point zero.
OK.
So this is the host and readouts are done with the API.
Just almost 150 lines of code.
Not too big.
OK.
That can make it smaller.
Probably you know for example these things like updates we can write a function that up these things
automatically so it can take this just in one line of code.
For example this update to you can change it in one line of code so you can do a lot of stuff here.
Let's let us remove these two Tutu's because we're done with them to do it right.
So yeah hopefully this wasn't too hard.
It's just the main idea here is the classifying class and actually everything beyond this area here
is actually pretty old.
So we've discussed it before.
So the only new area here I would say is the request get your elso we got that you are well from the
requests we generated the result Jason or dictionary.
And then we opened the image store that so we store the the image from their request that we got from
their request and then we opened a new process and we ran in it.
Lifeson classified image model directory in my file.
Then I communicated with the process and I waited until the process subprocesses done.
And finally this process year we changed it so that it writes text that DST file and that and it stores
and dumps in it.
The risk very turned up.
So what I do here is to open it and retrieve the dictionary once I have that then I'm willing to return.
Richard Jewson and that's about it.
So we're going to stop here and the next video we're going to be testing the API just see how it works
how we can interact with it.
And you know see if it can work correctly classify a couple of images so let's give it a image of a
zebra or a panda and see if it works or not.
They're just up here and will pick up in the next minute or so until the next minute.
Happy Cody.