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
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.0.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", "~> 10.0"
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
@@ -1,21 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "api/clients/base"
4
- require_relative "api/clients/all"
5
-
6
4
  require_relative "api/clients/actions"
5
+ require_relative "api/clients/donation_forms"
7
6
  require_relative "api/clients/donations"
7
+ require_relative "api/clients/manual_donations"
8
8
  require_relative "api/clients/newsletter_subscriptions"
9
9
  require_relative "api/clients/projects"
10
+ require_relative "api/clients/recurring_donors"
10
11
  require_relative "api/clients/segments"
11
12
  require_relative "api/clients/sites"
12
13
  require_relative "api/clients/teams"
13
14
  require_relative "api/clients/users"
14
15
 
15
16
  require_relative "api/resources/base"
16
- require_relative "api/resources/pagination"
17
+ require_relative "api/resources/error"
18
+ require_relative "api/resources/list"
17
19
  require_relative "api/resources/resource"
18
- require_relative "api/resources/status"
19
20
 
20
21
  require_relative "api/resources/action"
21
22
  require_relative "api/resources/actions"
@@ -23,15 +24,22 @@ require_relative "api/resources/activity"
23
24
  require_relative "api/resources/address"
24
25
  require_relative "api/resources/banner"
25
26
  require_relative "api/resources/consent"
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"
33
+ require_relative "api/resources/manual_donation"
34
+ require_relative "api/resources/manual_donations"
29
35
  require_relative "api/resources/newsletter_subscription"
30
36
  require_relative "api/resources/newsletter_subscriptions"
31
37
  require_relative "api/resources/photo"
32
38
  require_relative "api/resources/project"
33
39
  require_relative "api/resources/projects"
34
40
  require_relative "api/resources/question"
41
+ require_relative "api/resources/recurring_donor"
42
+ require_relative "api/resources/recurring_donors"
35
43
  require_relative "api/resources/registration_fee"
36
44
  require_relative "api/resources/reward"
37
45
  require_relative "api/resources/segment"
@@ -11,10 +11,18 @@ 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
17
21
 
22
+ def manual_donations
23
+ Kentaa::Api::Clients::ManualDonations.new(@config)
24
+ end
25
+
18
26
  def newsletter_subscriptions
19
27
  Kentaa::Api::Clients::NewsletterSubscriptions.new(@config)
20
28
  end
@@ -23,6 +31,10 @@ module Kentaa
23
31
  Kentaa::Api::Clients::Projects.new(@config)
24
32
  end
25
33
 
34
+ def recurring_donors
35
+ Kentaa::Api::Clients::RecurringDonors.new(@config)
36
+ end
37
+
26
38
  def segments
27
39
  Kentaa::Api::Clients::Segments.new(@config)
28
40
  end
@@ -4,16 +4,29 @@ module Kentaa
4
4
  module Api
5
5
  module Clients
6
6
  class Actions < Base
7
- include Kentaa::Api::Clients::All
7
+ def all(options = {})
8
+ actions = Kentaa::Api::Resources::Actions.new(config, options)
9
+ actions.all
10
+ end
8
11
 
9
12
  def list(options = {})
10
- response = request.get("/actions", options)
11
- Kentaa::Api::Resources::Actions.new(config, response)
13
+ actions = Kentaa::Api::Resources::Actions.new(config, options)
14
+ actions.load
15
+ end
16
+
17
+ def get(id, options = {})
18
+ action = Kentaa::Api::Resources::Action.new(config, id: id, options: options)
19
+ action.load
20
+ end
21
+
22
+ def create(attributes = {}, options = {})
23
+ action = Kentaa::Api::Resources::Actions.new(config, options)
24
+ action.create(attributes)
12
25
  end
13
26
 
14
- def get(id)
15
- response = request.get("/actions/#{id}")
16
- Kentaa::Api::Resources::Action.new(config, response)
27
+ def update(id, attributes = {}, options = {})
28
+ action = Kentaa::Api::Resources::Action.new(config, id: id, options: options)
29
+ action.save(attributes)
17
30
  end
18
31
  end
19
32
  end
@@ -9,10 +9,6 @@ module Kentaa
9
9
  def initialize(config)
10
10
  @config = config
11
11
  end
12
-
13
- def request
14
- @request ||= Kentaa::Api::Request.new(config)
15
- end
16
12
  end
17
13
  end
18
14
  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
