kentaa-api 0.4.0 → 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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -1
  3. data/.travis.yml +5 -6
  4. data/Gemfile +4 -3
  5. data/Gemfile.lock +31 -23
  6. data/README.md +320 -66
  7. data/kentaa-api.gemspec +3 -3
  8. data/lib/kentaa/api.rb +6 -0
  9. data/lib/kentaa/api/client.rb +8 -0
  10. data/lib/kentaa/api/clients/actions.rb +2 -2
  11. data/lib/kentaa/api/clients/donation_forms.rb +24 -0
  12. data/lib/kentaa/api/clients/donations.rb +1 -1
  13. data/lib/kentaa/api/clients/manual_donations.rb +5 -5
  14. data/lib/kentaa/api/clients/newsletter_subscriptions.rb +1 -1
  15. data/lib/kentaa/api/clients/projects.rb +1 -1
  16. data/lib/kentaa/api/clients/recurring_donors.rb +24 -0
  17. data/lib/kentaa/api/clients/segments.rb +1 -1
  18. data/lib/kentaa/api/clients/sites.rb +1 -1
  19. data/lib/kentaa/api/clients/teams.rb +1 -1
  20. data/lib/kentaa/api/clients/users.rb +7 -2
  21. data/lib/kentaa/api/config.rb +4 -0
  22. data/lib/kentaa/api/exception.rb +5 -2
  23. data/lib/kentaa/api/request.rb +9 -0
  24. data/lib/kentaa/api/resources/action.rb +10 -6
  25. data/lib/kentaa/api/resources/actions.rb +2 -2
  26. data/lib/kentaa/api/resources/contact.rb +1 -1
  27. data/lib/kentaa/api/resources/donation.rb +16 -6
  28. data/lib/kentaa/api/resources/donation_form.rb +100 -0
  29. data/lib/kentaa/api/resources/donation_forms.rb +35 -0
  30. data/lib/kentaa/api/resources/donations.rb +1 -1
  31. data/lib/kentaa/api/resources/manual_donation.rb +15 -5
  32. data/lib/kentaa/api/resources/manual_donations.rb +2 -2
  33. data/lib/kentaa/api/resources/newsletter_subscription.rb +13 -3
  34. data/lib/kentaa/api/resources/newsletter_subscriptions.rb +1 -1
  35. data/lib/kentaa/api/resources/project.rb +10 -2
  36. data/lib/kentaa/api/resources/projects.rb +1 -1
  37. data/lib/kentaa/api/resources/question.rb +8 -0
  38. data/lib/kentaa/api/resources/recurring_donor.rb +110 -0
  39. data/lib/kentaa/api/resources/recurring_donors.rb +35 -0
  40. data/lib/kentaa/api/resources/resource.rb +6 -6
  41. data/lib/kentaa/api/resources/segment.rb +12 -0
  42. data/lib/kentaa/api/resources/segments.rb +1 -1
  43. data/lib/kentaa/api/resources/site.rb +4 -0
  44. data/lib/kentaa/api/resources/team.rb +9 -5
  45. data/lib/kentaa/api/resources/teams.rb +1 -1
  46. data/lib/kentaa/api/resources/user.rb +11 -1
  47. data/lib/kentaa/api/resources/users.rb +7 -2
  48. data/lib/kentaa/api/version.rb +1 -1
  49. metadata +14 -8
data/kentaa-api.gemspec CHANGED
@@ -21,10 +21,10 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.required_ruby_version = ">= 2.3.0"
24
+ spec.required_ruby_version = ">= 2.4.0"
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.14"
27
- spec.add_development_dependency "rake", "~> 12.3"
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "rake", "~> 13.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
29
  spec.add_development_dependency "webmock", "~> 2.3", ">= 2.3.2"
30
30
  end
data/lib/kentaa/api.rb CHANGED
@@ -2,10 +2,12 @@
2
2
 
3
3
  require_relative "api/clients/base"
4
4
  require_relative "api/clients/actions"
5
+ require_relative "api/clients/donation_forms"
5
6
  require_relative "api/clients/donations"
6
7
  require_relative "api/clients/manual_donations"
7
8
  require_relative "api/clients/newsletter_subscriptions"
8
9
  require_relative "api/clients/projects"
10
+ require_relative "api/clients/recurring_donors"
9
11
  require_relative "api/clients/segments"
10
12
  require_relative "api/clients/sites"
