I'm writing a client to some Google APIs, including Google Sheets API.
This action here is causing me some troubles:
As you can see, they capture the id of the object in the URL as usual, but the custom action batchUpdate is specified after a semi-colon that I can't modelize properly with the :> combinator.
As was thinking of either :
Do you have any advice ?
I would probably pick the second option, it's the simplest one by far and will get the job done without (to me) feeling like a hack. In case you need to support different "keywords" (i.e not just `batchUpdate`), you could even have something like:
newtype Spreadsheet (action :: Symbol) a = Spreadsheet a
where the 'action' bit would be "batchUpdate" or any other string that you need it to be. This might be overkill for now though if you only need to handle "batchUpdate". Then the logic of extracting the spreadsheetId and checking that it is followed by ":batchUpdate" or more generally by ":" and the keyword specified by "action" with my newtype above, could all be handled as part of the instance for FromHttpApiData
On Mon, May 22, 2017 at 10:14 AM, Frédéric Menou <[hidden email]> wrote:
OK, thank you,
here what I ended with :
data BatchUpdateCommand = BatchUpdateCommand SpreadsheetId
instance ToHttpApiData BatchUpdateCommand where
toUrlPiece (BUC sid) = pack sid <> ":batchUpdate"
type API = "spreadsheets"
:> Capture "spreadsheetId" BatchUpdateCommand
:> ReqBody '[JSON] BatchUpdate
:> Post '[JSON] BatchUpdateResult
batchUpdate' :: BatchUpdateCommand -> BatchUpdate -> ClientM BatchUpdateResult
batchUpdate' = client api
batchUpdate :: SpreadsheetId -> BatchUpdate -> ClientM BatchUpdateResult
batchUpdate sid = batchUpdate' (BUC sid)
Le lundi 22 mai 2017 10:23:39 UTC+2, Alp Mestanogullari a écrit :
Oh right, you only need to ToHttpApiData direction. Looks good to me. I'd probably make BatchUpdateCommand a newtype, but that's just nitpicking :)
On Mon, May 22, 2017 at 11:07 AM, Frédéric Menou <[hidden email]> wrote:
OK, thank you,
Thank you :)
Le lundi 22 mai 2017 11:22:51 UTC+2, Alp Mestanogullari a écrit :
|Free forum by Nabble||Edit this page|