kentaa-api 0.2.1 → 0.5.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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +22 -4
  4. data/.travis.yml +5 -5
  5. data/Gemfile +4 -2
  6. data/Gemfile.lock +33 -20
  7. data/README.md +320 -66
  8. data/kentaa-api.gemspec +3 -3
  9. data/lib/kentaa/api.rb +12 -4
  10. data/lib/kentaa/api/client.rb +12 -0
  11. data/lib/kentaa/api/clients/actions.rb +19 -6
  12. data/lib/kentaa/api/clients/base.rb +0 -4
  13. data/lib/kentaa/api/clients/donation_forms.rb +24 -0
  14. data/lib/kentaa/api/clients/donations.rb +9 -6
  15. data/lib/kentaa/api/clients/manual_donations.rb +39 -0
  16. data/lib/kentaa/api/clients/newsletter_subscriptions.rb +9 -6
  17. data/lib/kentaa/api/clients/projects.rb +9 -6
  18. data/lib/kentaa/api/clients/recurring_donors.rb +24 -0
  19. data/lib/kentaa/api/clients/segments.rb +9 -6
  20. data/lib/kentaa/api/clients/sites.rb +3 -3
  21. data/lib/kentaa/api/clients/teams.rb +9 -6
  22. data/lib/kentaa/api/clients/users.rb +24 -6
  23. data/lib/kentaa/api/config.rb +4 -0
  24. data/lib/kentaa/api/exception.rb +21 -0
  25. data/lib/kentaa/api/finder.rb +9 -0
  26. data/lib/kentaa/api/request.rb +55 -5
  27. data/lib/kentaa/api/resources/action.rb +40 -20
  28. data/lib/kentaa/api/resources/actions.rb +11 -3
  29. data/lib/kentaa/api/resources/activity.rb +10 -2
  30. data/lib/kentaa/api/resources/address.rb +6 -2
  31. data/lib/kentaa/api/resources/banner.rb +20 -2
  32. data/lib/kentaa/api/resources/base.rb +35 -11
  33. data/lib/kentaa/api/resources/consent.rb +7 -1
  34. data/lib/kentaa/api/resources/contact.rb +83 -0
  35. data/lib/kentaa/api/resources/donation.rb +35 -18
  36. data/lib/kentaa/api/resources/donation_form.rb +100 -0
  37. data/lib/kentaa/api/resources/donation_forms.rb +35 -0
  38. data/lib/kentaa/api/resources/donations.rb +6 -3
  39. data/lib/kentaa/api/resources/error.rb +23 -0
  40. data/lib/kentaa/api/resources/{pagination.rb → list.rb} +26 -3
  41. data/lib/kentaa/api/resources/location.rb +7 -1
  42. data/lib/kentaa/api/resources/manual_donation.rb +122 -0
  43. data/lib/kentaa/api/resources/manual_donations.rb +40 -0
  44. data/lib/kentaa/api/resources/newsletter_subscription.rb +21 -10
  45. data/lib/kentaa/api/resources/newsletter_subscriptions.rb +6 -3
  46. data/lib/kentaa/api/resources/photo.rb +20 -2
  47. data/lib/kentaa/api/resources/project.rb +34 -12
  48. data/lib/kentaa/api/resources/projects.rb +6 -3
  49. data/lib/kentaa/api/resources/question.rb +18 -2
  50. data/lib/kentaa/api/resources/recurring_donor.rb +110 -0
  51. data/lib/kentaa/api/resources/recurring_donors.rb +35 -0
  52. data/lib/kentaa/api/resources/registration_fee.rb +1 -1
  53. data/lib/kentaa/api/resources/resource.rb +50 -3
  54. data/lib/kentaa/api/resources/reward.rb +10 -2
  55. data/lib/kentaa/api/resources/segment.rb +28 -4
  56. data/lib/kentaa/api/resources/segments.rb +6 -3
  57. data/lib/kentaa/api/resources/site.rb +20 -4
  58. data/lib/kentaa/api/resources/team.rb +27 -14
  59. data/lib/kentaa/api/resources/teams.rb +6 -3
  60. data/lib/kentaa/api/resources/user.rb +27 -5
  61. data/lib/kentaa/api/resources/users.rb +16 -3
  62. data/lib/kentaa/api/resources/video.rb +20 -2
  63. data/lib/kentaa/api/response.rb +21 -3
  64. data/lib/kentaa/api/version.rb +1 -1
  65. metadata +24 -16
  66. data/lib/kentaa/api/clients/all.rb +0 -26
  67. data/lib/kentaa/api/resources/status.rb +0 -27
@@ -6,36 +6,39 @@ require 'time'
6
6
  module Kentaa
7
7
  module Api
8
8
  module Resources
9
- class Donation < Base
10
- include Kentaa::Api::Resources::Resource
11
-
9
+ class Donation < Resource
12
10
  def object_key
13
11
  "Donation_#{id}"