11
13
  require_relative "api/clients/teams"
@@ -23,6 +25,8 @@ require_relative "api/resources/address"
23
25
  require_relative "api/resources/banner"
24
26
  require_relative "api/resources/consent"
25
27
  require_relative "api/resources/contact"
28
+ require_relative "api/resources/donation_form"
29
+ require_relative "api/resources/donation_forms"
26
30
  require_relative "api/resources/donation"
27
31
  require_relative "api/resources/donations"
28
32
  require_relative "api/resources/location"
@@ -34,6 +38,8 @@ require_relative "api/resources/photo"
34
38
  require_relative "api/resources/project"
35
39
  require_relative "api/resources/projects"
36
40
  require_relative "api/resources/question"
41
+ require_relative "api/resources/recurring_donor"
42
+ require_relative "api/resources/recurring_donors"
37
43
  require_relative "api/resources/registration_fee"
38
44
  require_relative "api/resources/reward"
39
45
  require_relative "api/resources/segment"
@@ -11,6 +11,10 @@ module Kentaa
11
11
  Kentaa::Api::Clients::Actions.new(@config)
12
12
  end
13
13
 
14
+ def donation_forms
15
+ Kentaa::Api::Clients::DonationForms.new(@config)
16
+ end
17
+
14
18
  def donations
15
19
  Kentaa::Api::Clients::Donations.new(@config)
16
20
  end
@@ -27,6 +31,10 @@ module Kentaa
27
31
  Kentaa::Api::Clients::Projects.new(@config)
28
32
  end
29
33
 
34
+ def recurring_donors
35
+ Kentaa::Api::Clients::RecurringDonors.new(@config)
36
+ end
37
+
30
38
  def segments
31
39
  Kentaa::Api::Clients::Segments.new(@config)
32
40
  end
@@ -15,7 +15,7 @@ module Kentaa
15
15
  end
16
16
 
17
17
  def get(id, options = {})
18
- action = Kentaa::Api::Resources::Action.new(config, options.merge(id: id))
18
+ action = Kentaa::Api::Resources::Action.new(config, id: id, options: options)
19
19
  action.load
20
20
  end
21
21
 
@@ -25,7 +25,7 @@ module Kentaa
25
25
  end
26
26
 
27
27
  def update(id, attributes = {}, options = {})
28
- action = Kentaa::Api::Resources::Action.new(config, options.merge(id: id))
28
+ action = Kentaa::Api::Resources::Action.new(config, id: id, options: options)
29
29
  action.save(attributes)
30
30
  end
31
31
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kentaa
4
+ module Api
5
+ module Clients
6
+ class DonationForms < Base
7
+ def all(options = {})
8
+ donation_forms = Kentaa::Api::Resources::DonationForms.new(config, options)
9
+ donation_forms.all
10
+ end
11
+
12
+ def list(options = {})
13
+ donation_forms = Kentaa::Api::Resources::DonationForms.new(config, options)
14
+ donation_forms.load
15
+ end
16
+
17
+ def get(id, options = {})
18
+ donation_form = Kentaa::Api::Resources::DonationForm.new(config, id: id, options: options)
19
+ donation_form.load
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -15,7 +15,7 @@ module Kentaa
15
15
  end
16
16
 
17
17
  def get(id, options = {})
18
- donation = Kentaa::Api::Resources::Donation.new(config, options.merge(id: id))
18
+ donation = Kentaa::Api::Resources::Donation.new(config, id: id, options: options)
19
19
  donation.load
20
20
  end
21
21
  end
@@ -15,22 +15,22 @@ module Kentaa
15
15
  end
16
16
 
17
17
  def get(id, options = {})
18
- donation = Kentaa::Api::Resources::ManualDonation.new(config, options.merge(id: id))
18
+ donation = Kentaa::Api::Resources::ManualDonation.new(config, id: id, options: options)
19
19
  donation.load
20
20
  end
21
21
 
22
22
  def create(attributes = {}, options = {})
23
- donation = Kentaa::Api::Resources::ManualDonation.new(config, options)
24
- donation.save(attributes)
23
+ donation = Kentaa::Api::Resources::ManualDonations.new(config, options)
24
+ donation.create(attributes)
25
25
  end
26
26
 
27
27
  def update(id, attributes = {}, options = {})
