-
Notifications
You must be signed in to change notification settings - Fork 0
/
jira.rb
84 lines (69 loc) · 2.03 KB
/
jira.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
#!/usr/bin/env ruby
require 'rfusefs'
require 'httparty'
require 'pp'
require 'deep_merge'
require './cache'
class Jira
include HTTParty
def initialize
@config = JSON.parse File.read 'config.json'
@cache = Cache.new
end
def get(path, options = {})
return raw_get("/rest/api/2#{path}", options.deep_merge({
headers: {
'Accept' => 'application/json',
}
}))
end
def raw_get(path, options = {})
options = options.deep_merge({
base_uri: @config['base_uri'],
headers: {
'X-Atlassian-Token' => 'nocheck',
},
basic_auth: {
username: @config['user'],
password: @config['password'],
},
})
response = @cache.get(path, options[:max_age] || 10) { |path| self.class.get(path, options) }
return response if (200..299).include?(response.code)
puts 'Response:'
puts response.to_s
puts 'Options:'
pp(options)
puts "Response Code: #{response.code}"
puts "Path: #{path}"
raise 'hell'
end
def post(path, options = {})
return raw_post("/rest/api/2#{path}", options.deep_merge({
headers: {
'Accept' => 'application/json',
'Content-Type' => 'application/json',
}
}))
end
def raw_post(path, options = {})
response = self.class.post(path, options.deep_merge({
base_uri: @config['base_uri'],
headers: {
'X-Atlassian-Token' => 'nocheck',
},
basic_auth: {
username: @config['user'],
password: @config['password'],
},
}))
return response if (200..299).include?(response.code)
puts 'Response:'
puts response.to_s
puts 'Options:'
pp(options)
puts "Response Code: #{response.code}"
puts "Path: #{path}"
raise 'hell'
end
end