Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
baz committed Jul 1, 2011
0 parents commit 9abc1f4
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules/
48 changes: 48 additions & 0 deletions lib/jira.coffee
@@ -0,0 +1,48 @@
url = require 'url'
JiraRPC = require('./jira_client').JiraRPC
JiraREST = require('./jira_client').JiraREST

class JiraAPI
constructor: ->
@jiraRPC = new JiraRPC username, password, location
@jiraREST = new JiraREST username, password, location

authenticate: (callback) ->
@jiraRPC.call 'login', [@jiraRPC.username, @jiraRPC.password], (error, response) ->
if error then callback error, false else callback null, true

allProjects: (callback) ->
@jiraRPC.call 'getProjectsNoSchemes', null, callback

allVersions: (projectKey, callback) ->
@jiraRPC.call 'getVersions', [projectKey], callback

allComponents: (projectKey, callback) ->
@jiraRPC.call 'getComponents', [projectKey], callback

issueTypes: (projectID, callback) ->
@jiraRPC.call 'getIssueTypesForProject', [projectID], callback

subTaskIssueTypes: (projectID, callback) ->
@jiraRPC.call 'getSubTaskIssueTypesForProject', [projectID], callback

priorities: (callback) ->
@jiraRPC.call 'getPriorities', null, callback

statuses: (callback) ->
@jiraRPC.call 'getStatuses', null, callback

resolutions: (callback) ->
@jiraRPC.call 'getResolutions', null, callback

items: (projectKey, limit, callback) ->
query = "project = #{ projectKey } ORDER BY updated DESC, key DESC"
@jiraRPC.call 'getIssuesFromJqlSearch', [query, limit], callback

availableActions: (issueKey, callback) ->
@jiraRPC.call 'getAvailableActions', [issueKey], callback

worklogs: (issueKey, callback) ->
@jiraRPC.call 'getWorklogs', [issueKey], callback

module.exports = new JiraAPI()
61 changes: 61 additions & 0 deletions lib/jira_client.coffee
@@ -0,0 +1,61 @@
rest = require 'restler'
querystring = require 'querystring'
url = require 'url'

class JiraRPC
constructor: (@username, @password, @location) ->
@apiPath = url.resolve @location, 'rpc/json-rpc/jirasoapservice-v2'

call: (methodName, params = [], callback) ->
# We are authenticating via basic auth, so the token is not needed
# But a placeholder value is required
# The only method which does not require a token parameter is the login method
if methodName != 'login' then params.unshift 'token123'

body =
jsonrpc: '2.0'
method: methodName
params: params
id: null
bodyData = JSON.stringify(body)
options =
data: bodyData
username: @username
password: @password
headers:
'Content-Type': 'application/json'
'Content-Length': bodyData.length

request = rest.post @apiPath, options
request.on 'success', (data) ->
if data.error
return callback data.error.message, null
else
return callback null, data.result
request.on 'error', (data, response) =>
error = 'Error with HTTP status code: ' + response.statusCode + '\n'
error += 'Your credentials or location (' + @apiPath + ') may be incorrect, please try again.'
return callback error, null


class JiraREST
constructor: (@username, @password, @location) ->
@apiPath = url.resolve @location, 'rest/api/2.0.alpha1/'

get: (methodName, params = {}, callback) ->
query = querystring.stringify params
options =
username: @username
password: @password

path = url.resolve @apiPath, methodName + "?#{ query }"
request = rest.get path, options
request.on 'success', (data) ->
return callback null, data
request.on 'error', (data, response) =>
error = 'Error with HTTP status code: ' + response.statusCode + '\n'
error += 'Your credentials or location (' + @apiPath + ') may be incorrect, please try again.'
return callback error, null

module.exports.JiraRPC = JiraRPC
module.exports.JiraREST = JiraREST
17 changes: 17 additions & 0 deletions package.json
@@ -0,0 +1,17 @@
{
"name": "node-jira",
"description": "JIRA v4.3 SOAP Interface",
"version": "0.0.1",
"author": "Basil Shkara <basil@neat.io>",
"keywords": ["jira"],
"main" : "lib/jira",
"dependencies": {
"restler": ">=0.2.1"
},
"directories" : {
"lib" : "./lib"
},
"engines": {
"node": ">= 0.4.2"
}
}

0 comments on commit 9abc1f4

Please sign in to comment.