28
- donation = Kentaa::Api::Resources::ManualDonation.new(config, options.merge(id: id))
28
+ donation = Kentaa::Api::Resources::ManualDonation.new(config, id: id, options: options)
29
29
  donation.save(attributes)
30
30
  end
31
31
 
32
32
  def delete(id, options = {})
33
- donation = Kentaa::Api::Resources::ManualDonation.new(config, options.merge(id: id))
33
+ donation = Kentaa::Api::Resources::ManualDonation.new(config, id: id, options: options)
34
34
  donation.delete
35
35
  end
36
36
  end
@@ -15,7 +15,7 @@ module Kentaa
15
15
  end
16
16
 
17
17
  def get(id, options = {})
18
- newsletter_subscription = Kentaa::Api::Resources::NewsletterSubscription.new(config, options.merge(id: id))
18
+ newsletter_subscription = Kentaa::Api::Resources::NewsletterSubscription.new(config, id: id, options: options)
19
19
  newsletter_subscription.load
20
20
  end
21
21
  end
@@ -15,7 +15,7 @@ module Kentaa
15
15
  end
16
16
 
17
17
  def get(id, options = {})
18
- project = Kentaa::Api::Resources::Project.new(config, options.merge(id: id))
18
+ project = Kentaa::Api::Resources::Project.new(config, id: id, options: options)
19
19
  project.load
20
20
  end
21
21
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kentaa
4
+ module Api
5
+ module Clients
6
+ class RecurringDonors < Base
7
+ def all(options = {})
8
+ recurring_donors = Kentaa::Api::Resources::RecurringDonors.new(config, options)
9
+ recurring_donors.all
10
+ end
11
+
12
+ def list(options = {})
13
+ recurring_donors = Kentaa::Api::Resources::RecurringDonors.new(config, options)
14
+ recurring_donors.load
15
+ end
16
+
17
+ def get(id, options = {})
18
+ recurring_donor = Kentaa::Api::Resources::RecurringDonor.new(config, id: id, options: options)
19
+ recurring_donor.load
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -15,7 +15,7 @@ module Kentaa
15
15
  end
16
16
 
17
17
  def get(id, options = {})
18
- segment = Kentaa::Api::Resources::Segment.new(config, options.merge(id: id))
18
+ segment = Kentaa::Api::Resources::Segment.new(config, id: id, options: options)
19
19
  segment.load
20
20
  end
21
21
  end
@@ -5,7 +5,7 @@ module Kentaa
5
5
  module Clients
6
6
  class Sites < Base
7
7
  def current(options = {})
8
- site = Kentaa::Api::Resources::Site.new(config, options)
8
+ site = Kentaa::Api::Resources::Site.new(config, options: options)
9
9
  site.load
10
10
  end
11
11
  end
@@ -15,7 +15,7 @@ module Kentaa
15
15
  end
16
16
 
17
17
  def get(id, options = {})
18
- team = Kentaa::Api::Resources::Team.new(config, options.merge(id: id))
18
+ team = Kentaa::Api::Resources::Team.new(config, id: id, options: options)
19
19
  team.load
20
20
  end
21
21
  end
@@ -15,7 +15,7 @@ module Kentaa
15
15
  end
16
16
 
17
17
  def get(id, options = {})
18
- user = Kentaa::Api::Resources::User.new(config, options.merge(id: id))
18
+ user = Kentaa::Api::Resources::User.new(config, id: id, options: options)
19
19
  user.load
20
20
  end
21
21
 
@@ -25,9 +25,14 @@ module Kentaa
25
25
  end
26
26
 
27
27
  def update(id, attributes = {}, options = {})
28
- user = Kentaa::Api::Resources::User.new(config, options.merge(id: id))
28
+ user = Kentaa::Api::Resources::User.new(config, id: id, options: options)
29
29
  user.save(attributes)
30
30
  end
31
+
32
+ def auth(attributes = {}, options = {})
33
+ user = Kentaa::Api::Resources::Users.new(config, options)
34
+ user.auth(attributes)
35
+ end
31
36
  end
32
37
  end
33
38
  end
@@ -34,6 +34,10 @@ module Kentaa
34
34
  :live
35
35
  end
36
36
  end
37
+
38
+ def debug?
39
+ options.fetch(:debug, false)
40
+ end
37
41
  end
38
42
  end
39
43
  end
@@ -10,8 +10,7 @@ module Kentaa
10
10
 
