I am making HTTP Calls using Retrofit for making web calls. Every call has different parameters and responses.
What I want to achieve
Make a GenericCaller
What I want to do is whenever I make a call, I pass it to a GenericCaller. Now it can add any additional parameter, or manipulate it as required and send.
Make a GenericResponseHandler
When GenericCaller returns response, it would be sent to GenericResponseHandler for initial processing (like in case of error or unauthenticated access, take user out of the app or show error etc) and then pass it for further specific processing.
I’ve been thinking for past day, but couldn’t come up with clear idea.
I do have some thoughts.
- I have classes for different Params to be sent with the call. I can make a ParentParams and inherit all Params from it. Now I can add as many attributes in ParentParams as I can. For GenericResponseHandler, pass every response to it and process.
- Make a single SenderAndReceiver class which acts as gateway. Every request is sent and received through it. But I don’t have an idea what would be inside that class.
I need some help in achieving this task. Any help is highly appreciated. Thanks!