brendanhay / gogol

A comprehensive Google Services SDK for Haskell.
Other
281 stars 105 forks source link

Google.runGoogle doesn't exist anymore #180

Closed tonyalaribe closed 1 week ago

tonyalaribe commented 2 years ago

Google.runGoogle doesn't exist anymore, but the docs still point to it for executing commands, and it's not clear what the new alternative should be.

mklinik commented 1 year ago

It is send now, in line with amazonka. After a while of tinkering I came up with this. GoogleOptions is just a record with some Text and FilePath. Our key is in a .pem file.

helloGogol :: GoogleOptions -> Text -> IO ()
helloGogol gOpts purchaseToken = do
  privKey <- readKeyFile (googleKeyFile gOpts) >>= \case
    [] -> error "no key found"
    x:_ -> case x of
      Unprotected (PrivKeyRSA key) -> return key
      Unprotected _ -> error "not an RSA key"
      Protected _ -> error "protected key"
  let logger = \_ _ -> return ()
  let credentials = Gogol.FromAccount $ Gogol.ServiceAccount
        { _serviceId = Gogol.ClientId ""
        , _serviceEmail = googleServiceAccount gOpts
        , _serviceKeyId = googleKeyId gOpts
        , _serviceAccountUser = Nothing
        , _servicePrivateKey = privKey
        }
  manager <- Gogol.newManager Gogol.tlsManagerSettings
  env <- Gogol.newEnvWith @'[Android.Androidpublisher'FullControl] credentials logger manager
  subscription <- Gogol.runResourceT $ Gogol.send env $ Android.newAndroidPublisherPurchasesSubscriptionsv2Get (googleAppPkgName gOpts) purchaseToken
  print subscription
tonicebrian commented 1 week ago

With @mklinik and code in the examples folder I think we can close this issue.