Class: Kentaa::Api::Resources::Action

Inherits:
Resource show all
Defined in:
lib/kentaa/api/resources/action.rb

Constant Summary collapse

WHO_TYPE_OWNER =
'owner'
WHO_TYPE_OTHER =
'other'

Instance Attribute Summary

Attributes inherited from Resource

#id

Attributes inherited from Base

#config, #endpoint_path, #options, #resource_class

Instance Method Summary collapse

Methods inherited from Resource

#create, #created_at, #delete, #initialize, #load, #save, #updated_at

Methods inherited from Base

attribute_key, #initialize, #load, #loaded?

Constructor Details

This class inherits a constructor from Kentaa::Api::Resources::Resource

Instance Method Details

#activityObject



147
148
149
# File 'lib/kentaa/api/resources/action.rb', line 147

def activity
  @activity ||= Kentaa::Api::Resources::Activity.new(config, data: data[:activity]) if data[:activity]
end

#avatar_urlObject



91
92
93
# File 'lib/kentaa/api/resources/action.rb', line 91

def avatar_url
  data[:avatar_url]
end

#closed?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/kentaa/api/resources/action.rb', line 135

def closed?
  data[:closed]
end

#company_idObject



51
52
53
# File 'lib/kentaa/api/resources/action.rb', line 51

def company_id
  data[:company_id]
end


217
218
219
220
221
# File 'lib/kentaa/api/resources/action.rb', line 217

def consent
  Kentaa::Api::Deprecation.warn('#consent is deprecated. Please use #consents instead.', caller)

  @consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
end

#consentsObject



223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/kentaa/api/resources/action.rb', line 223

def consents
  @consents ||= begin
    consents = []

    if data[:consents]
      data[:consents].each do |consent|
        consents << Kentaa::Api::Resources::Consent.new(consent)
      end
    end

    consents
  end
end

#countable?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/kentaa/api/resources/action.rb', line 131

def countable?
  data[:countable]
end

#descriptionObject



107
108
109
# File 'lib/kentaa/api/resources/action.rb', line 107

def description
  data[:description]
end


159
160
161
# File 'lib/kentaa/api/resources/action.rb', line 159

def donate_url
  data[:donate_url]
end

#donationsObject



241
242
243
# File 'lib/kentaa/api/resources/action.rb', line 241

def donations
  @donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Donation, endpoint_path: "/actions/#{id}/donations")
end

#end_dateObject



143
144
145
# File 'lib/kentaa/api/resources/action.rb', line 143

def end_date
  Time.parse(data[:end_date]) if data[:end_date]
end

#ended?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/kentaa/api/resources/action.rb', line 139

def ended?
  data[:ended]
end

#external_referenceObject



237
238
239
# File 'lib/kentaa/api/resources/action.rb', line 237

def external_reference
  data[:external_reference]
end

#first_nameObject



79
80
81
# File 'lib/kentaa/api/resources/action.rb', line 79

def first_name
  data[:first_name]
end

#fundraiser_page?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/kentaa/api/resources/action.rb', line 99

def fundraiser_page?
  data[:fundraiser_page]
end

#infixObject



83
84
85
# File 'lib/kentaa/api/resources/action.rb', line 83

def infix
  data[:infix]
end

#last_nameObject



87
88
89
# File 'lib/kentaa/api/resources/action.rb', line 87

def last_name
  data[:last_name]
end

#locationObject



171
172
173
# File 'lib/kentaa/api/resources/action.rb', line 171

def location
  @location ||= Kentaa::Api::Resources::Location.new(data[:location]) if data[:location]
end

#manual_donationsObject



245
246
247
# File 'lib/kentaa/api/resources/action.rb', line 245

def manual_donations
  @manual_donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::ManualDonation, endpoint_path: "/actions/#{id}/manual-donations")
end

#nameObject



95
96
97
# File 'lib/kentaa/api/resources/action.rb', line 95

def name
  [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(' ')
end

#object_keyObject



13
14
15
# File 'lib/kentaa/api/resources/action.rb', line 13

def object_key
  "Action_#{id}"
end

#ordersObject



249
250
251
# File 'lib/kentaa/api/resources/action.rb', line 249

def orders
  @orders ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Order, endpoint_path: "/actions/#{id}/orders")