@@ -4,16 +4,19 @@ module Kentaa
4
4
  module Api
5
5
  module Clients
6
6
  class Donations < Base
7
- include Kentaa::Api::Clients::All
7
+ def all(options = {})
8
+ donations = Kentaa::Api::Resources::Donations.new(config, options)
9
+ donations.all
10
+ end
8
11
 
9
12
  def list(options = {})
10
- response = request.get("/donations", options)
11
- Kentaa::Api::Resources::Donations.new(config, response)
13
+ donations = Kentaa::Api::Resources::Donations.new(config, options)
14
+ donations.load
12
15
  end
13
16
 
14
- def get(id)
15
- response = request.get("/donations/#{id}")
16
- Kentaa::Api::Resources::Donation.new(config, response)
17
+ def get(id, options = {})
18
+ donation = Kentaa::Api::Resources::Donation.new(config, id: id, options: options)
19
+ donation.load
17
20
  end
18
21
  end
19
22
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kentaa
4
+ module Api
5
+ module Clients
6
+ class ManualDonations < Base
7
+ def all(options = {})
8
+ donations = Kentaa::Api::Resources::ManualDonations.new(config, options)
9
+ donations.all
10
+ end
11
+
12
+ def list(options = {})
13
+ donations = Kentaa::Api::Resources::ManualDonations.new(config, options)
14
+ donations.load
15
+ end
16
+
17
+ def get(id, options = {})
18
+ donation = Kentaa::Api::Resources::ManualDonation.new(config, id: id, options: options)
19
+ donation.load
20
+ end
21
+
22
+ def create(attributes = {}, options = {})
23
+ donation = Kentaa::Api::Resources::ManualDonations.new(config, options)
24
+ donation.create(attributes)
25
+ end
26
+
27
+ def update(id, attributes = {}, options = {})
28
+ donation = Kentaa::Api::Resources::ManualDonation.new(config, id: id, options: options)
29
+ donation.save(attributes)
30
+ end
31
+
32
+ def delete(id, options = {})
33
+ donation = Kentaa::Api::Resources::ManualDonation.new(config, id: id, options: options)
34
+ donation.delete
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -4,16 +4,19 @@ module Kentaa
4
4
  module Api
5
5
  module Clients
6
6
  class NewsletterSubscriptions < Base
7
- include Kentaa::Api::Clients::All
7
+ def all(options = {})
8
+ newsletter_subscriptions = Kentaa::Api::Resources::NewsletterSubscriptions.new(config, options)
9
+ newsletter_subscriptions.all
10
+ end
8
11
 
9
12
  def list(options = {})
10
- response = request.get("/newsletter-subscriptions", options)
11
- Kentaa::Api::Resources::NewsletterSubscriptions.new(config, response)
13
+ newsletter_subscriptions = Kentaa::Api::Resources::NewsletterSubscriptions.new(config, options)
14
+ newsletter_subscriptions.load
12
15
  end
13
16
 
14
- def get(id)
15
- response = request.get("/newsletter-subscriptions/#{id}")
16
- Kentaa::Api::Resources::NewsletterSubscription.new(config, response)
17
+ def get(id, options = {})
18
+ newsletter_subscription = Kentaa::Api::Resources::NewsletterSubscription.new(config, id: id, options: options)
19
+ newsletter_subscription.load
17
20
  end
18
21
  end
19
22
  end
@@ -4,16 +4,19 @@ module Kentaa
4
4
  module Api
5
5
  module Clients
6
6
  class Projects < Base
7
- include Kentaa::Api::Clients::All
7
+ def all(options = {})
8
+ projects = Kentaa::Api::Resources::Projects.new(config, options)
9
+ projects.all
10
+ end
8
11
 
9
12
  def list(options = {})
10
- response = request.get("/projects", options)
11
- Kentaa::Api::Resources::Projects.new(config, response)
13
+ projects = Kentaa::Api::Resources::Projects.new(config, options)
14
+ projects.load
12
15
  end
13
16
 
14
- def get(id)
15
- response = request.get("/projects/#{id}")
16
- Kentaa::Api::Resources::Project.new(config, response)
17
+ def get(id, options = {})
18
+ project = Kentaa::Api::Resources::Project.new(config, id: id, options: options)
19
+ project.load
17
20
  end
18
21
  end
19
22
  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
@@ -4,16 +4,19 @@ module Kentaa
4
4
  module Api
5
5
  module Clients
6
6
  class Segments < Base
7
- include Kentaa::Api::Clients::All
7
+ def all(options = {})
8
+ segments = Kentaa::Api::Resources::Segments.new(config, options)
9
+ segments.all
10
+ end
8
11
 
9
12
  def list(options = {})
10
- response = request.get("/segments", options)
11
- Kentaa::Api::Resources::Segments.new(config, response)
13
+ segments = Kentaa::Api::Resources::Segments.new(config, options)
14
+ segments.load
12
15
  end
13
16
 
14
- def get(id)
15
- response = request.get("/segments/#{id}")
16
- Kentaa::Api::Resources::Segment.new(config, response)
17
+ def get(id, options = {})
18
+ segment = Kentaa::Api::Resources::Segment.new(config, id: id, options: options)
19
+ segment.load
17
20
  end
18
21
  end
19
22
  end
@@ -4,9 +4,9 @@ module Kentaa
4
4
  module Api
5
5
  module Clients
6
6
  class Sites < Base
7
- def current
8
- response = request.get("/sites/current")
9
- Kentaa::Api::Resources::Site.new(config, response)
7
+ def current(options = {})
8
+ site = Kentaa::Api::Resources::Site.new(config, options: options)
9
+ site.load
10
10
  end
11
11
  end
12
12
  end
@@ -4,16 +4,19 @@ module Kentaa
4
4
  module Api
5
5
  module Clients
6
6
  class Teams < Base
7
- include Kentaa::Api::Clients::All
7
+ def all(options = {})
8
+ teams = Kentaa::Api::Resources::Teams.new(config, options)
9
+ teams.all
10
+ end
8
11
 
9
12
  def list(options = {})
10
- response = request.get("/teams", options)
11
- Kentaa::Api::Resources::Teams.new(config, response)
13
+ teams = Kentaa::Api::Resources::Teams.new(config, options)
14
+ teams.load
12
15
  end
13
16
 
14
- def get(id)
15
- response = request.get("/teams/#{id}")
16
- Kentaa::Api::Resources::Team.new(config, response)
17
+ def get(id, options = {})
18
+ team = Kentaa::Api::Resources::Team.new(config, id: id, options: options)
19
+ team.load
17
20
  end
18
21
  end
19
22
  end
@@ -4,16 +4,34 @@ module Kentaa
4
4
  module Api
5
5
  module Clients
6
6
  class Users < Base
7
- include Kentaa::Api::Clients::All
7
+ def all(options = {})
8
+ users = Kentaa::Api::Resources::Users.new(config, options)
9
+ users.all
10
+ end
8
11
 
9
12
  def list(options = {})
10
- response = request.get("/users", options)
11
- Kentaa::Api::Resources::Users.new(config, response)
13
+ users = Kentaa::Api::Resources::Users.new(config, options)
14
+ users.load
15
+ end
16
+
17
+ def get(id, options = {})
18
+ user = Kentaa::Api::Resources::User.new(config, id: id, options: options)
19
+ user.load
20
+ end
21
+
22
+ def create(attributes = {}, options = {})
23
+ user = Kentaa::Api::Resources::Users.new(config, options)
24
+ user.create(attributes)
25
+ end
26
+
27
+ def update(id, attributes = {}, options = {})
28
+ user = Kentaa::Api::Resources::User.new(config, id: id, options: options)
29
+ user.save(attributes)
12
30
  end
13
31
 
14
- def get(id)
15
- response = request.get("/users/#{id}")
16
- Kentaa::Api::Resources::User.new(config, response)
32
+ def auth(attributes = {}, options = {})
33
+ user = Kentaa::Api::Resources::Users.new(config, options)
34
+ user.auth(attributes)
17
35
  end
18
36
  end
19
37
  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
@@ -4,5 +4,26 @@ module Kentaa
4
4
  module Api
5
5
  class Exception < StandardError
6
6
  end
7
+
8
+ class RequestError < Kentaa::Api::Exception
9
+ attr_accessor :response
10
+
11
+ def initialize(response)
12
+ @response = response
13
+ super()
14
+ end
15
+
16
+ def errors
17
+ response.errors
18
+ end
19
+
20
+ def http_code
21
+ response.http_code
22
+ end
23
+
24
+ def to_s
25
+ "#{response.http_code}: #{response.message}"
26
+ end
27
+ end
7
28
  end
8
29
  end