pd4d10 / git-touch

An open-source app for GitHub, GitLab, Bitbucket, Gitea, and Gitee(码云), built with Flutter
Apache License 2.0
1.56k stars 138 forks source link

refactoring fetchBb #158

Open shreyas1599 opened 3 years ago

shreyas1599 commented 3 years ago

Hi, @pd4d10 fetchBb and fetchBbJson are two different methods. I need to add other HTTP methods(PUT, DELETE, PATCH) like I did for Gitee. Is it alright if I refactor this into a single fetchBb method and update the references across all files? Also was there any specific reason you used two methods(fetchBb and fetchBbJson) for bitbucket unlike the others?

pd4d10 commented 3 years ago

refactor this into a single fetchBb method

OK. BTW, the http lib seems a bit verbose when using the HTTP method other than 'GET'.

Currently it is:

http.get()
http.post()

But for the common request utility function, what we want is more like:

http.request(method: MethodEnum.GET)
http.request(method: MethodEnum.POST)

So we could pass the HTTP method enum directly

shreyas1599 commented 3 years ago

Oh do you mean using this function:

http.Request(method: String, URL: Uri)

and then Something like this?

enum Methods {
    GET, POST,...
}
extension parsdUri on Methods {
   Uri getParsedUri(params) {

   }
}

http.Request(method: methodName, Methods.GET.getParsedUri(params))

But the above seems will not make the existing code simpler. Are you talking more along these lines: https://github.com/dart-lang/language/issues/158 ? Seems like we can't create methods in enums. Only using extensions we can call methods

pd4d10 commented 3 years ago

Yeah, I mean if the http lib does already support this, the code would be simpler. For example, we could get rid of the switch case as follows:

https://github.com/git-touch/git-touch/blob/780970a5b754c7d7ceffb6f85a1b61383bbccf17/lib/models/auth.dart#L333-L366

We could just pass the method instead, no matter if it is a string or enum

pd4d10 commented 3 years ago

I think your proposal is fine. Let's just do the refactor as you supposed.