brendanhay/gogol

Google.runGoogle doesn't exist anymore

Opened this issue · 1 comments

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.

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