14
12
  end
15
13
 
16
14
  def entity
17
15
  if action_id
18
- client = Kentaa::Api::Clients::Actions.new(config)
19
- client.get(action_id)
16
+ Kentaa::Api::Resources::Action.new(config, id: action_id, options: options)
20
17
  elsif team_id
21
- client = Kentaa::Api::Clients::Teams.new(config)
22
- client.get(team_id)
18
+ Kentaa::Api::Resources::Team.new(config, id: team_id, options: options)
23
19
  elsif project_id
24
- client = Kentaa::Api::Clients::Projects.new(config)
25
- client.get(project_id)
20
+ Kentaa::Api::Resources::Project.new(config, id: project_id, options: options)
26
21
  elsif segment_id
27
- client = Kentaa::Api::Clients::Segments.new(config)
28
- client.get(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)
29
25
  else
30
- client = Kentaa::Api::Clients::Sites.new(config)
31
- client.current
26
+ Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
32
27
  end
33
28
  end
34
29
 
30
+ def site
31
+ Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
32
+ end
33
+
35
34
  def site_id
36
35
  data[:site_id]
37
36
  end
38
37
 
38
+ def donation_form_id
39
+ data[:donation_form_id]
40
+ end
41
+
39
42
  def segment_id
40
43
  data[:segment_id]
41
44
  end
@@ -108,6 +111,10 @@ module Kentaa
108
111
  BigDecimal(data[:transaction_costs]) if data[:transaction_costs]
109
112
  end
110
113
 
114
+ def start_donation?
115
+ data[:start_donation]
116
+ end
117
+
111
118
  def registration_fee?
112
119
  data[:registration_fee]
113
120
  end
@@ -120,6 +127,10 @@ module Kentaa
120
127
  BigDecimal(data[:total_amount])
121
128
  end
122
129
 
130
+ def receivable_amount
131
+ BigDecimal(data[:receivable_amount])
132
+ end
133
+
123
134
  def countable?
124
135
  data[:countable]
125
136
  end
@@ -174,7 +185,7 @@ module Kentaa
174
185
 
175
186
  if data[:questions]
176
187
  data[:questions].each do |question|
177
- questions << Kentaa::Api::Resources::Question.new(config, question)
188
+ questions << Kentaa::Api::Resources::Question.new(question)
178
189
  end
179
190
  end
180
191
 
@@ -183,15 +194,15 @@ module Kentaa
183
194
  end
184
195
 
185
196
  def reward
186
- @reward ||= Kentaa::Api::Resources::Reward.new(config, data[:reward]) if data[:reward]
197
+ @reward ||= Kentaa::Api::Resources::Reward.new(data[:reward]) if data[:reward]
187
198
  end
188
199
 
189
200
  def address
190
- @address ||= Kentaa::Api::Resources::Address.new(config, data[:address]) if data[:address]
201
+ @address ||= Kentaa::Api::Resources::Address.new(data[:address]) if data[:address]
191
202
  end
192
203
 
193
204
  def birthday
194
- Time.parse(data[:birthday]) if data[:birthday]
205
+ Date.parse(data[:birthday]) if data[:birthday]
195
206
  end
196
207
 
197
208
  def gender
@@ -203,7 +214,13 @@ module Kentaa
203
214
  end
204
215
 
205
216
  def consent
206
- @consent ||= Kentaa::Api::Resources::Consent.new(config, data[:consent]) if data[:consent]
217
+ @consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
218
+ end
219
+
220
+ private
221
+
222
+ def load_resource
223
+ request.get("/donations/#{id}", options)
207
224
  end
208
225
  end
209
226
  end
@@ -0,0 +1,100 @@
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::Donations.new(config, donation_form_id: id)
82
+ end
83
+
84
+ def manual_donations
85
+ @manual_donations ||= Kentaa::Api::Resources::ManualDonations.new(config, donation_form_id: id)
86
+ end
87
+
88
+ def newsletter_subscriptions
89
+ @newsletter_subscriptions ||= Kentaa::Api::Resources::NewsletterSubscriptions.new(config, donation_form_id: id)
90
+ end
91
+
92
+ private
93
+
94
+ def load_resource
95
+ request.get("/donation-forms/#{id}", options)
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kentaa
4
+ module Api
5
+ module Resources
6
+ class DonationForms < List
7
+ include Enumerable
8
+
9
+ def each(&block)
10
+ donation_forms.each(&block)
11
+ end
12
+
13
+ private
14
+
15
+ def load_resource
16
+ request.get("/donation-forms", options)
17
+ end
18
+
19
+ def donation_forms
20
+ @donation_forms ||= begin
21
+ donation_forms = []
22
+
23
+ if data
24
+ data.each do |donation_form|
25
+ donation_forms << Kentaa::Api::Resources::DonationForm.new(config, data: donation_form, options: options)
26
+ end
27
+ end
28
+
29
+ donation_forms
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -3,9 +3,8 @@
3
3
  module Kentaa
