-
Notifications
You must be signed in to change notification settings - Fork 0
/
segment.rb
120 lines (92 loc) · 2.96 KB
/
segment.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
# frozen_string_literal: true
require 'bigdecimal'
require 'time'
module Kentaa
module Api
module Resources
class Segment < Resource
def object_key
"Segment_#{id}"
end
def parent
site
end
def site
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
end
def site_id
data[:site_id]
end
def subdomain
data[:subdomain]
end
def name
data[:name]
end
def title
data[:title]
end
def description
data[:description]
end
def target_amount
data[:target_amount]
end
def total_amount
BigDecimal(data[:total_amount])
end
def total_donations
data[:total_donations]
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 banners
@banners ||= begin
banners = []
if data[:banners]
data[:banners].each do |banner|
banners << Kentaa::Api::Resources::Banner.new(banner)
end
end
banners
end
end
def external_reference
data[:external_reference]
end
def actions
@actions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Action, endpoint_path: "/segments/#{id}/actions")
end
def teams
@teams ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Team, endpoint_path: "/segments/#{id}/teams")
end
def projects
@projects ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Project, endpoint_path: "/segments/#{id}/projects")
end
def donations
@donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Donation, endpoint_path: "/segments/#{id}/donations")
end
def manual_donations
@manual_donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::ManualDonation, endpoint_path: "/segments/#{id}/manual-donations")
end
def newsletter_subscriptions
@newsletter_subscriptions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::NewsletterSubscription, endpoint_path: "/segments/#{id}/newsletter-subscriptions")
end
def activities
@activities ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Activity, endpoint_path: "/segments/#{id}/activities")
end
private
def load_resource
request.get("/segments/#{id}", options)
end
end
end
end
end