-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteam.rb
184 lines (143 loc) · 3.84 KB
/
team.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# frozen_string_literal: true
require 'bigdecimal'
require 'time'
module Kentaa
module Api
module Resources
class Team < Resource
def object_key
"Team_#{id}"
end
def parent
if project_id
Kentaa::Api::Resources::Project.new(config, id: project_id, options: options)
elsif segment_id
Kentaa::Api::Resources::Segment.new(config, id: segment_id, options: options)
else
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
end
end
def site
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
end
def slug
data[:slug]
end
def site_id
data[:site_id]
end
def segment_id
data[:segment_id]
end
def project_id
data[:project_id]
end
def owner
@owner ||= Kentaa::Api::Resources::User.new(config, data: data[:owner], options: options)
end
def members
@members ||= begin
members = []
if data[:members]
data[:members].each do |member|
members << Kentaa::Api::Resources::Action.new(config, data: member, options: options)
end
end
members
end
end
def name
data[:name]
end
def title
data[:title]
end
def description
data[:description]
end
def total_team_members
data[:total_team_members]
end
def target_amount
data[:target_amount]
end
def total_amount
BigDecimal(data[:total_amount])
end
def total_donations
data[:total_donations]
end
def target_amount_achieved?
data[:target_amount_achieved]
end
def visible?
data[:visible]
end
def countable?
data[:countable]
end
def closed?
data[:closed]
end
def ended?
data[:ended]
end
def end_date
Time.parse(data[:end_date]) if data[:end_date]
end
def url
data[:url]
end
def donate_url
data[:donate_url]
end
def photos
@photos ||= begin
photos = []
if data[:photos]
data[:photos].each do |photo|
photos << Kentaa::Api::Resources::Photo.new(photo)
end
end
photos
end
end
def videos
@videos ||= begin
videos = []
if data[:videos]
data[:videos].each do |video|
videos << Kentaa::Api::Resources::Video.new(video)
end
end
videos
end
end
def questions
@questions ||= begin
questions = []
if data[:questions]
data[:questions].each do |question|
questions << Kentaa::Api::Resources::Question.new(question)
end
end
questions
end
end
def external_reference
data[:external_reference]
end
def donations
@donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Donation, endpoint_path: "/teams/#{id}/donations")
end
def manual_donations
@manual_donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::ManualDonation, endpoint_path: "/teams/#{id}/manual-donations")
end
private
def load_resource
request.get("/teams/#{id}", options)
end
end
end
end
end