I want to ask you for advises what i could do with that
class to make
it looks more "pro"/elegant/build in "proper way". Probably
there are
lot of mistakes which all beginners are doing.
eg.: Did i use interface correctly?
You are reasonably close:
credential sig = new sigv4();
Why are you creating sigv4 object with type credential? How in
your
opinion should look interface for such class?
Although go is not really doing what I expect it to do.
To me go should be dedicated to performing a request given
what ever
you need for just that request. The class sigv4 is your
global state
aka what doesn't change per request.
To me what go returns is whatever is the common denominator
for what
you need from it is.
Not sure if i correctly understood that. Do you propose to
take out eg
signing process from go function and let it only to make
requests?
Signature is depending on kind of request and accurate time
when request
is send. That is why i all that things put to it.
The implementation such as sigv4 can be configured with as much
detail as possible extra that you need.
The method go can for instance do what ever it needs to, to for
fill it's goal.
From what I can see, you probably want go to take the payload
as an
argument.
That way you can reuse an instance of sigv4. Which is the
ultimate goal.
In plan i wanted to change variables per request that why i
left that
public variables and created that arguments for constructor -
to have
possibility to change that values durring creation of object.
On example, im expecting it will be behaving like that:
sigv4 obj = new sigv4();
content = obj.go(); //will get instances list
obj.request_parameters =
"Action=DescribeRegions&Version=2013-10-15"
content2 = obj.go(); //will get list of regions
destroy(obj);
so that go will get me back what i need per request not per
one object
live, or it wont work like that?
It indeed should not.
Also remember go is currently returning an integer. Not data
from the request.
I test it with such code:
void main()
{
SigV4 sig = new SigV4();
writeln(sig.go);
sig.requestParameters =
"Action=DescribeRegions&Version=2013-10-15";
writeln(sig.go());
}
Actually it is working, first it returned to me default request
DescribeInstances and right after that request DescirbeRegions. I
understand that, before i will start parsing it with xml lib i
need to convert it to string. Should it be solved in other way?
go method returns xml form (need to find out how force AWS to
return
JSON cos i saw xml module in dlang is deprecated) with
structures
depends on query - in default query that will be list of
instances with
all parameters. That xml file i want to parse in higher
classes/functions (different class for different request).
If you need to use std.xml use it. We don't appear to be
replacing it any time soon.
So here is the thing. You are tieing your usage of the API to
SigV4 standard. This is bad bad bad. Any updates or changes to
it, will cause problems. If you want to tie yourself to said
standard, then you don't need OOP.
How it could be solved in that case to not be tied to SigV4? If
there will came some other request signing process it will need
to be implement in that "go" function. Is there possibility to
make it universal for all kind of signing processes? How it
should be done in OOP (some example, pseudo code)? Or i missed
what you are pointing to?
Another thing, you may want to consider to use an interface as
the return type of go. That way your implementation of it can
have extra fields/methods which if you know that it is sigv4
you can cast to, to get access to, should you need it.
It interesting what you wrote. Can you show me some example
(pseudo code) how it can be implemented and how it could be used?
It think that it is what you wrote in previous post:
Credential sigv4 = new sigv4();
Remember im really beginner and some obvious things are not
necessarily such for me. :)
Also classes start with a capital letter, like Credential or
SigV4. And D prefers camal casing aka requestParameters for
variables/functions.
Updated my code according to those directions.
//holo