end

#other?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/kentaa/api/resources/action.rb', line 75

def other?
  who_type == WHO_TYPE_OTHER
end

#ownerObject



59
60
61
# File 'lib/kentaa/api/resources/action.rb', line 59

def owner
  @owner ||= Kentaa::Api::Resources::User.new(config, data: data[:owner], options: options)
end

#owner?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/kentaa/api/resources/action.rb', line 71

def owner?
  who_type == WHO_TYPE_OWNER
end

#parentObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kentaa/api/resources/action.rb', line 17

def parent
  if team_id
    Kentaa::Api::Resources::Team.new(config, id: team_id, options: options)
  elsif company_id
    Kentaa::Api::Resources::Company.new(config, id: company_id, options: options)
  elsif 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

#performances(options = {}) ⇒ Object



253
254
255
# File 'lib/kentaa/api/resources/action.rb', line 253

def performances(options = {})
  @performances ||= Kentaa::Api::Resources::List.new(config, options.merge(resource_class: Kentaa::Api::Resources::Performance, endpoint_path: "/actions/#{id}/performances"))
end

#photosObject



175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/kentaa/api/resources/action.rb', line 175

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

#previous_participationsObject



151
152
153
# File 'lib/kentaa/api/resources/action.rb', line 151

def previous_participations
  data[:previous_participations]
end

#project_idObject



47
48
49
# File 'lib/kentaa/api/resources/action.rb', line 47

def project_id
  data[:project_id]
end

#questionsObject



203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/kentaa/api/resources/action.rb', line 203

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

#registration_feeObject



163
164
165
# File 'lib/kentaa/api/resources/action.rb', line 163

def registration_fee
  @registration_fee ||= Kentaa::Api::Resources::RegistrationFee.new(data[:registration_fee]) if data[:registration_fee]
end

#segment_idObject



43
44
45
# File 'lib/kentaa/api/resources/action.rb', line 43

def segment_id
  data[:segment_id]
end

#siteObject



31
32
33
# File 'lib/kentaa/api/resources/action.rb', line 31

def site
  Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
end

#site_idObject



39
40
41
# File 'lib/kentaa/api/resources/action.rb', line 39

def site_id
  data[:site_id]
end

#slugObject



35
36
37
# File 'lib/kentaa/api/resources/action.rb', line 35

def slug
  data[:slug]
end

#target_amountObject



111
112
113
# File 'lib/kentaa/api/resources/action.rb', line 111

def target_amount
  data[:target_amount]
end

#target_amount_achieved?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/kentaa/api/resources/action.rb', line 123

def target_amount_achieved?
  data[:target_amount_achieved]
end

#team_captain?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/kentaa/api/resources/action.rb', line 63

def team_captain?
  data.fetch(:team_captain, false)
end

#team_idObject



55
56
57
# File 'lib/kentaa/api/resources/action.rb', line 55

def team_id
  data[:team_id]
end

#ticketObject



167
168
169
# File 'lib/kentaa/api/resources/action.rb', line 167

def ticket
  @ticket ||= Kentaa::Api::Resources::Ticket.new(data[:ticket]) if data[:ticket]
end

#titleObject



103
104
105
# File 'lib/kentaa/api/resources/action.rb', line 103

def title
  data[:title]
end

#total_amountObject



115
116
117
# File 'lib/kentaa/api/resources/action.rb', line 115

def total_amount
  BigDecimal(data[:total_amount])
end

#total_donationsObject



119
120
121
# File 'lib/kentaa/api/resources/action.rb', line 119

def total_donations
  data[:total_donations]
end

#urlObject



155
156
157
# File 'lib/kentaa/api/resources/action.rb', line 155

def url
  data[:url]
end

#videosObject



189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/kentaa/api/resources/action.rb', line 189

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

#visible?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/kentaa/api/resources/action.rb', line 127

def visible?
  data[:visible]
end

#who_typeObject



67
68
69
# File 'lib/kentaa/api/resources/action.rb', line 67

def who_type
  data[:who_type]
end