-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_issues.rb
executable file
·83 lines (65 loc) · 1.92 KB
/
get_issues.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
require 'httparty'
require 'json'
@config = JSON.load(File.read('config.json'))
def get_issues(project_id, type, key)
query = project_id ? { project_id: project_id } : {}
headers = {
'X-Redmine-API-Key' => @config['redmine_api_key']
}
response = HTTParty.get(
"http://#{@config['redmine_url']}/#{type}",
:query => query,
:headers => headers
)
if response.code == 200
response[key]
else
[]
end
end
def get_weather
url = "http://api.wunderground.com/api/#{@config['weather_api_key']}/conditions/q/Hod_Hasharon.json"
response = HTTParty.get(url)
if response.code == 200
response["current_observation"]
else
{}
end
end
def get_image
headers = { 'X-Redmine-API-Key' => @config['redmine_api_key'] }
query = { project_id: 5 }
response = HTTParty.get(
"http://#{@config['redmine_url']}/issues/534.json?include=attachments",
:query => query,
:headers => headers
)
link = response.parsed_response["issue"]["attachments"].last["content_url"]
pic = HTTParty.get(
link,
:headers => headers
)
File.open('images/page3.jpg', 'w') { |file| file.write(pic) }
end
messages = get_issues(5, 'issues.json', 'issues').map do |r|
{
"title" => r["subject"].tr("'"," "),
"description" => r["description"].tr("\n"," ").tr("\r"," ").tr("'"," "),
"date" => r["start_date"]
}
end
issues = get_issues(1, "issues.json", "issues").map do |r|
{
'id' => r['id'] ,
"subject" => r["subject"].tr("'"," "),
"status" => r["status"]["name"],
"created_on" => Time.parse(r["created_on"]).strftime("%d-%m-%Y"),#.to_date,
"days_open" => "#{(Time.now.to_date - Time.parse(r["created_on"]).to_date).round}" #r["created_on"]
}
end
weather = get_weather
get_image
# open and write to a file with ruby
open('issues.json', 'w') { |f|
f.puts "data = '" + issues.to_json + "';\nmessages = '" + messages.to_json + "';\nweather = '" + weather.to_json + "';"
}