kentaa-api 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da9bb3b58fe4533c642cd80ca677b29aff5e779aa1335ecbda2ba5c502133487
4
- data.tar.gz: 3ad011c17955567de318e2e1c8f959afd3ea3f6aad8d66381f0d2c48abd7c6e5
3
+ metadata.gz: 1aca25f29280f1c8b1ac63c17a8d8bac967c27a10975027ceaa163ca13a57a09
4
+ data.tar.gz: 7e9a8a9e7bcc65b8f63de8284db9e8550d238bf75dc8565a2eeb5f147f48e5c3
5
5
  SHA512:
6
- metadata.gz: 2b00e2f9db7313a96e4d205337ae9c2a9d9872d5ff97865246a6b1b391ae47cd615c2e736eac0ea5a6e890cb553bbfa66d5ddf31b83a60dc6d48f580912a430d
7
- data.tar.gz: 50f33d783a2055d71bdbf9bdc446be064bb109b71e04f6736e9dfb29b0dc670fe42001b89c218904405a218b3700c3d030fdd1c1292658b958ba77e62b9dafc3
6
+ metadata.gz: 5b5889b38da0cf1ed917460cfae3f2c4987c4fe62e48988f865dd1768c2106ca12d726e324f3d3c1f7199b8888848c93ecfcd93ff2a6de5bb6bff01a79418d9a
7
+ data.tar.gz: bd4b8963915d48a62f44082aa20225b1826c2a0eae40488084c138e78799f06787e7213d6d7bc8b2bd1e7f19de92f3ddbae7ad2e13ec6e2a47fb192d1187c57b
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 Peter Postma
3
+ Copyright (c) 2017-2021 Kentaa BV
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -11,11 +11,13 @@ This gem provides a Ruby library for communicating with the [Kentaa API](https:/
11
11
  - [Installation](#installation)
12
12
  - [Usage](#usage)
13
13
  - [Actions](#actions)
14
+ - [Companies](#companies)
14
15
  - [Donation forms](#donation-forms)
15
16
  - [Donations](#donations)
16
17
  - [Manual donations](#manual-donations)
17
18
  - [Newsletter subscriptions](#newsletter-subscriptions)
18
19
  - [Performances](#performances)
20
+ - [Photos](#performance-photos)
19
21
  - [Projects](#projects)
20
22
  - [Recurring donors](#recurring-donors)
21
23
  - [Segments](#segments)
@@ -99,6 +101,29 @@ action.title # => "Foobar"
99
101
 
100
102
  See also the [Kentaa API docs](https://developer.kentaa.nl/kentaa-api/#actions) and [Kentaa::Api::Resources::Action](lib/kentaa/api/resources/action.rb) for all available properties.
101
103
 
104
+
105
+ ### Companies
106
+
107
+ ```ruby
108
+ # List Companies
109
+ companies = client.companies # paginated
110
+ companies = client.companies.all # non-paginated
111
+
112
+ companies.each do |company|
113
+ company.title # => "Lorem ipsum"
114
+ company.url # => "https://demo1.kentaa.nl/bedrijven/kentaa-bv"
115
+ end
116
+
117
+ # Get Company by ID or slug
118
+ company = client.companies.get(1)
119
+ company = client.companies.get("kentaa-bv")
120
+
121
+ company.title # => "Lorem ipsum"
122
+ company.url # => "https://demo1.kentaa.nl/bedrijven/kentaa-bv"
123
+ ```
124
+
125
+ See also the [Kentaa API docs](https://developer.kentaa.nl/kentaa-api/#companies) and [Kentaa::Api::Resources::Company](lib/kentaa/api/resources/company.rb) for all available properties.
126
+
102
127
  ### Donation forms
103
128
 
104
129
  ```ruby
@@ -244,16 +269,43 @@ performance.title # => "First tour"
244
269
  performance.distance # => BigDecimal("65.25")
245
270
 
246
271
  # Update a Performance
247
- performance = action.performance.update(1, title: "Big tour")
272
+ performance = action.performances.update(1, title: "Big tour")
248
273
 
249
274
  performance.title # => "Big tour"
250
275
 
251
276
  # Delete a Performance
252
- action.performance.delete(1)
277
+ action.performances.delete(1)
253
278
  ```
254
279
 
255
280
  See also the [Kentaa API docs](https://developer.kentaa.nl/kentaa-api/#performances) and [Kentaa::Api::Resources::Performance](lib/kentaa/api/resources/performance.rb) for all available properties.
256
281
 
282
+ #### Performance photos
283
+
284
+ ```ruby
285
+ # List Performance photos
286
+ photos = performance.photos # paginated
287
+ photos = performance.photos.all # non-paginated
288
+
289
+ photos.each do |photo|
290
+ photos.image_url # => "https://d2a3ux41sjxpco.cloudfront.net/action_performance_photos/file/1/normal_8ce42aeb3bbb1b4964e621b42691f13d4dfa3f21.jpg"
291
+ end
292
+
293
+ # Get Performance photo
294
+ photo = performance.photos.get(1)
295
+
296
+ photo.image_url # => "https://d2a3ux41sjxpco.cloudfront.net/action_performance_photos/file/1/normal_8ce42aeb3bbb1b4964e621b42691f13d4dfa3f21.jpg"
297
+
298
+ # Create a Performance photo
299
+ photo = performance.photos.create(
300
+ io: File.open("photo.jpeg"),
301
+ content_type: "image/jpeg"
302
+ )
303
+
304
+ photo.image_url # => "https://d2a3ux41sjxpco.cloudfront.net/action_performance_photos/file/1/normal_8ce42aeb3bbb1b4964e621b42691f13d4dfa3f21.jpg"
305
+ ```
306
+
307
+ See also the [Kentaa API docs](https://developer.kentaa.nl/kentaa-api/#performances-photos) and [Kentaa::Api::Resources::PerformancePhoto](lib/kentaa/api/resources/performance_photo.rb) for all available properties.
308
+
257
309
  ### Projects
258
310
 
259
311
  ```ruby
@@ -272,7 +324,7 @@ project = client.projects.get("project")
272
324
 
273
325
  project.title # => "Dignissimos provident rerum enim alias magni asperna..."
274
326
  project.target_amount # => 250000
275
- project.url # => "https://demo1.kentaa.nl/project/dignissimos-provident-rerum-enim-alias-magni-asperna"
327
+ project.url # => "https://demo1.kentaa.nl/project/dignissimos-provident"
276
328
  ```
277
329
 
278
330
  See also the [Kentaa API docs](https://developer.kentaa.nl/kentaa-api/#projects) and [Kentaa::Api::Resources::Project](lib/kentaa/api/resources/project.rb) for all available properties.
@@ -422,7 +474,7 @@ You can iterate through the pages using the `.next` method and checking the resu
422
474
  ```ruby
423
475
  actions = client.actions
424
476
 
425
- loop do
477
+ loop do
426
478
  actions.each do |action|
427
479
  # Do something with actions
428
480
  end
@@ -473,4 +525,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Kentaa
473
525
  ## License
474
526
 
475
527
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
476
-
@@ -8,35 +8,39 @@ module Kentaa
8
8
  end
9
9
 
10
10
  def actions(options = {})
11
- Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::Action, endpoint_path: "/actions"))
11
+ Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::Action, endpoint_path: '/actions'))
12
+ end
13
+
14
+ def companies(options = {})
15
+ Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::Company, endpoint_path: '/companies'))
12
16
  end
13
17
 
14
18
  def donations(options = {})
15
- Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::Donation, endpoint_path: "/donations"))
19
+ Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::Donation, endpoint_path: '/donations'))
16
20
  end
17
21
 
18
22
  def donation_forms(options = {})
19
- Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::DonationForm, endpoint_path: "/donation-forms"))
23
+ Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::DonationForm, endpoint_path: '/donation-forms'))
20
24
  end
21
25
 
22
26
  def manual_donations(options = {})
23
- Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::ManualDonation, endpoint_path: "/manual-donations"))
27
+ Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::ManualDonation, endpoint_path: '/manual-donations'))
24
28
  end
25
29
 
26
30
  def newsletter_subscriptions(options = {})
27
- Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::NewsletterSubscription, endpoint_path: "/newsletter-subscriptions"))
31
+ Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::NewsletterSubscription, endpoint_path: '/newsletter-subscriptions'))
28
32
  end
29
33
 
30
34
  def projects(options = {})
31
- Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::Project, endpoint_path: "/projects"))
35
+ Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::Project, endpoint_path: '/projects'))
32
36
  end
33
37
 
34
38
  def recurring_donors(options = {})
35
- Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::RecurringDonor, endpoint_path: "/recurring-donors"))
39
+ Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::RecurringDonor, endpoint_path: '/recurring-donors'))
36
40
  end
37
41
 
38
42
  def segments(options = {})
39
- Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::Segment, endpoint_path: "/segments"))
43
+ Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::Segment, endpoint_path: '/segments'))
40
44
  end
41
45
 
42
46
  def sites(options = {})
@@ -44,7 +48,7 @@ module Kentaa
44
48
  end
45
49
 
46
50
  def teams(options = {})
47
- Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::Team, endpoint_path: "/teams"))
51
+ Kentaa::Api::Resources::List.new(@config, options.merge(resource_class: Kentaa::Api::Resources::Team, endpoint_path: '/teams'))
48
52
  end
49
53
 
50
54
  def users(options = {})
@@ -3,9 +3,9 @@
3
3
  module Kentaa
4
4
  module Api
5
5
  class Config
6
- LIVE_URL = "https://api.kentaa.nl/v1"
7
- TEST_URL = "https://api.kentaa.staatklaar.nu/v1"
8
- DEV_URL = "http://api.lvh.me:3000/v1"
6
+ LIVE_URL = 'https://api.kentaa.nl/v1'
7
+ TEST_URL = 'https://api.kentaa.staatklaar.nu/v1'
8
+ DEV_URL = 'http://api.lvh.me:3000/v1'
9
9
 
10
10
  attr_accessor :options
11
11
 
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kentaa
4
+ module Api
5
+ module Deprecation
6
+ module_function
7
+
8
+ def warn(message, callstack = caller)
9
+ Kernel.warn("DEPRECATION WARNING: #{message} (called from #{callstack.first})")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -13,37 +13,48 @@ module Kentaa
13
13
  @config = config
14
14
  end
15
15
 
16
- def get(path, params = {})
17
- request(:get, path, params)
16
+ def get(path, params = {}, options = {})
17
+ request(:get, path, params, nil, options)
18
18
  end
19
19
 
20
- def post(path, params = {}, body = {})
21
- request(:post, path, params, body)
20
+ def post(path, params = {}, body = {}, options = {})
21
+ request(:post, path, params, body, options)
22
22
  end
23
23
 
24
- def patch(path, params = {}, body = {})
25
- request(:patch, path, params, body)
24
+ def patch(path, params = {}, body = {}, options = {})
25
+ request(:patch, path, params, body, options)
26
26
  end
27
27
 
28
- def delete(path, params = {})
29
- request(:delete, path, params)
28
+ def delete(path, params = {}, options = {})
29
+ request(:delete, path, params, nil, options)
30
30
  end
31
31
 
32
32
  private
33
33
 
34
- def request(http_method, path, params = {}, body = {})
34
+ def request(http_method, path, params = {}, body = nil, options = {})
35
35
  uri = URI.parse(File.join(config.api_url, path))
36
36
  uri.query = URI.encode_www_form(params) unless params.empty?
37
37
 
38
+ content_type = options.fetch(:content_type, 'application/json')
39
+
40
+ # Body can be passed as an IO-like object or an object that can be serialized to JSON.
41
+ if body
42
+ if body.respond_to?(:read)
43
+ body = body.read
44
+ elsif body.respond_to?(:to_json)
45
+ body = body.to_json
46
+ end
47
+ end
48
+
38
49
  case http_method
39
50
  when :get
40
51
  request = Net::HTTP::Get.new(uri)
41
52
  when :post
42
53
  request = Net::HTTP::Post.new(uri)
43
- request.body = body.to_json
54
+ request.body = body
44
55
  when :patch
45
56
  request = Net::HTTP::Patch.new(uri)
46
- request.body = body.to_json
57
+ request.body = body
47
58
  when :delete
48
59
  request = Net::HTTP::Delete.new(uri)
49
60
  else
@@ -52,13 +63,13 @@ module Kentaa
52
63
 
53
64
  logger.debug("[Kentaa-API] Request: #{http_method.upcase} #{uri}") if config.debug?
54
65
 
55
- request["Accept"] = "application/json"
56
- request["Content-Type"] = "application/json"
57
- request["X-Api-Key"] = config.api_key
58
- request["User-Agent"] = "Ruby kentaa-api/#{Kentaa::Api::VERSION}"
66
+ request['Accept'] = 'application/json'
67
+ request['Content-Type'] = content_type
68
+ request['X-Api-Key'] = config.api_key
69
+ request['User-Agent'] = "Ruby kentaa-api/#{Kentaa::Api::VERSION}"
59
70
 
60
71
  client = Net::HTTP.new(uri.hostname, uri.port)
61
- client.use_ssl = uri.scheme == "https"
72
+ client.use_ssl = uri.scheme == 'https'
62
73
  client.verify_mode = OpenSSL::SSL::VERIFY_PEER
63
74
 
64
75
  begin
@@ -72,9 +83,7 @@ module Kentaa
72
83
 
73
84
  logger.debug("[Kentaa-API] Response: #{response.http_code}, body: #{response.body}") if config.debug?
74
85
 
75
- if response.error?
76
- raise Kentaa::Api::RequestError, response
77
- end
86
+ raise Kentaa::Api::RequestError, response if response.error?
78
87
 
79
88
  response
80
89
  end
@@ -7,6 +7,9 @@ module Kentaa
7
7
  module Api
8
8
  module Resources
9
9
  class Action < Resource
10
+ WHO_TYPE_OWNER = 'owner'
11
+ WHO_TYPE_OTHER = 'other'
12
+
10
13
  def object_key
11
14
  "Action_#{id}"
12
15
  end
@@ -55,6 +58,18 @@ module Kentaa
55
58
  data.fetch(:team_captain, false)
56
59
  end
57
60
 
61
+ def who_type
62
+ data[:who_type]
63
+ end
64
+
65
+ def owner?
66
+ who_type == WHO_TYPE_OWNER
67
+ end
68
+
69
+ def other?
70
+ who_type == WHO_TYPE_OTHER
71
+ end
72
+
58
73
  def first_name
59
74
  data[:first_name]
60
75
  end
@@ -72,7 +87,7 @@ module Kentaa
72
87
  end
73
88
 
74
89
  def name
75
- [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
90
+ [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(' ')
76
91
  end
77
92
 
78
93
  def fundraiser_page?
@@ -124,7 +139,7 @@ module Kentaa
124
139
  end
125
140
 
126
141
  def activity
127
- @activity ||= Kentaa::Api::Resources::Activity.new(data[:activity])
142
+ @activity ||= Kentaa::Api::Resources::Activity.new(data[:activity]) if data[:activity]
128
143
  end
129
144
 
130
145
  def previous_participations
@@ -190,9 +205,25 @@ module Kentaa
190
205
  end
191
206
 
192
207
  def consent
208
+ Kentaa::Api::Deprecation.warn('#consent is deprecated. Please use #consents instead.', caller)
209
+
193
210
  @consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
194
211
  end
195
212
 
213
+ def consents
214
+ @consents ||= begin
215
+ consents = []
216
+
217
+ if data[:consents]
218
+ data[:consents].each do |consent|
219
+ consents << Kentaa::Api::Resources::Consent.new(consent)
220
+ end
221
+ end
222
+
223
+ consents
224
+ end
225
+ end
226
+
196
227
  def external_reference
197
228
  data[:external_reference]
198
229
  end
@@ -205,8 +236,8 @@ module Kentaa
205
236
  @manual_donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::ManualDonation, endpoint_path: "/actions/#{id}/manual-donations")
206
237
  end
207
238
 
208
- def performances
209
- @performances ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Performance, endpoint_path: "/actions/#{id}/performances")
239
+ def performances(options = {})
240
+ @performances ||= Kentaa::Api::Resources::List.new(config, options.merge(resource_class: Kentaa::Api::Resources::Performance, endpoint_path: "/actions/#{id}/performances"))
210
241
  end
211
242
 
212
243
  private
@@ -216,7 +247,7 @@ module Kentaa
216
247
  end
217
248
 
218
249
  def create_resource(attributes)
219
- request.post("/actions", options, attributes)
250
+ request.post('/actions', options, attributes)
220
251
  end
221
252
 
222
253
  def update_resource(attributes)
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kentaa
4
+ module Api
5
+ module Resources
6
+ class Billing
7
+ attr_reader :data
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+
13
+ def attn
14
+ data[:attn]
15
+ end
16
+
17
+ def street
18
+ data[:street]
19
+ end
20
+
21
+ def house_number
22
+ data[:house_number]
23
+ end
24
+
25
+ def house_number_addition
26
+ data[:house_number_addition]
27
+ end
28
+
29
+ def address
30
+ data[:address]
31
+ end
32
+
33
+ def address2
34
+ data[:address2]
35
+ end
36
+
37
+ def zipcode
38
+ data[:zipcode]
39
+ end
40
+
41
+ def city
42
+ data[:city]
43
+ end
44
+
45
+ def country
46
+ data[:country]
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,218 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bigdecimal'
4
+ require 'time'
5
+
6
+ module Kentaa
7
+ module Api
8
+ module Resources
9
+ class Company < Resource
10
+ def object_key
11
+ "Company_#{id}"
12
+ end
13
+
14
+ def parent
15
+ if project_id
16
+ Kentaa::Api::Resources::Project.new(config, id: project_id, options: options)
17
+ elsif segment_id
18
+ Kentaa::Api::Resources::Segment.new(config, id: segment_id, options: options)
19
+ else
20
+ Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
21
+ end
22
+ end
23
+
24
+ def site
25
+ Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
26
+ end
27
+
28
+ def slug
29
+ data[:slug]
30
+ end
31
+
32
+ def site_id
33
+ data[:site_id]
34
+ end
35
+
36
+ def segment_id
37
+ data[:segment_id]
38
+ end
39
+
40
+ def project_id
41
+ data[:project_id]
42
+ end
43
+
44
+ def owner
45
+ @owner ||= Kentaa::Api::Resources::User.new(config, data: data[:owner], options: options)
46
+ end
47
+
48
+ def members
49
+ @members ||= begin
50
+ members = []
51
+
52
+ if data[:members]
53
+ data[:members].each do |member|
54
+ members << Kentaa::Api::Resources::Action.new(config, data: member, options: options)
55
+ end
56
+ end
57
+
58
+ members
59
+ end
60
+ end
61
+
62
+ def name
63
+ data[:name]
64
+ end
65
+
66
+ def title
67
+ data[:title]
68
+ end
69
+
70
+ def description
71
+ data[:description]
72
+ end
73
+
74
+ def target_amount
75
+ data[:target_amount]
76
+ end
77
+
78
+ def total_amount
79
+ BigDecimal(data[:total_amount])
80
+ end
81
+
82
+ def total_donations
83
+ data[:total_donations]
84
+ end
85
+
86
+ def target_amount_achieved?
87
+ data[:target_amount_achieved]
88
+ end
89
+
90
+ def visible?
91
+ data[:visible]
92
+ end
93
+
94
+ def countable?
95
+ data[:countable]
96
+ end
97
+
98
+ def closed?
99
+ data[:closed]
100
+ end
101
+
102
+ def ended?
103
+ data[:ended]
104
+ end
105
+
106
+ def end_date
107
+ Time.parse(data[:end_date]) if data[:end_date]
108
+ end
109
+
110
+ def url
111
+ data[:url]
112
+ end
113
+
114
+ def donate_url
115
+ data[:donate_url]
116
+ end
117
+
118
+ def member_sign_up_url
119
+ data[:member_sign_up_url]
120
+ end
121
+
122
+ def photos
123
+ @photos ||= begin
124
+ photos = []
125
+
126
+ if data[:photos]
127
+ data[:photos].each do |photo|
128
+ photos << Kentaa::Api::Resources::Photo.new(photo)
129
+ end
130
+ end
131
+
132
+ photos
133
+ end
134
+ end
135
+
136
+ def videos
137
+ @videos ||= begin
138
+ videos = []
139
+
140
+ if data[:videos]
141
+ data[:videos].each do |video|
142
+ videos << Kentaa::Api::Resources::Video.new(video)
143
+ end
144
+ end
145
+
146
+ videos
147
+ end
148
+ end
149
+
150
+ def questions
151
+ @questions ||= begin
152
+ questions = []
153
+
154
+ if data[:questions]
155
+ data[:questions].each do |question|
156
+ questions << Kentaa::Api::Resources::Question.new(question)
157
+ end
158
+ end
159
+
160
+ questions
161
+ end
162
+ end
163
+
164
+ def company_package
165
+ @company_package ||= Kentaa::Api::Resources::CompanyPackage.new(data[:package]) if data[:package]
166
+ end
167
+
168
+ def activity
169
+ @activity ||= Kentaa::Api::Resources::Activity.new(data[:activity]) if data[:activity]
170
+ end
171
+
172
+ def contact
173
+ @contact ||= Kentaa::Api::Resources::Contact.new(data[:contact]) if data[:contact]
174
+ end
175
+
176
+ def external_reference
177
+ data[:external_reference]
178
+ end
179
+
180
+ def commerce_number
181
+ data[:commerce_number]
182
+ end
183
+
184
+ def consents
185
+ @consents ||= begin
186
+ consents = []
187
+
188
+ if data[:consents]
189
+ data[:consents].each do |consent|
190
+ consents << Kentaa::Api::Resources::Consent.new(consent)
191
+ end
192
+ end
193
+
194
+ consents
195
+ end
196
+ end
197
+
198
+ def billing
199
+ @billing ||= Kentaa::Api::Resources::Billing.new(data[:billing]) if data[:billing]
200
+ end
201
+
202
+ def donations
203
+ @donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Donation, endpoint_path: "/companies/#{id}/donations")
204
+ end
205
+
206
+ def manual_donations
207
+ @manual_donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::ManualDonation, endpoint_path: "/companies/#{id}/manual-donations")
208
+ end
209
+
210
+ private
211
+
212
+ def load_resource
213
+ request.get("/companies/#{id}", options)
214
+ end
215
+ end
216
+ end
217
+ end
218
+ end