Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Haskforce.SForce.Common where
import Data.Text (Text)
import Data.Aeson
import Data.Aeson.Types
@Woody88
Woody88 / Example.hs
Last active March 24, 2018 04:48
Example of using my Haskforce library to query and Account object on salesforce
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Example where
import Data.Text (Text)
import Data.Aeson
type Optionals = HML.HashMap Text Text
type SFApiNumber = Text
data SFClient = SFClient SFApiNumber AuthResponse deriving Show
data UserCred = UserCred
{ username :: Maybe Username
, password :: Maybe UserPassword
, secretKey :: Maybe SecretKey
, clientId :: Text
-- This function uses getSObjectRow to get an Account by id number.
-- The (Proxy @Account) just tell the function what we are expecting back (of course an Account).
--
getAcc :: IO (Either ServantError (SObject Account))
getAcc = do
(Right client) <- sfclient
getSObjectRow (SObjectId "0016A00000JcdjK") (Proxy @Account) client
-- This a helper function for the updateAcc. It just retrieves an account
-- and return the account with the sfclient as a tuple.
@Woody88
Woody88 / sfclient.hs
Last active March 25, 2018 04:19
Salesforce Client Setup
{-# LANGUAGE OverloadedStrings #-}
import Data.Text (Text)
import Haskforce
import Haskforce.API.Resources
-- User Credential, they are fake so dont try those...
-- We have a type UserCred which will hold all of our salesforce user credential.
-- For security reason these values would be set as environment variable.
cred :: UserCred
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeApplications #-}
import Data.Text (Text)
import Data.Aeson
import Data.Proxy
import GHC.Generics
import Servant.Client
import Haskforce
traverseIntMapWithKeyWithAdjustImpl :: forall t w v' p p' v m. (PatchTarget (p' (Dynamic t w)) ~ IntMap (Dynamic t w), PatchTarget (p' w) ~ IntMap w, Patch (p' w), Patch (p' (Dynamic t w)), MonadFix m, Monoid w, Reflex t, MonadHold t m, Functor p, p ~ p')
=> ( (IntMap.Key -> v -> m ((v', Dynamic t w)))
-> IntMap v
-> Event t (p v)
-> m (IntMap (v', Dynamic t w), Event t (p (v', Dynamic t w)))
)
-> (Incremental t (p' (Dynamic t w)) -> Incremental t (p' w))
-> (IntMap.Key -> v -> DynamicWriterT t w m v')
-> IntMap v
-> Event t (p v)
import Web.Cookie (SetCookie,parseSetCookie,renderSetCookie)
-- |
-- >>> let Right c = parseUrlPiece "SESSID=r2t5uvjq435r4q7ib3vtdjq120" :: Either Text SetCookie
-- >>> toUrlPiece c
-- "\"SESSID=r2t5uvjq435r4q7ib3vtdjq120\""
instance ToHttpApiData SetCookie where
toUrlPiece = showt . BS.toLazyByteString . renderSetCookie
toEncodedUrlPiece = renderSetCookie
@Woody88
Woody88 / Devel.hs
Created April 14, 2018 05:38
UPDATED: Running jsaddle and your applications server on the same port (Author hamishmack!)
{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Devel (
test
@Woody88
Woody88 / DivType.hs
Created April 23, 2018 20:20
Div Type
div_ :: [Attribute action] -> [View action] -> View action