This repository was archived by the owner on Jan 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 402
Expand file tree
/
Copy pathconversions.rb
More file actions
84 lines (76 loc) · 2.5 KB
/
conversions.rb
File metadata and controls
84 lines (76 loc) · 2.5 KB
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
class Comment
def to_xml(options = {})
options[:indent] ||= 2
xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
xml.instruct! unless options[:skip_instruct]
xml.comment :id => id do
xml.tag! 'body', body
xml.tag! 'body-html', body_html
xml.tag! 'created-at', created_at.to_s(:db)
xml.tag! 'user-id', user_id
unless Array(options[:include]).include? :comments
xml.tag! 'project-id', project_id
xml.tag! 'target-id', target.id
xml.tag! 'target-type', target.class
end
if target.is_a? Task
xml.tag! 'assigned-id', assigned_id
xml.tag! 'previous-assigned-id', previous_assigned_id
xml.tag! 'previous-status', previous_status
xml.tag! 'status', status
end
if uploads.any?
xml.files :count => uploads.size do
for upload in uploads
upload.to_xml(options.merge({ :skip_instruct => true }))
end
end
end
end
end
def to_api_hash(options = {})
base = {
:id => id,
:body => body,
:body_html => body_html,
:created_at => created_at.to_s(:api_time),
:updated_at => updated_at.to_s(:api_time),
:user_id => user_id,
:project_id => project_id,
:target_id => target_id,
:target_type => target_type,
:hours => hours,
:upload_ids => upload_ids,
:google_doc_ids => google_doc_ids
}
base[:type] = self.class.to_s if options[:emit_type]
if target_type == 'Task'
base[:assigned_id] = assigned_id
base[:previous_assigned_id] = previous_assigned_id
base[:previous_status] = previous_status
base[:status] = status
base[:due_on] = due_on
base[:previous_due_on] = previous_due_on
base[:urgent] = urgent
base[:previous_urgent] = previous_urgent
end
if Array(options[:include]).include?(:uploads) && uploads.any?
base[:uploads] = uploads.map {|u| u.to_api_hash(options)}
end
if Array(options[:include]).include?(:google_docs) && google_docs.any?
base[:google_docs] = google_docs.map {|u| u.to_api_hash(options)}
end
if Array(options[:include]).include?(:assigned)
base[:assigned] = assigned
end
if Array(options[:include]).include? :user
base[:user] = {
:username => user.login,
:first_name => user.first_name,
:last_name => user.last_name,
:avatar_url => user.avatar_or_gravatar_url(:thumb)
}
end
base
end
end