refactoring fetchBb #102

Open
opened 2025-10-31 17:05:40 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @shreyas1599 on GitHub (Jan 10, 2021).

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?

Originally created by @shreyas1599 on GitHub (Jan 10, 2021). Hi, @pd4d10 [`fetchBb`](https://github.com/git-touch/git-touch/blob/780970a5b754c7d7ceffb6f85a1b61383bbccf17/lib/models/auth.dart#L431-L451) and [`fetchBbJson`](https://github.com/git-touch/git-touch/blob/780970a5b754c7d7ceffb6f85a1b61383bbccf17/lib/models/auth.dart#L453-L464) are two different methods. I need to add other HTTP methods(PUT, DELETE, PATCH) like I did for [Gitee](https://github.com/git-touch/git-touch/blob/780970a5b754c7d7ceffb6f85a1b61383bbccf17/lib/models/auth.dart#L323-L372). 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?
Author
Owner

@pd4d10 commented on GitHub (Jan 10, 2021):

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

@pd4d10 commented on GitHub (Jan 10, 2021): > 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: ```dart http.get() http.post() ``` But for the common request utility function, what we want is more like: ```dart http.request(method: MethodEnum.GET) http.request(method: MethodEnum.POST) ``` So we could pass the HTTP method enum directly
Author
Owner

@shreyas1599 commented on GitHub (Jan 10, 2021):

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

@shreyas1599 commented on GitHub (Jan 10, 2021): 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
Author
Owner

@pd4d10 commented on GitHub (Jan 11, 2021):

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:

780970a5b7/lib/models/auth.dart (L333-L366)

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

@pd4d10 commented on GitHub (Jan 11, 2021): 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`
Author
Owner

@pd4d10 commented on GitHub (Jan 11, 2021):

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

@pd4d10 commented on GitHub (Jan 11, 2021): I think your proposal is fine. Let's just do the refactor as you supposed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/git-touch#102