11
11
  def initialize(response)
12
12
  @response = response
13
-
14
- super(response.message)
13
+ super()
15
14
  end
16
15
 
17
16
  def errors
@@ -21,6 +20,10 @@ module Kentaa
21
20
  def http_code
22
21
  response.http_code
23
22
  end
23
+
24
+ def to_s
25
+ "#{response.http_code}: #{response.message}"
26
+ end
24
27
  end
25
28
  end
26
29
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'logger'
3
4
  require 'net/http'
4
5
  require 'uri'
5
6
 
@@ -34,6 +35,8 @@ module Kentaa
34
35
  uri = URI.parse(File.join(config.api_url, path))
35
36
  uri.query = URI.encode_www_form(params) unless params.empty?
36
37
 
38
+ logger.debug("[Kentaa-API] Request: #{http_method.upcase} #{uri}") if config.debug?
39
+
37
40
  case http_method
38
41
  when :get
39
42
  request = Net::HTTP::Get.new(uri)
@@ -67,12 +70,18 @@ module Kentaa
67
70
  raise Kentaa::Api::Exception, e.message
68
71
  end
69
72
 
73
+ logger.debug("[Kentaa-API] Response: #{response.http_code}, body: #{response.body}") if config.debug?
74
+
70
75
  if response.error?
71
76
  raise Kentaa::Api::RequestError, response
72
77
  end
73
78
 
74
79
  response
75
80
  end
81
+
82
+ def logger
83
+ @logger ||= Logger.new($stdout)
84
+ end
76
85
  end
77
86
  end
78
87
  end
@@ -13,16 +13,20 @@ module Kentaa
13
13
 
14
14
  def parent
15
15
  if team_id
16
- Kentaa::Api::Resources::Team.new(config, id: team_id)
16
+ Kentaa::Api::Resources::Team.new(config, id: team_id, options: options)
17
17
  elsif project_id
18
- Kentaa::Api::Resources::Project.new(config, id: project_id)
18
+ Kentaa::Api::Resources::Project.new(config, id: project_id, options: options)
19
19
  elsif segment_id
20
- Kentaa::Api::Resources::Segment.new(config, id: segment_id)
20
+ Kentaa::Api::Resources::Segment.new(config, id: segment_id, options: options)
21
21
  else
22
- Kentaa::Api::Resources::Site.new(config, id: site_id)
22
+ Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
23
23
  end
24
24
  end
25
25
 
26
+ def site
27
+ Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
28
+ end
29
+
26
30
  def slug
27
31
  data[:slug]
28
32
  end
@@ -44,11 +48,11 @@ module Kentaa
44
48
  end
45
49
 
46
50
  def owner
47
- @owner ||= Kentaa::Api::Resources::User.new(config, data: data[:owner])
51
+ @owner ||= Kentaa::Api::Resources::User.new(config, data: data[:owner], options: options)
48
52
  end
49
53
 
50
54
  def team_captain?
51
- data[:team_captain]
55
+ data.fetch(:team_captain, false)
52
56
  end
53
57
 
54
58
  def first_name
@@ -11,7 +11,7 @@ module Kentaa
11
11
  end
12
12
 
13
13
  def create(attributes = {})
14
- action = Kentaa::Api::Resources::Action.new(config, options)
14
+ action = Kentaa::Api::Resources::Action.new(config, options: options)
15
15
  action.save(attributes)
16
16
  end
17
17
 
@@ -27,7 +27,7 @@ module Kentaa
27
27
 
28
28
  if data
29
29
  data.each do |action|
30
- actions << Kentaa::Api::Resources::Action.new(config, data: action)
30
+ actions << Kentaa::Api::Resources::Action.new(config, data: action, options: options)
31
31
  end
32
32
  end
33
33
 
@@ -71,7 +71,7 @@ module Kentaa
71
71
  end
72
72
 
73
73
  def birthday
74
- Time.parse(data[:birthday]) if data[:birthday]
74
+ Date.parse(data[:birthday]) if data[:birthday]
75
75
  end
76
76
 
77
77
  def gender
@@ -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
@@ -192,7 +202,7 @@ module Kentaa
192
202
  end
193
203
 
194
204
  def birthday
195
- Time.parse(data[:birthday]) if data[:birthday]
205
+ Date.parse(data[:birthday]) if data[:birthday]
196
206
  end
197
207
 
198
208
  def gender
@@ -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