kentaa-api 0.3.2 → 0.4.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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +11 -11
  4. data/lib/kentaa/api.rb +4 -2
  5. data/lib/kentaa/api/client.rb +4 -0
  6. data/lib/kentaa/api/clients/actions.rb +14 -1
  7. data/lib/kentaa/api/clients/donations.rb +4 -1
  8. data/lib/kentaa/api/clients/manual_donations.rb +39 -0
  9. data/lib/kentaa/api/clients/newsletter_subscriptions.rb +4 -1
  10. data/lib/kentaa/api/clients/projects.rb +4 -1
  11. data/lib/kentaa/api/clients/segments.rb +4 -1
  12. data/lib/kentaa/api/clients/teams.rb +4 -1
  13. data/lib/kentaa/api/clients/users.rb +14 -1
  14. data/lib/kentaa/api/exception.rb +4 -0
  15. data/lib/kentaa/api/request.rb +41 -6
  16. data/lib/kentaa/api/resources/action.rb +25 -9
  17. data/lib/kentaa/api/resources/actions.rb +7 -4
  18. data/lib/kentaa/api/resources/activity.rb +11 -1
  19. data/lib/kentaa/api/resources/address.rb +7 -1
  20. data/lib/kentaa/api/resources/banner.rb +21 -1
  21. data/lib/kentaa/api/resources/base.rb +2 -2
  22. data/lib/kentaa/api/resources/consent.rb +7 -1
  23. data/lib/kentaa/api/resources/contact.rb +7 -1
  24. data/lib/kentaa/api/resources/donation.rb +6 -6
  25. data/lib/kentaa/api/resources/donations.rb +2 -4
  26. data/lib/kentaa/api/resources/error.rb +23 -0
  27. data/lib/kentaa/api/resources/list.rb +17 -0
  28. data/lib/kentaa/api/resources/location.rb +7 -1
  29. data/lib/kentaa/api/resources/manual_donation.rb +112 -0
  30. data/lib/kentaa/api/resources/manual_donations.rb +40 -0
  31. data/lib/kentaa/api/resources/newsletter_subscription.rb +3 -3
  32. data/lib/kentaa/api/resources/newsletter_subscriptions.rb +2 -4
  33. data/lib/kentaa/api/resources/photo.rb +21 -1
  34. data/lib/kentaa/api/resources/project.rb +16 -8
  35. data/lib/kentaa/api/resources/projects.rb +2 -4
  36. data/lib/kentaa/api/resources/question.rb +11 -1
  37. data/lib/kentaa/api/resources/registration_fee.rb +1 -1
  38. data/lib/kentaa/api/resources/resource.rb +31 -0
  39. data/lib/kentaa/api/resources/reward.rb +11 -1
  40. data/lib/kentaa/api/resources/segment.rb +11 -3
  41. data/lib/kentaa/api/resources/segments.rb +2 -4
  42. data/lib/kentaa/api/resources/site.rb +11 -3
  43. data/lib/kentaa/api/resources/team.rb +13 -5
  44. data/lib/kentaa/api/resources/teams.rb +2 -4
  45. data/lib/kentaa/api/resources/user.rb +11 -3
  46. data/lib/kentaa/api/resources/users.rb +7 -4
  47. data/lib/kentaa/api/resources/video.rb +21 -1
  48. data/lib/kentaa/api/response.rb +16 -2
  49. data/lib/kentaa/api/version.rb +1 -1
  50. metadata +11 -8
  51. data/lib/kentaa/api/clients/all.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcbbd3d3b46eccb8bf6224cee26a3324db3abae8a61f16a1988eb098ef736dac
4
- data.tar.gz: 4dbec5d42ba8db8db765004ccbb6e3991ec70f5a32394c0a89fe6607888a622e
3
+ metadata.gz: 4ebca7b73a3ae49b7d9948211b21638e7131340fe58f6b34551260853dd4b6fb
4
+ data.tar.gz: cc9a8b5450c1b4068867a2bf0eada220174e3d107ae2369ddbc5080bcf785257
5
5
  SHA512:
6
- metadata.gz: 1acabd32a16472d377ee191f72791f2664574494e07e106fa2ee633d2a21332de2614bffdea797d3bd1d52c65516f454c8357b9bfd5357cf56ad755c4215a8d0
7
- data.tar.gz: 83efd25c71013041ba37f8c36d488417501f6e080cd1172adb166517ad132c3776fa61cdfd0d38fbb2f581c52eb1088bbf27101feb52bd4b4f37a24730f00a83
6
+ metadata.gz: 2815897919718da19a9ed6ddb05589523b492639427fced920168bb469c794a83c5cc4477f9dc3403e7a932f6d88d657035a741f5cb3a44c075807b88b3ccf0f
7
+ data.tar.gz: 696d64f0bf684fafcbf1c38c24f3f1b03c97312f2c6b666054464b85b58b0907eb27e8a42bffd4e886d035475daaab8e22354af9a39ce9ea9a54943fbd225962
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kentaa-api (0.3.2)
4
+ kentaa-api (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -37,7 +37,7 @@ client = Kentaa::Api::Client.new(config)
37
37
 
38
38
  ### Retrieving data
39
39
 
40
- All endpoints use the same convention for retrieving data. The methods `list` and `all` are used for retrieving multiple resources. The method `get` is used for retrieving a single resource.
40
+ All endpoints use the same convention for retrieving data. The method `list` is for retrieving multiple resources. The method `get` is used for retrieving a single resource.
41
41
 
42
42
  The `list` method on the endpoint returns an [Enumerable](https://ruby-doc.org/core/Enumerable.html) object:
43
43
 
@@ -51,7 +51,7 @@ actions.first
51
51
  The results might be part of a paginated set. You can query the next page by doing:
52
52
 
53
53
  ```ruby
54
- actions = client.actions.list(page: actions.next_page) if actions.next_page?
54
+ actions = actions.next if actions.next_page?
55
55
  ```
56
56
 
57
57
  See also `Kentaa::Api::Resources::List` for the available methods for pagination.
@@ -84,10 +84,10 @@ See also the [Kentaa API docs](https://api.kentaa.nl/v1/doc/actions).
84
84
  #### Donations
85
85
 
86
86
  ```ruby
87
- donations = client.donations.list # get donations (paginated)
88
- donations = client.donations.all # get all donations (non-paginated)
87
+ donations = client.donations.list # get donations (paginated)
88
+ donations = client.donations.all # get all donations (non-paginated)
89
89
 
90
- donation = client.donations.get(1) # query donation by ID
90
+ donation = client.donations.get(1) # query donation by ID
91
91
  ```
92
92
 
93
93
  See also the [Kentaa API docs](https://api.kentaa.nl/v1/doc/donations).
@@ -95,11 +95,11 @@ See also the [Kentaa API docs](https://api.kentaa.nl/v1/doc/donations).
95
95
  #### Newsletter subscriptions
96
96
 
97
97
  ```ruby
98
- newsletter_subscriptions = client.newsletter_subscriptions.all # get newsletter subscriptions (paginated)
99
- newsletter_subscriptions = client.newsletter_subscriptions.list # get all newsletter subscriptions (non-paginated)
98
+ newsletter_subscriptions = client.newsletter_subscriptions.list # get newsletter subscriptions (paginated)
99
+ newsletter_subscriptions = client.newsletter_subscriptions.all # get all newsletter subscriptions (non-paginated)
100
100
 
101
101
 
102
- newsletter_subscriptions = client.newsletter_subscriptions.get(1) # query newsletter subscription by ID
102
+ newsletter_subscriptions = client.newsletter_subscriptions.get(1) # query newsletter subscription by ID
103
103
  ```
104
104
 
105
105
  See also the [Kentaa API docs](https://api.kentaa.nl/v1/doc/newsletter-subscriptions).
@@ -119,10 +119,10 @@ See also the [Kentaa API docs](https://api.kentaa.nl/v1/doc/projects).
119
119
  #### Segments
120
120
 
121
121
  ```ruby
122
- segments = client.segments.list # get segments (paginated)
123
- segments = client.segments.all # get all segments (non-paginated)
122
+ segments = client.segments.list # get segments (paginated)
123
+ segments = client.segments.all # get all segments (non-paginated)
124
124
 
125
- segment = client.segments.get(1) # query segment by ID
125
+ segment = client.segments.get(1) # query segment by ID
126
126
  ```
127
127
 
128
128
  See also the [Kentaa API docs](https://api.kentaa.nl/v1/doc/segments).
@@ -1,10 +1,9 @@
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"
7
5
  require_relative "api/clients/donations"
6
+ require_relative "api/clients/manual_donations"
8
7
  require_relative "api/clients/newsletter_subscriptions"
9
8
  require_relative "api/clients/projects"
10
9
  require_relative "api/clients/segments"
@@ -13,6 +12,7 @@ require_relative "api/clients/teams"
13
12
  require_relative "api/clients/users"
14
13
 
15
14
  require_relative "api/resources/base"
15
+ require_relative "api/resources/error"
16
16
  require_relative "api/resources/list"
17
17
  require_relative "api/resources/resource"
18
18
 
@@ -26,6 +26,8 @@ require_relative "api/resources/contact"
26
26
  require_relative "api/resources/donation"
27
27
  require_relative "api/resources/donations"
28
28
  require_relative "api/resources/location"
29
+ require_relative "api/resources/manual_donation"
30
+ require_relative "api/resources/manual_donations"
29
31
  require_relative "api/resources/newsletter_subscription"
30
32
  require_relative "api/resources/newsletter_subscriptions"
31
33
  require_relative "api/resources/photo"
@@ -15,6 +15,10 @@ module Kentaa
15
15
  Kentaa::Api::Clients::Donations.new(@config)
16
16
  end
17
17
 
18
+ def manual_donations
19
+ Kentaa::Api::Clients::ManualDonations.new(@config)
20
+ end
21
+
18
22
  def newsletter_subscriptions
19
23
  Kentaa::Api::Clients::NewsletterSubscriptions.new(@config)
20
24
  end
@@ -4,7 +4,10 @@ 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
13
  actions = Kentaa::Api::Resources::Actions.new(config, options)
@@ -15,6 +18,16 @@ module Kentaa
15
18
  action = Kentaa::Api::Resources::Action.new(config, options.merge(id: id))
16
19
  action.load
17
20
  end
21
+
22
+ def create(attributes = {}, options = {})
23
+ action = Kentaa::Api::Resources::Actions.new(config, options)
24
+ action.create(attributes)
25
+ end
26
+
27
+ def update(id, attributes = {}, options = {})
28
+ action = Kentaa::Api::Resources::Action.new(config, options.merge(id: id))
29
+ action.save(attributes)
30
+ end
18
31
  end
19
32
  end
20
33
  end
@@ -4,7 +4,10 @@ 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
13
  donations = Kentaa::Api::Resources::Donations.new(config, options)
@@ -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, options.merge(id: id))
19
+ donation.load
20
+ end
21
+
22
+ def create(attributes = {}, options = {})
23
+ donation = Kentaa::Api::Resources::ManualDonation.new(config, options)
24
+ donation.save(attributes)
25
+ end
26
+
27
+ def update(id, attributes = {}, options = {})
28
+ donation = Kentaa::Api::Resources::ManualDonation.new(config, options.merge(id: id))
29
+ donation.save(attributes)
30
+ end
31
+
32
+ def delete(id, options = {})
33
+ donation = Kentaa::Api::Resources::ManualDonation.new(config, options.merge(id: id))
34
+ donation.delete
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -4,7 +4,10 @@ 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
13
  newsletter_subscriptions = Kentaa::Api::Resources::NewsletterSubscriptions.new(config, options)
@@ -4,7 +4,10 @@ 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
13
  projects = Kentaa::Api::Resources::Projects.new(config, options)
@@ -4,7 +4,10 @@ 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
13
  segments = Kentaa::Api::Resources::Segments.new(config, options)
@@ -4,7 +4,10 @@ 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
13
  teams = Kentaa::Api::Resources::Teams.new(config, options)
@@ -4,7 +4,10 @@ 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
13
  users = Kentaa::Api::Resources::Users.new(config, options)
@@ -15,6 +18,16 @@ module Kentaa
15
18
  user = Kentaa::Api::Resources::User.new(config, options.merge(id: id))
16
19
  user.load
17
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, options.merge(id: id))
29
+ user.save(attributes)
30
+ end
18
31
  end
19
32
  end
20
33
  end
@@ -14,6 +14,10 @@ module Kentaa
14
14
  super(response.message)
15
15
  end
16
16
 
17
+ def errors
18
+ response.errors
19
+ end
20
+
17
21
  def http_code
18
22
  response.http_code
19
23
  end
@@ -13,16 +13,53 @@ module Kentaa
13
13
  end
14
14
 
15
15
  def get(path, params = {})
16
+ request(:get, path, params)
17
+ end
18
+
19
+ def post(path, params = {}, body = {})
20
+ request(:post, path, params, body)
21
+ end
22
+
23
+ def patch(path, params = {}, body = {})
24
+ request(:patch, path, params, body)
25
+ end
26
+
27
+ def delete(path, params = {})
28
+ request(:delete, path, params)
29
+ end
30
+
31
+ private
32
+
33
+ def request(http_method, path, params = {}, body = {})
16
34
  uri = URI.parse(File.join(config.api_url, path))
17
35
  uri.query = URI.encode_www_form(params) unless params.empty?
18
36
 
19
- request = Net::HTTP::Get.new(uri)
37
+ case http_method
38
+ when :get
39
+ request = Net::HTTP::Get.new(uri)
40
+ when :post
41
+ request = Net::HTTP::Post.new(uri)
42
+ request.body = body.to_json
43
+ when :patch
44
+ request = Net::HTTP::Patch.new(uri)
45
+ request.body = body.to_json
46
+ when :delete
47
+ request = Net::HTTP::Delete.new(uri)
48
+ else
49
+ raise Kentaa::Api::Exception, "Invalid HTTP method: #{http_method}"
50
+ end
51
+
52
+ request["Accept"] = "application/json"
53
+ request["Content-Type"] = "application/json"
20
54
  request["X-Api-Key"] = config.api_key
55
+ request["User-Agent"] = "Ruby kentaa-api/#{Kentaa::Api::VERSION}"
56
+
57
+ client = Net::HTTP.new(uri.hostname, uri.port)
58
+ client.use_ssl = uri.scheme == "https"
59
+ client.verify_mode = OpenSSL::SSL::VERIFY_PEER
21
60
 
22
61
  begin
23
- result = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
24
- http.request(request)
25
- end
62
+ response = Kentaa::Api::Response.new(client.request(request))
26
63
  # Try to catch some common exceptions Net::HTTP might raise.
27
64
  rescue Errno::ETIMEDOUT, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EHOSTUNREACH,
28
65
  IOError, SocketError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::OpenTimeout,
@@ -30,8 +67,6 @@ module Kentaa
30
67
  raise Kentaa::Api::Exception, e.message
31
68
  end
32
69
 
33
- response = Kentaa::Api::Response.new(result)
34
-
35
70
  if response.error?
36
71
  raise Kentaa::Api::RequestError, response
37
72
  end
@@ -120,7 +120,7 @@ module Kentaa
120
120
  end
121
121
 
122
122
  def activity
123
- @activity ||= Kentaa::Api::Resources::Activity.new(config, data: data[:activity])
123
+ @activity ||= Kentaa::Api::Resources::Activity.new(data[:activity])
124
124
  end
125
125
 
126
126
  def previous_participations
@@ -136,11 +136,11 @@ module Kentaa
136
136
  end
137
137
 
138
138
  def registration_fee
139
- @registration_fee ||= Kentaa::Api::Resources::RegistrationFee.new(config, data: data[:registration_fee])
139
+ @registration_fee ||= Kentaa::Api::Resources::RegistrationFee.new(data[:registration_fee])
140
140
  end
141
141
 
142
142
  def location
143
- @location ||= Kentaa::Api::Resources::Location.new(config, data: data[:location])
143
+ @location ||= Kentaa::Api::Resources::Location.new(data[:location])
144
144
  end
145
145
 
146
146
  def photos
@@ -149,7 +149,7 @@ module Kentaa
149
149
 
150
150
  if data[:photos]
151
151
  data[:photos].each do |photo|
152
- photos << Kentaa::Api::Resources::Photo.new(config, data: photo)
152
+ photos << Kentaa::Api::Resources::Photo.new(photo)
153
153
  end
154
154
  end
155
155
 
@@ -163,7 +163,7 @@ module Kentaa
163
163
 
164
164
  if data[:videos]
165
165
  data[:videos].each do |video|
166
- videos << Kentaa::Api::Resources::Video.new(config, data: video)
166
+ videos << Kentaa::Api::Resources::Video.new(video)
167
167
  end
168
168
  end
169
169
 
@@ -177,7 +177,7 @@ module Kentaa
177
177
 
178
178
  if data[:questions]
179
179
  data[:questions].each do |question|
180
- questions << Kentaa::Api::Resources::Question.new(config, data: question)
180
+ questions << Kentaa::Api::Resources::Question.new(question)
181
181
  end
182
182
  end
183
183
 
@@ -186,18 +186,34 @@ module Kentaa
186
186
  end
187
187
 
188
188
  def consent
189
- @consent ||= Kentaa::Api::Resources::Consent.new(config, data: data[:consent]) if data[:consent]
189
+ @consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
190
190
  end
191
191
 
192
192
  def external_reference
193
193
  data[:external_reference]
194
194
  end
195
195
 
196
- protected
196
+ def donations
197
+ @donations ||= Kentaa::Api::Resources::Donations.new(config, action_id: id)
198
+ end
199
+
200
+ def manual_donations
201
+ @manual_donations ||= Kentaa::Api::Resources::ManualDonations.new(config, action_id: id)
202
+ end
203
+
204
+ private
197
205
 
198
- def load_resource(options)
206
+ def load_resource
199
207
  request.get("/actions/#{id}", options)
200
208
  end
209
+
210
+ def create_resource(attributes)
211
+ request.post("/actions", options, attributes)
212
+ end
213
+
214
+ def update_resource(attributes)
215
+ request.patch("/actions/#{id}", options, attributes)
216
+ end
201
217
  end
202
218
  end
203
219
  end