I’m making wrappers over rest api methods. my code represents similar pieces of code. I’m looking for a generalized method to wrap a rest api
'crm.lead.update'(conf(AccessToken, ClientEndpoint), Fields, Reply) :-
bitrix24_auth:check_token,
format(atom(Url), '~w~w', [ClientEndpoint, 'crm.lead.update']),
bearer(AccessToken, Bearer),
bitrix24_request:post(Url,
json(
Fields
),
Reply,
[Bearer, status_code(StatusCode)]),
(200 == StatusCode
->
memberchk(result= @(true), Reply)
; debug(http(error), 'error ~q', [Reply])
).
This code is repeated for all API methods. I’m looking for a way to get rid of this repetition. What if there is a way to write a generalized predicate?