Created
August 14, 2013 11:12
-
-
Save hapylestat/6230101 to your computer and use it in GitHub Desktop.
Allows ps script to access JIRA data via REST interface
This file contains 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
#======================================== | |
# ps-jira-connect | |
# Author: H.L. | |
# Version: 0.1 | |
# Description: JIRA Connector | |
# Created: 8/14/2013 4:08 AM | |
#======================================== | |
$ps_jira_connect={ | |
function ConvertToBase64($string) { | |
$bytes = [System.Text.Encoding]::UTF8.GetBytes($string); | |
$encoded = [System.Convert]::ToBase64String($bytes); | |
return $encoded; | |
} | |
function Init($url,$user,$pass){ | |
$mtaData.jira.url=$url; | |
$mtaData.jira.name=$user; | |
$mtaData.jira.pass=$pass; | |
} | |
function loadUriData($url,$user,$pass){ | |
$auth=ConvertToBase64 "${user}:${pass}" | |
$webrequest = [System.Net.WebRequest]::Create("$url") | |
if ($user -ne "" -and $pass -ne ""){ | |
$webrequest.PreAuthenticate = $true | |
$webrequest.Credentials = new-object system.net.networkcredential("$user", "$pass") | |
} | |
# | |
$webrequest.Headers.Add("AUTHORIZATION", "BASIC " + $auth) | |
$webrequest.Method="GET"; | |
$webrequest.ContentLength = 0; | |
#$webrequest.ContentType="application/json"; | |
$response = $webrequest.GetResponse() | |
$sr = [Io.StreamReader]($response.GetResponseStream()) | |
return $sr.ReadToEnd() | |
} | |
function getIssue($issue){ | |
$url=$mtaData.jira.url | |
$data=loadUriData "${url}/${issue}" $mtaData.jira.name $mtaData.jira.pass; | |
[System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") |out-null | |
$ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer | |
$obj = $ser.DeserializeObject($data) | |
return $obj | |
} | |
Export-ModuleMember -function getIssue,Init | |
} | |
$mtaData.sdc=new-module -ScriptBlock $ps_jira_connect -AsCustomObject |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment