-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaily.rb
executable file
·63 lines (51 loc) · 1.51 KB
/
daily.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
#!/usr/bin/env ruby
require 'rubygems'
require 'net/http'
require 'nokogiri'
require 'json'
require 'yaml'
config = YAML.load_file('config.yml')
api_key = config['api_key']
base_url = config['server_url']
json_url = 'daily.json'
url = "https://#{base_url}/#{json_url}?api_key=#{api_key}"
uri = URI(url)
response = Net::HTTP.get(uri)
times = Array.new
time_entries_json=JSON.parse(response)
build_daily = Nokogiri::XML::Builder.new { |xml|
xml.items {
time_entries_json.each { |time_entry|
times.push("#{time_entry['time_entry']['minutes'].to_i}")
}
sum = times.inject(&:+)
@total_time = Time.at(sum).gmtime.strftime('%T')
xml.item('uuid' => 'string', 'type' => 'string') {
xml.icon('src/info.png')
xml.title("Total: #{@total_time}")
}
time_entries_json.each { |time_entry|
if time_entry['time_entry']['billable']
billable = 'Billable'
else
billable = 'Non Billable'
end
xml.item('uuid' => 'string', 'arg' => "#{base_url}/time_entries/#{time_entry['time_entry']['id']}", 'type' => 'string') {
xml.title("#{time_entry['time_entry']['project_name']} - #{time_entry['time_entry']['note'].split(' ')[0]}")
xml.subtitle("#{time_entry['time_entry']['minutes']} Minutes as #{billable}")
}
}
}
}
build_daily_empty = Nokogiri::XML::Builder.new { |xml|
xml.items {
xml.item('uuid' => 'string', 'arg' => "#{base_url}", 'type' => 'string') {
xml.title('No worklogs have been made yet')
}
}
}
if response == "[]"
puts build_daily_empty.to_xml
else
puts build_daily.to_xml
end