4
4
  module Api
5
5
  module Resources
6
- class Donations < Base
6
+ class Donations < List
7
7
  include Enumerable
8
- include Kentaa::Api::Resources::Pagination
9
8
 
10
9
  def each(&block)
11
10
  donations.each(&block)
@@ -13,13 +12,17 @@ module Kentaa
13
12
 
14
13
  private
15
14
 
15
+ def load_resource
16
+ request.get("/donations", options)
17
+ end
18
+
16
19
  def donations
17
20
  @donations ||= begin
18
21
  donations = []
19
22
 
20
23
  if data
21
24
  data.each do |donation|
22
- donations << Kentaa::Api::Resources::Donation.new(config, donation)
25
+ donations << Kentaa::Api::Resources::Donation.new(config, data: donation, options: options)
23
26
  end
24
27
  end
25
28
 
@@ -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
@@ -3,9 +3,7 @@
3
3
  module Kentaa
4
4
  module Api
5
5
  module Resources
6
- module Pagination
7
- attr_accessor :body
8
-
6
+ class List < Base
9
7
  def links
10
8
  body[:links]
11
9
  end
@@ -45,6 +43,31 @@ module Kentaa
45
43
  def previous_page?
46
44
  current_page && current_page > 1
47
45
  end
46
+
47
+ def next
48
+ self.class.new(config, options.merge(page: next_page)) if next_page?
49
+ end
50
+
51
+ def previous
52
+ self.class.new(config, options.merge(page: previous_page)) if previous_page?
53
+ end
54
+
55
+ def all
56
+ enumerator = Enumerator.new do |yielder|
57
+ page = 1
58
+
59
+ loop do
60
+ response = self.class.new(config, options.merge(page: page))
61
+ response.each { |item| yielder.yield item }
62
+
63
+ raise StopIteration unless response.next_page?
64
+
65
+ page = response.next_page
66
+ end
67
+ end
68
+
69
+ enumerator.lazy
70
+ end
48
71
  end
49
72
  end
50
73
  end
@@ -3,7 +3,13 @@
3
3
  module Kentaa
4
4
  module Api
5
5
  module Resources
6
- class Location < Base
6
+ class Location
7
+ attr_reader :data
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+
7
13
  def zip_code
8
14
  data[:zip_code]
9
15
  end
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bigdecimal'
4
+ require 'time'
5
+
6
+ module Kentaa
7
+ module Api
8
+ module Resources
9
+ class ManualDonation < Resource
10
+ def object_key
11
+ "Donation_#{id}"
12
+ end
13
+
14
+ def entity
15
+ if action_id
16
+ Kentaa::Api::Resources::Action.new(config, id: action_id, options: options)
17
+ elsif team_id
18
+ Kentaa::Api::Resources::Team.new(config, id: team_id, options: options)
19
+ elsif project_id
20
+ Kentaa::Api::Resources::Project.new(config, id: project_id, options: options)
21
+ elsif 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)
25
+ else
26
+ Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
27
+ end
28
+ end
29
+
30
+ def site
31
+ Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
32
+ end
33
+
34
+ def site_id
35
+ data[:site_id]
36
+ end
37
+
38
+ def donation_form_id
39
+ data[:donation_form_id]
40
+ end
41
+
42
+ def segment_id
43
+ data[:segment_id]
44
+ end
45
+
46
+ def project_id
47
+ data[:project_id]
48
+ end
49
+
50
+ def team_id
51
+ data[:team_id]
52
+ end
53
+
54
+ def action_id
55
+ data[:action_id]
56
+ end
57
+
58
+ def first_name
59
+ data[:first_name]
60
+ end
61
+
62
+ def infix
63
+ data[:infix]
64
+ end
65
+
66
+ def last_name
67
+ data[:last_name]
68
+ end
69
+
70
+ def name
71
+ [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
72
+ end
73
+
74
+ def anonymous?
75
+ data[:anonymous]
76
+ end
77
+
78
+ def email
79
+ data[:email]
80
+ end
81
+
82
+ def message
83
+ data[:message]
84
+ end
85
+
86
+ def currency
87
+ data[:currency]
88
+ end
89
+
90
+ def amount
91
+ BigDecimal(data[:amount])
92
+ end
93
+
94
+ def countable?
95
+ data[:countable]
96
+ end
97
+
98
+ def target_url
99
+ data[:target_url]
100
+ end
101
+
102
+ private
103
+
104
+ def load_resource
105
+ request.get("/manual-donations/#{id}", options)
106
+ end
107
+
108
+ def create_resource(attributes)
109
+ request.post("/manual-donations", options, attributes)
110
+ end
111
+
112
+ def update_resource(attributes)
113
+ request.patch("/manual-donations/#{id}", options, attributes)
114
+ end
115
+
116
+ def delete_resource
117
+ request.delete("/manual-donations/#{id}", options)
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end