kentaa-api 0.3.0 → 0.6.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 +4 -4
- data/.github/workflows/test.yml +23 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +21 -5
- data/Gemfile +4 -2
- data/Gemfile.lock +45 -32
- data/README.md +364 -67
- data/kentaa-api.gemspec +3 -3
- data/lib/kentaa/api.rb +9 -20
- data/lib/kentaa/api/client.rb +30 -18
- data/lib/kentaa/api/config.rb +10 -3
- data/lib/kentaa/api/exception.rb +9 -2
- data/lib/kentaa/api/request.rb +49 -5
- data/lib/kentaa/api/resources/action.rb +39 -15
- data/lib/kentaa/api/resources/activity.rb +11 -1
- data/lib/kentaa/api/resources/address.rb +7 -1
- data/lib/kentaa/api/resources/banner.rb +21 -1
- data/lib/kentaa/api/resources/base.rb +19 -6
- data/lib/kentaa/api/resources/consent.rb +7 -1
- data/lib/kentaa/api/resources/contact.rb +83 -0
- data/lib/kentaa/api/resources/donation.rb +30 -12
- data/lib/kentaa/api/resources/donation_form.rb +104 -0
- data/lib/kentaa/api/resources/error.rb +23 -0
- data/lib/kentaa/api/resources/list.rb +77 -2
- data/lib/kentaa/api/resources/location.rb +7 -1
- data/lib/kentaa/api/resources/manual_donation.rb +122 -0
- data/lib/kentaa/api/resources/newsletter_subscription.rb +16 -6
- data/lib/kentaa/api/resources/performance.rb +62 -0
- data/lib/kentaa/api/resources/photo.rb +21 -1
- data/lib/kentaa/api/resources/project.rb +37 -9
- data/lib/kentaa/api/resources/question.rb +19 -1
- data/lib/kentaa/api/resources/recurring_donor.rb +110 -0
- data/lib/kentaa/api/resources/registration_fee.rb +1 -1
- data/lib/kentaa/api/resources/resource.rb +43 -5
- data/lib/kentaa/api/resources/reward.rb +11 -1
- data/lib/kentaa/api/resources/segment.rb +35 -3
- data/lib/kentaa/api/resources/site.rb +15 -3
- data/lib/kentaa/api/{clients → resources}/sites.rb +2 -2
- data/lib/kentaa/api/resources/team.rb +22 -10
- data/lib/kentaa/api/resources/user.rb +16 -4
- data/lib/kentaa/api/resources/users.rb +5 -24
- data/lib/kentaa/api/resources/video.rb +21 -1
- data/lib/kentaa/api/response.rb +20 -2
- data/lib/kentaa/api/util.rb +13 -0
- data/lib/kentaa/api/version.rb +1 -1
- metadata +21 -30
- data/.travis.yml +0 -11
- data/lib/kentaa/api/clients/actions.rb +0 -21
- data/lib/kentaa/api/clients/all.rb +0 -26
- data/lib/kentaa/api/clients/base.rb +0 -15
- data/lib/kentaa/api/clients/donations.rb +0 -21
- data/lib/kentaa/api/clients/newsletter_subscriptions.rb +0 -21
- data/lib/kentaa/api/clients/projects.rb +0 -21
- data/lib/kentaa/api/clients/segments.rb +0 -21
- data/lib/kentaa/api/clients/teams.rb +0 -21
- data/lib/kentaa/api/clients/users.rb +0 -21
- data/lib/kentaa/api/finder.rb +0 -44
- data/lib/kentaa/api/resources/actions.rb +0 -37
- data/lib/kentaa/api/resources/donations.rb +0 -37
- data/lib/kentaa/api/resources/newsletter_subscriptions.rb +0 -37
- data/lib/kentaa/api/resources/projects.rb +0 -37
- data/lib/kentaa/api/resources/segments.rb +0 -37
- data/lib/kentaa/api/resources/teams.rb +0 -37
@@ -1,9 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'time'
|
4
|
+
|
3
5
|
module Kentaa
|
4
6
|
module Api
|
5
7
|
module Resources
|
6
|
-
class Banner
|
8
|
+
class Banner
|
9
|
+
attr_reader :data
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
@data = data
|
13
|
+
end
|
14
|
+
|
15
|
+
def id
|
16
|
+
data[:id]
|
17
|
+
end
|
18
|
+
|
19
|
+
def created_at
|
20
|
+
Time.parse(data[:created_at]) if data[:created_at]
|
21
|
+
end
|
22
|
+
|
23
|
+
def updated_at
|
24
|
+
Time.parse(data[:updated_at]) if data[:updated_at]
|
25
|
+
end
|
26
|
+
|
7
27
|
def url
|
8
28
|
data[:url]
|
9
29
|
end
|
@@ -4,15 +4,29 @@ module Kentaa
|
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
6
|
class Base
|
7
|
-
attr_reader :config, :options
|
7
|
+
attr_reader :config, :options, :resource_class, :endpoint_path
|
8
8
|
|
9
9
|
def initialize(config, options = {})
|
10
10
|
@config = config
|
11
11
|
@options = options
|
12
|
+
@resource_class = options.delete(:resource_class) || self.class
|
13
|
+
@endpoint_path = options.delete(:endpoint_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def attribute_key
|
18
|
+
class_name = name.split('::').last
|
19
|
+
class_name.gsub(/([^\^])([A-Z])/, '\1_\2').downcase
|
20
|
+
end
|
12
21
|
end
|
13
22
|
|
14
23
|
def load
|
15
|
-
@response ||=
|
24
|
+
@response ||=
|
25
|
+
if block_given?
|
26
|
+
yield
|
27
|
+
else
|
28
|
+
load_resource
|
29
|
+
end
|
16
30
|
|
17
31
|
self
|
18
32
|
end
|
@@ -24,11 +38,10 @@ module Kentaa
|
|
24
38
|
private
|
25
39
|
|
26
40
|
def attribute_key
|
27
|
-
|
28
|
-
class_name.gsub(/([^\^])([A-Z])/, '\1_\2').downcase.to_sym
|
41
|
+
self.class.attribute_key
|
29
42
|
end
|
30
43
|
|
31
|
-
def load_resource
|
44
|
+
def load_resource
|
32
45
|
raise NotImplementedError
|
33
46
|
end
|
34
47
|
|
@@ -36,7 +49,7 @@ module Kentaa
|
|
36
49
|
@data ||= begin
|
37
50
|
load unless loaded?
|
38
51
|
|
39
|
-
@response.body[attribute_key] || {}
|
52
|
+
@response.body[attribute_key.to_sym] || {}
|
40
53
|
end
|
41
54
|
end
|
42
55
|
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kentaa
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Contact
|
7
|
+
attr_reader :data
|
8
|
+
|
9
|
+
def initialize(data)
|
10
|
+
@data = data
|
11
|
+
end
|
12
|
+
|
13
|
+
def first_name
|
14
|
+
data[:first_name]
|
15
|
+
end
|
16
|
+
|
17
|
+
def infix
|
18
|
+
data[:infix]
|
19
|
+
end
|
20
|
+
|
21
|
+
def last_name
|
22
|
+
data[:last_name]
|
23
|
+
end
|
24
|
+
|
25
|
+
def name
|
26
|
+
[first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
|
27
|
+
end
|
28
|
+
|
29
|
+
def email
|
30
|
+
data[:email]
|
31
|
+
end
|
32
|
+
|
33
|
+
def avatar_url
|
34
|
+
data[:avatar_url]
|
35
|
+
end
|
36
|
+
|
37
|
+
def address
|
38
|
+
data[:address]
|
39
|
+
end
|
40
|
+
|
41
|
+
def address2
|
42
|
+
data[:address2]
|
43
|
+
end
|
44
|
+
|
45
|
+
def street
|
46
|
+
data[:street]
|
47
|
+
end
|
48
|
+
|
49
|
+
def house_number
|
50
|
+
data[:house_number]
|
51
|
+
end
|
52
|
+
|
53
|
+
def house_number_addition
|
54
|
+
data[:house_number_addition]
|
55
|
+
end
|
56
|
+
|
57
|
+
def zipcode
|
58
|
+
data[:zipcode]
|
59
|
+
end
|
60
|
+
|
61
|
+
def city
|
62
|
+
data[:city]
|
63
|
+
end
|
64
|
+
|
65
|
+
def country
|
66
|
+
data[:country]
|
67
|
+
end
|
68
|
+
|
69
|
+
def phone
|
70
|
+
data[:phone]
|
71
|
+
end
|
72
|
+
|
73
|
+
def birthday
|
74
|
+
Date.parse(data[:birthday]) if data[:birthday]
|
75
|
+
end
|
76
|
+
|
77
|
+
def gender
|
78
|
+
data[:gender]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -13,22 +13,32 @@ module Kentaa
|
|
13
13
|
|
14
14
|
def entity
|
15
15
|
if action_id
|
16
|
-
Kentaa::Api::Resources::Action.new(config, id: action_id)
|
16
|
+
Kentaa::Api::Resources::Action.new(config, id: action_id, options: options)
|
17
17
|
elsif team_id
|
18
|
-
Kentaa::Api::Resources::Team.new(config, id: team_id)
|
18
|
+
Kentaa::Api::Resources::Team.new(config, id: team_id, options: options)
|
19
19
|
elsif project_id
|
20
|
-
Kentaa::Api::Resources::Project.new(config, id: project_id)
|
20
|
+
Kentaa::Api::Resources::Project.new(config, id: project_id, options: options)
|
21
21
|
elsif segment_id
|
22
|
-
Kentaa::Api::Resources::Segment.new(config, id: segment_id)
|
22
|
+
Kentaa::Api::Resources::Segment.new(config, id: segment_id, options: options)
|
23
|
+
elsif donation_form_id
|
24
|
+
Kentaa::Api::Resources::DonationForm.new(config, id: donation_form_id, options: options)
|
23
25
|
else
|
24
|
-
Kentaa::Api::Resources::Site.new(config, id: site_id)
|
26
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
30
|
+
def site
|
31
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
|
32
|
+
end
|
33
|
+
|
28
34
|
def site_id
|
29
35
|
data[:site_id]
|
30
36
|
end
|
31
37
|
|
38
|
+
def donation_form_id
|
39
|
+
data[:donation_form_id]
|
40
|
+
end
|
41
|
+
|
32
42
|
def segment_id
|
33
43
|
data[:segment_id]
|
34
44
|
end
|
@@ -101,6 +111,10 @@ module Kentaa
|
|
101
111
|
BigDecimal(data[:transaction_costs]) if data[:transaction_costs]
|
102
112
|
end
|
103
113
|
|
114
|
+
def start_donation?
|
115
|
+
data[:start_donation]
|
116
|
+
end
|
117
|
+
|
104
118
|
def registration_fee?
|
105
119
|
data[:registration_fee]
|
106
120
|
end
|
@@ -113,6 +127,10 @@ module Kentaa
|
|
113
127
|
BigDecimal(data[:total_amount])
|
114
128
|
end
|
115
129
|
|
130
|
+
def receivable_amount
|
131
|
+
BigDecimal(data[:receivable_amount])
|
132
|
+
end
|
133
|
+
|
116
134
|
def countable?
|
117
135
|
data[:countable]
|
118
136
|
end
|
@@ -167,7 +185,7 @@ module Kentaa
|
|
167
185
|
|
168
186
|
if data[:questions]
|
169
187
|
data[:questions].each do |question|
|
170
|
-
questions << Kentaa::Api::Resources::Question.new(
|
188
|
+
questions << Kentaa::Api::Resources::Question.new(question)
|
171
189
|
end
|
172
190
|
end
|
173
191
|
|
@@ -176,15 +194,15 @@ module Kentaa
|
|
176
194
|
end
|
177
195
|
|
178
196
|
def reward
|
179
|
-
@reward ||= Kentaa::Api::Resources::Reward.new(
|
197
|
+
@reward ||= Kentaa::Api::Resources::Reward.new(data[:reward]) if data[:reward]
|
180
198
|
end
|
181
199
|
|
182
200
|
def address
|
183
|
-
@address ||= Kentaa::Api::Resources::Address.new(
|
201
|
+
@address ||= Kentaa::Api::Resources::Address.new(data[:address]) if data[:address]
|
184
202
|
end
|
185
203
|
|
186
204
|
def birthday
|
187
|
-
|
205
|
+
Date.parse(data[:birthday]) if data[:birthday]
|
188
206
|
end
|
189
207
|
|
190
208
|
def gender
|
@@ -196,12 +214,12 @@ module Kentaa
|
|
196
214
|
end
|
197
215
|
|
198
216
|
def consent
|
199
|
-
@consent ||= Kentaa::Api::Resources::Consent.new(
|
217
|
+
@consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
|
200
218
|
end
|
201
219
|
|
202
|
-
|
220
|
+
private
|
203
221
|
|
204
|
-
def load_resource
|
222
|
+
def load_resource
|
205
223
|
request.get("/donations/#{id}", options)
|
206
224
|
end
|
207
225
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
module Kentaa
|
7
|
+
module Api
|
8
|
+
module Resources
|
9
|
+
class DonationForm < Resource
|
10
|
+
def object_key
|
11
|
+
"DonationForm_#{id}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def parent
|
15
|
+
site
|
16
|
+
end
|
17
|
+
|
18
|
+
def site
|
19
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def slug
|
23
|
+
data[:slug]
|
24
|
+
end
|
25
|
+
|
26
|
+
def site_id
|
27
|
+
data[:site_id]
|
28
|
+
end
|
29
|
+
|
30
|
+
def owner
|
31
|
+
@owner ||= Kentaa::Api::Resources::User.new(config, data: data[:owner], options: options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def title
|
35
|
+
data[:title]
|
36
|
+
end
|
37
|
+
|
38
|
+
def description
|
39
|
+
data[:description]
|
40
|
+
end
|
41
|
+
|
42
|
+
def total_amount
|
43
|
+
BigDecimal(data[:total_amount])
|
44
|
+
end
|
45
|
+
|
46
|
+
def total_donations
|
47
|
+
data[:total_donations]
|
48
|
+
end
|
49
|
+
|
50
|
+
def published?
|
51
|
+
data[:published]
|
52
|
+
end
|
53
|
+
|
54
|
+
def visible?
|
55
|
+
data[:visible]
|
56
|
+
end
|
57
|
+
|
58
|
+
def external_reference
|
59
|
+
data[:external_reference]
|
60
|
+
end
|
61
|
+
|
62
|
+
def url
|
63
|
+
data[:url]
|
64
|
+
end
|
65
|
+
|
66
|
+
def banners
|
67
|
+
@banners ||= begin
|
68
|
+
banners = []
|
69
|
+
|
70
|
+
if data[:banners]
|
71
|
+
data[:banners].each do |banner|
|
72
|
+
banners << Kentaa::Api::Resources::Banner.new(banner)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
banners
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def donations
|
81
|
+
@donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Donation, endpoint_path: "/donation-forms/#{id}/donations")
|
82
|
+
end
|
83
|
+
|
84
|
+
def manual_donations
|
85
|
+
@manual_donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::ManualDonation, endpoint_path: "/donation-forms/#{id}/manual-donations")
|
86
|
+
end
|
87
|
+
|
88
|
+
def newsletter_subscriptions
|
89
|
+
@newsletter_subscriptions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::NewsletterSubscription, endpoint_path: "/donation-forms/#{id}/newsletter-subscriptions")
|
90
|
+
end
|
91
|
+
|
92
|
+
def recurring_donors
|
93
|
+
@recurring_donors ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::RecurringDonor, endpoint_path: "/donation-forms/#{id}/recurring-donors")
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def load_resource
|
99
|
+
request.get("/donation-forms/#{id}", options)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kentaa
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Error
|
7
|
+
attr_reader :data
|
8
|
+
|
9
|
+
def initialize(data)
|
10
|
+
@data = data
|
11
|
+
end
|
12
|
+
|
13
|
+
def field
|
14
|
+
data[:field]
|
15
|
+
end
|
16
|
+
|
17
|
+
def error
|
18
|
+
data[:error]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -4,6 +4,20 @@ module Kentaa
|
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
6
|
class List < Base
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
def [](index)
|
10
|
+
resources[index]
|
11
|
+
end
|
12
|
+
|
13
|
+
def size
|
14
|
+
resources.size
|
15
|
+
end
|
16
|
+
|
17
|
+
def each(&block)
|
18
|
+
resources.each(&block)
|
19
|
+
end
|
20
|
+
|
7
21
|
def links
|
8
22
|
body[:links]
|
9
23
|
end
|
@@ -45,11 +59,72 @@ module Kentaa
|
|
45
59
|
end
|
46
60
|
|
47
61
|
def next
|
48
|
-
self.class.new(config, options.merge(page: next_page)) if next_page?
|
62
|
+
self.class.new(config, options.merge(resource_class: resource_class, endpoint_path: endpoint_path, page: next_page)) if next_page?
|
49
63
|
end
|
50
64
|
|
51
65
|
def previous
|
52
|
-
self.class.new(config, options.merge(page: previous_page)) if previous_page?
|
66
|
+
self.class.new(config, options.merge(resource_class: resource_class, endpoint_path: endpoint_path, page: previous_page)) if previous_page?
|
67
|
+
end
|
68
|
+
|
69
|
+
def all
|
70
|
+
enumerator = Enumerator.new do |yielder|
|
71
|
+
page = 1
|
72
|
+
|
73
|
+
loop do
|
74
|
+
response = self.class.new(config, options.merge(resource_class: resource_class, endpoint_path: endpoint_path, page: page))
|
75
|
+
response.each { |item| yielder.yield item }
|
76
|
+
|
77
|
+
raise StopIteration unless response.next_page?
|
78
|
+
|
79
|
+
page = response.next_page
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
enumerator.lazy
|
84
|
+
end
|
85
|
+
|
86
|
+
def get(id, options = {})
|
87
|
+
resource = resource_class.new(config, id: id, options: options.merge(endpoint_path: endpoint_path))
|
88
|
+
resource.load
|
89
|
+
end
|
90
|
+
|
91
|
+
def create(attributes, options = {})
|
92
|
+
resource = resource_class.new(config, options: options.merge(endpoint_path: endpoint_path))
|
93
|
+
resource.save(attributes)
|
94
|
+
end
|
95
|
+
|
96
|
+
def update(id, attributes, options = {})
|
97
|
+
resource = resource_class.new(config, id: id, options: options.merge(endpoint_path: endpoint_path))
|
98
|
+
resource.save(attributes)
|
99
|
+
end
|
100
|
+
|
101
|
+
def delete(id, options = {})
|
102
|
+
resource = resource_class.new(config, id: id, options: options.merge(endpoint_path: endpoint_path))
|
103
|
+
resource.delete
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def resources
|
109
|
+
@resources ||= begin
|
110
|
+
resources = []
|
111
|
+
|
112
|
+
if data
|
113
|
+
data.each do |resource|
|
114
|
+
resources << resource_class.new(config, data: resource, options: options)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
resources
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def attribute_key
|
123
|
+
Util.pluralize(resource_class.attribute_key)
|
124
|
+
end
|
125
|
+
|
126
|
+
def load_resource
|
127
|
+
request.get(endpoint_path, options)
|
53
128
|
end
|
54
129
|
end
|
55
130
|
end
|