-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoneDone-API-Ruby.rb
102 lines (80 loc) · 2.73 KB
/
DoneDone-API-Ruby.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require "base64"
require 'net/http'
class IssueTracker
# Provide access to the DoneDone IssueTracker API.
def initialize(domain, token, username, password=nil, debug=nil)
@baseURL = "https://#{domain}.mydonedone.com/IssueTracker/API/"
@auth = calculateAuth(username, token)
@token = token
@result = None
@debug = debug
end
def self.curlCallback(result)
@result = result
end
def self.calculateAuth(username, password)
Base64.encode64 "#{username}:#{password}"
end
def API(methodURL, data=nil, attachments=nil, update=false, post=false)
url = @baseURL + methodURL
headers = {}
files = []
if attachments
request_method = Net::HTTP.post
if attachments
files = []
attachments.each do |index, attachment|
files << 'attachment-#{index}'
else
request_method = Net::HTTP.get
end
if update
request_method = Net::HTTP.put
end
if post
request_method = Net::HTTP.post
end
headers[ "Authorization" ] = "Basic #{@auth}"
request_method(url, data=data, files=files, headers=headers)
end
def get_projects(loadWithIssues=false)
url = "Projects/true" if loadWithIssues else "Projects"
self.API(url)
end
def get_priority_levels
self.API("PriorityLevels")
end
def get_all_people_in_project(projectID)
self.API("PeopleInProject/#{projectID}")
end
def get_all_issues_in_project(projectID)
self.API("IssuesInProject/#{projec}")
end
def does_issue_exist(projectID, issueID)
self.API("DoesIssueExist/#{projectID}/#{issueID}")
end
def get_potential_statuses_for_issue(projectID, issueID)
self.API("PotentialStatusesForIssue/#{projectID.to_s}/#{issueID.to_s}")
end
def get_issue_details(projectID, issueID)
self.API("Issue/#{projectID.to_s}/#{issueID.to_s}")
end
def get_people_for_issue_assignment(projectID, issueID)
self.API("PeopleForIssueAssignment/#{projectID.to_s}/#{issueID.to_s}")
end
def create_issue(projectID, title, priorityID, resolverID, testerID, description="", tags="", watcherIDs="", attachments=nil)
data = [
('title', title),
('priority_level_id', priorityID.to_s),
('resolver_id', resolverID.to_s),
('tester_id', testerID.to_s)]
if description
data << ('description', description)
end
if tags
data << ('tags', tags)
end
if watcherIDs
data << ('watcherIDs', watcherIDs.to_s)
end
self.API("Issue/")