Created
April 2, 2023 08:46
-
-
Save ahndmal/18f26abbabc6eff4b7320bdd43c31bdb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
{-# LANGUAGE OverloadedStrings #-} | |
-- {-# LANGUAGE QuasiQuotes #-} | |
-- {-# LANGUAGE DeriveGeneric #-} | |
-- {-# LANGUAGE RecordWildCards #-} | |
import Data.ByteString.Char8 (ByteString) | |
import qualified Data.ByteString.Char8 as BC | |
import qualified Data.ByteString.Lazy as DBL | |
import qualified Data.ByteString.Lazy.Char8 as L8 | |
import qualified Data.Text as T | |
import qualified System.IO.Streams as Streams | |
import qualified Data.CaseInsensitive as CI | |
import Control.Monad | |
-- import System.IO.Streams (InputStream, OutputStream, stdout) | |
import Data.Foldable | |
-- import Data.String | |
import Data.Maybe (fromJust, fromMaybe) | |
-- import Data.List | |
import Data.Char (ord) | |
-- import GHC.Generics | |
import Network.HTTP.Client | |
import Network.HTTP.Types.Status (statusCode) | |
import Network.HTTP.Types.Header | |
import Data.Aeson | |
import Data.Time (UTCTime) | |
import Data.Vector (Vector) | |
import Control.DeepSeq (NFData (..)) | |
-- import Prelude.Compat | |
import Control.Monad.IO.Class | |
import Data.Aeson | |
import Network.HTTP.Req | |
-- models | |
newtype Id entity = Id Int | |
deriving (Show) | |
data Project = Project { | |
projId :: Int | |
} deriving ( Show) | |
data Issuetype = Issuetype { id1 :: String } deriving (Show) | |
data Assignee = Assignee { id2 :: String } deriving (Show) | |
data Reporter = Reporter { name :: String } deriving (Show) | |
data Priority = Priority { id3 :: String } deriving (Show) | |
data Fields = Fields { | |
project :: Project, | |
summary :: String, | |
issuetype :: Issuetype, | |
assignee :: Assignee, | |
reporter :: Reporter, | |
priority :: Priority, | |
labels :: [String], | |
description :: String, | |
duedate :: String | |
} deriving (Show) | |
data CreatePageData = Page { url :: String | |
, token :: String | |
, title :: String | |
, body :: String | |
, parent :: String | |
, spaceKey :: String} deriving (Show) | |
data GetPageData = GetPageData { | |
key :: String | |
} deriving (Show) | |
-- createPage :: CreatePageData -> String | |
-- createPage cp = do | |
-- manager <- newManager defaultManagerSettings | |
-- let user = stringToBytes "admin" | |
-- let pass = stringToBytes "admin" | |
-- let auth = stringToBytes "Basic YWRtaW46YWRtaW4K" | |
-- let headers = [("Authorization", auth)] | |
-- let req = object ["fields" .= "aa"] | |
-- initialRequest <- parseRequest "http://localhost:9500/rest/api/2" | |
-- let request = initialRequest { method = "POST", requestBody = RequestBodyLBS $ encode req } | |
-- response <- httpLbs request manager | |
-- "success" | |
-- getPage :: GetPageData -> Page | |
-- getPage gpd = do ... | |
removeNonUppercase st = [ c | c <- st, c `elem` ['A'..'Z']] | |
stringToBytes :: String -> BC.ByteString | |
stringToBytes = BC.pack | |
main :: IO () | |
main = do | |
let user = stringToBytes "admin" | |
let pass = stringToBytes "admin" | |
let auth = stringToBytes "Basic YWRtaW46YWRtaW4=" | |
let headers = [("Authorization", auth), ("Content-Type", BC.pack "application/json"), ("Accept", BC.pack "application/json")] | |
let url = "http://localhost:9500/rest/api/2/issue" | |
let request = applyBasicAuth user pass $ parseRequest_ url | |
-- putStrLn $ show (requestHeaders request) | |
mngr <- newManager defaultManagerSettings | |
let bodyStr = L8.pack "" | |
let req = request | |
{ method = stringToBytes "POST" | |
, requestHeaders = [(hContentType, BC.pack "application/json")] | |
, requestBody = | |
RequestBodyLBS $ L8.pack "{\"fields\": { \"project\": { \"id\": \"10000\" }, \"summary\": \"something's wrong\", \"issuetype\": { \"id\": \"10006\" }, \"assignee\": { \"name\": \"admin\" }, \"reporter\": { \"name\": \"admin\" }, \"priority\": { \"id\": \"3\" }, \"labels\": [\"bugfix\"], \"description\": \"description\", \"duedate\": \"2023-04-11\" }}" | |
} | |
res <- httpLbs req mngr | |
putStrLn $ show res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment