kentaa-api 0.2.1 → 0.3.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +1 -1
  5. data/lib/kentaa/api.rb +1 -2
  6. data/lib/kentaa/api/clients/actions.rb +5 -5
  7. data/lib/kentaa/api/clients/all.rb +1 -1
  8. data/lib/kentaa/api/clients/base.rb +0 -4
  9. data/lib/kentaa/api/clients/donations.rb +5 -5
  10. data/lib/kentaa/api/clients/newsletter_subscriptions.rb +5 -5
  11. data/lib/kentaa/api/clients/projects.rb +5 -5
  12. data/lib/kentaa/api/clients/segments.rb +5 -5
  13. data/lib/kentaa/api/clients/sites.rb +3 -3
  14. data/lib/kentaa/api/clients/teams.rb +5 -5
  15. data/lib/kentaa/api/clients/users.rb +5 -5
  16. data/lib/kentaa/api/exception.rb +14 -0
  17. data/lib/kentaa/api/finder.rb +9 -0
  18. data/lib/kentaa/api/request.rb +8 -2
  19. data/lib/kentaa/api/resources/action.rb +19 -19
  20. data/lib/kentaa/api/resources/actions.rb +8 -3
  21. data/lib/kentaa/api/resources/activity.rb +1 -3
  22. data/lib/kentaa/api/resources/address.rb +1 -3
  23. data/lib/kentaa/api/resources/banner.rb +1 -3
  24. data/lib/kentaa/api/resources/base.rb +35 -11
  25. data/lib/kentaa/api/resources/consent.rb +1 -1
  26. data/lib/kentaa/api/resources/donation.rb +16 -17
  27. data/lib/kentaa/api/resources/donations.rb +8 -3
  28. data/lib/kentaa/api/resources/{pagination.rb → list.rb} +9 -3
  29. data/lib/kentaa/api/resources/location.rb +1 -1
  30. data/lib/kentaa/api/resources/newsletter_subscription.rb +11 -10
  31. data/lib/kentaa/api/resources/newsletter_subscriptions.rb +8 -3
  32. data/lib/kentaa/api/resources/photo.rb +1 -3
  33. data/lib/kentaa/api/resources/project.rb +14 -12
  34. data/lib/kentaa/api/resources/projects.rb +8 -3
  35. data/lib/kentaa/api/resources/question.rb +1 -3
  36. data/lib/kentaa/api/resources/registration_fee.rb +1 -1
  37. data/lib/kentaa/api/resources/resource.rb +12 -3
  38. data/lib/kentaa/api/resources/reward.rb +1 -3
  39. data/lib/kentaa/api/resources/segment.rb +8 -4
  40. data/lib/kentaa/api/resources/segments.rb +8 -3
  41. data/lib/kentaa/api/resources/site.rb +8 -4
  42. data/lib/kentaa/api/resources/team.rb +15 -14
  43. data/lib/kentaa/api/resources/teams.rb +8 -3
  44. data/lib/kentaa/api/resources/user.rb +8 -4
  45. data/lib/kentaa/api/resources/users.rb +8 -3
  46. data/lib/kentaa/api/resources/video.rb +1 -3
  47. data/lib/kentaa/api/response.rb +2 -2
  48. data/lib/kentaa/api/version.rb +1 -1
  49. metadata +4 -6
  50. data/lib/kentaa/api/resources/status.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e317284946afab2fe387f02c389431d8da90563fce27a24f08ced1b7d917ef58
4
- data.tar.gz: aafac4c4a7092d5110574524feda8b3f574da2783f0da53348da74fd1fadcafc
3
+ metadata.gz: 58138e9b4ca52fbd0e9af4db524365bfed6f349ba30fb498c2078aaeeb280dd8
4
+ data.tar.gz: 01b8334eb0e53bee3cc4d5bc6f48047a1ec8189348c142deeefeee9c54ac32ab
5
5
  SHA512:
6
- metadata.gz: 38577f345e7899350c7cbc707a7b80d4d091d202f20c42e1852fa4c9c4f9f094fe5a43d2191c6090bdb18dfc44d107404a0ebc8700f9631c84e066b66cd3c381
7
- data.tar.gz: 56c05b187e22f81f163a5e124404e926260335fc3888c727af336f35f3fa3f115af3b4dd24e406d2b38b69f7953da2fe63cb3dc19e96b6b9b520541316649fc3
6
+ metadata.gz: 67f498117301de1f06b0e233fa7771cc41a8afbc41f27f3dc1a5124a1145463efeb9dae068d758fc8f867484f83973dce97972998307eea663e77a78367ed843
7
+ data.tar.gz: e5b371bac8cdaaccc5c133581176a1c28c364c997fecb6d7611ad60d0fb60faba2452ac7bb39e0b450db084761c8644a8c7f0768d863f5efb118e43cff945d96
data/.rubocop.yml CHANGED
@@ -19,6 +19,9 @@ Metrics/BlockLength:
19
19
  Metrics/ClassLength:
20
20
  Enabled: false
21
21
 
22
+ Metrics/CyclomaticComplexity:
23
+ Enabled: false
24
+
22
25
  Metrics/LineLength:
23
26
  Enabled: false
24
27
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kentaa-api (0.2.1)
4
+ kentaa-api (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -54,7 +54,7 @@ The results might be part of a paginated set. You can query the next page by doi
54
54
  actions = client.actions.list(page: actions.next_page) if actions.next_page?
55
55
  ```
56
56
 
57
- See also `Kentaa::Api::Resources::Pagination` for the available methods for pagination.
57
+ See also `Kentaa::Api::Resources::List` for the available methods for pagination.
58
58
 
59
59
  The `all` method on the endpoint returns an [Enumerator](https://ruby-doc.org/core/Enumerator.html) and will iterate automatically through all pages to retrieve the requested data.
60
60
 
data/lib/kentaa/api.rb CHANGED
@@ -13,9 +13,8 @@ require_relative "api/clients/teams"
13
13
  require_relative "api/clients/users"
14
14
 
15
15
  require_relative "api/resources/base"
16
- require_relative "api/resources/pagination"
16
+ require_relative "api/resources/list"
17
17
  require_relative "api/resources/resource"
18
- require_relative "api/resources/status"
19
18
 
20
19
  require_relative "api/resources/action"
21
20
  require_relative "api/resources/actions"
@@ -7,13 +7,13 @@ module Kentaa
7
7
  include Kentaa::Api::Clients::All
8
8
 
9
9
  def list(options = {})
10
- response = request.get("/actions", options)
11
- Kentaa::Api::Resources::Actions.new(config, response)
10
+ actions = Kentaa::Api::Resources::Actions.new(config, options)
11
+ actions.load
12
12
  end
13
13
 
14
- def get(id)
15
- response = request.get("/actions/#{id}")
16
- Kentaa::Api::Resources::Action.new(config, response)
14
+ def get(id, options = {})
15
+ action = Kentaa::Api::Resources::Action.new(config, options.merge(id: id))
16
+ action.load
17
17
  end
18
18
  end
19
19
  end
@@ -10,7 +10,7 @@ module Kentaa
10
10
 
11
11
  loop do
12
12
  response = list(options.merge(page: page))
13
- response.each { |item| yielder.yield item } if response.success?
13
+ response.each { |item| yielder.yield item }
14
14
 
15
15
  raise StopIteration unless response.next_page?
16
16
 
@@ -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
@@ -7,13 +7,13 @@ module Kentaa
7
7
  include Kentaa::Api::Clients::All
8
8
 
9
9
  def list(options = {})
10
- response = request.get("/donations", options)
11
- Kentaa::Api::Resources::Donations.new(config, response)
10
+ donations = Kentaa::Api::Resources::Donations.new(config, options)
11
+ donations.load
12
12
  end
13
13
 
14
- def get(id)
15
- response = request.get("/donations/#{id}")
16
- Kentaa::Api::Resources::Donation.new(config, response)
14
+ def get(id, options = {})
15
+ donation = Kentaa::Api::Resources::Donation.new(config, options.merge(id: id))
16
+ donation.load
17
17
  end
18
18
  end
19
19
  end
@@ -7,13 +7,13 @@ module Kentaa
7
7
  include Kentaa::Api::Clients::All
8
8
 
9
9
  def list(options = {})
10
- response = request.get("/newsletter-subscriptions", options)
11
- Kentaa::Api::Resources::NewsletterSubscriptions.new(config, response)
10
+ newsletter_subscriptions = Kentaa::Api::Resources::NewsletterSubscriptions.new(config, options)
11
+ newsletter_subscriptions.load
12
12
  end
13
13
 
14
- def get(id)
15
- response = request.get("/newsletter-subscriptions/#{id}")
16
- Kentaa::Api::Resources::NewsletterSubscription.new(config, response)
14
+ def get(id, options = {})
15
+ newsletter_subscription = Kentaa::Api::Resources::NewsletterSubscription.new(config, options.merge(id: id))
16
+ newsletter_subscription.load
17
17
  end
18
18
  end
19
19
  end
@@ -7,13 +7,13 @@ module Kentaa
7
7
  include Kentaa::Api::Clients::All
8
8
 
9
9
  def list(options = {})
10
- response = request.get("/projects", options)
11
- Kentaa::Api::Resources::Projects.new(config, response)
10
+ projects = Kentaa::Api::Resources::Projects.new(config, options)
11
+ projects.load
12
12
  end
13
13
 
14
- def get(id)
15
- response = request.get("/projects/#{id}")
16
- Kentaa::Api::Resources::Project.new(config, response)
14
+ def get(id, options = {})
15
+ project = Kentaa::Api::Resources::Project.new(config, options.merge(id: id))
16
+ project.load
17
17
  end
18
18
  end
19
19
  end
@@ -7,13 +7,13 @@ module Kentaa
7
7
  include Kentaa::Api::Clients::All
8
8
 
9
9
  def list(options = {})
10
- response = request.get("/segments", options)
11
- Kentaa::Api::Resources::Segments.new(config, response)
10
+ segments = Kentaa::Api::Resources::Segments.new(config, options)
11
+ segments.load
12
12
  end
13
13
 
14
- def get(id)
15
- response = request.get("/segments/#{id}")
16
- Kentaa::Api::Resources::Segment.new(config, response)
14
+ def get(id, options = {})
15
+ segment = Kentaa::Api::Resources::Segment.new(config, options.merge(id: id))
16
+ segment.load
17
17
  end
18
18
  end
19
19
  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)
9
+ site.load
10
10
  end
11
11
  end
12
12
  end
@@ -7,13 +7,13 @@ module Kentaa
7
7
  include Kentaa::Api::Clients::All
8
8
 
9
9
  def list(options = {})
10
- response = request.get("/teams", options)
11
- Kentaa::Api::Resources::Teams.new(config, response)
10
+ teams = Kentaa::Api::Resources::Teams.new(config, options)
11
+ teams.load
12
12
  end
13
13
 
14
- def get(id)
15
- response = request.get("/teams/#{id}")
16
- Kentaa::Api::Resources::Team.new(config, response)
14
+ def get(id, options = {})
15
+ team = Kentaa::Api::Resources::Team.new(config, options.merge(id: id))
16
+ team.load
17
17
  end
18
18
  end
19
19
  end
@@ -7,13 +7,13 @@ module Kentaa
7
7
  include Kentaa::Api::Clients::All
8
8
 
9
9
  def list(options = {})
10
- response = request.get("/users", options)
11
- Kentaa::Api::Resources::Users.new(config, response)
10
+ users = Kentaa::Api::Resources::Users.new(config, options)
11
+ users.load
12
12
  end
13
13
 
14
- def get(id)
15
- response = request.get("/users/#{id}")
16
- Kentaa::Api::Resources::User.new(config, response)
14
+ def get(id, options = {})
15
+ user = Kentaa::Api::Resources::User.new(config, options.merge(id: id))
16
+ user.load
17
17
  end
18
18
  end
19
19
  end
@@ -4,5 +4,19 @@ 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
+
14
+ super(response.message)
15
+ end
16
+
17
+ def http_code
18
+ response.code
19
+ end
20
+ end
7
21
  end
8
22
  end
@@ -16,6 +16,12 @@ module Kentaa
16
16
  when "Action"
17
17
  client = Kentaa::Api::Clients::Actions.new(config)
18
18
  client.get(id)
19
+ when "Donation"
20
+ client = Kentaa::Api::Clients::Donations.new(config)
21
+ client.get(id)
22
+ when "NewsletterSubscription"
23
+ client = Kentaa::Api::Clients::NewsletterSubscriptions.new(config)
24
+ client.get(id)
19
25
  when "Project"
20
26
  client = Kentaa::Api::Clients::Projects.new(config)
21
27
  client.get(id)
@@ -28,6 +34,9 @@ module Kentaa
28
34
  when "Team"
29
35
  client = Kentaa::Api::Clients::Teams.new(config)
30
36
  client.get(id)
37
+ when "User"
38
+ client = Kentaa::Api::Clients::Users.new(config)
39
+ client.get(id)
31
40
  end
32
41
  end
33
42
  end
@@ -20,7 +20,7 @@ module Kentaa
20
20
  request["X-Api-Key"] = config.api_key
21
21
 
22
22
  begin
23
- response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
23
+ result = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
24
24
  http.request(request)
25
25
  end
26
26
  # Try to catch some common exceptions Net::HTTP might raise.
@@ -30,7 +30,13 @@ module Kentaa
30
30
  raise Kentaa::Api::Exception, e.message
31
31
  end
32
32
 
33
- Kentaa::Api::Response.new(response)
33
+ response = Kentaa::Api::Response.new(result)
34
+
35
+ if response.error?
36
+ raise Kentaa::Api::RequestError, response
37
+ end
38
+
39
+ response
34
40
  end
35
41
  end
36
42
  end
@@ -6,26 +6,20 @@ require 'time'
6
6
  module Kentaa
7
7
  module Api
8
8
  module Resources
9
- class Action < Base
10
- include Kentaa::Api::Resources::Resource
11
-
9
+ class Action < Resource
12
10
  def object_key
13
11
  "Action_#{id}"
14
12
  end
15
13
 
16
14
  def parent
17
15
  if team_id
18
- client = Kentaa::Api::Clients::Teams.new(config)
19
- client.get(team_id)
16
+ Kentaa::Api::Resources::Team.new(config, id: team_id)
20
17
  elsif project_id
21
- client = Kentaa::Api::Clients::Projects.new(config)
22
- client.get(project_id)
18
+ Kentaa::Api::Resources::Project.new(config, id: project_id)
23
19
  elsif segment_id
24
- client = Kentaa::Api::Clients::Segments.new(config)
25
- client.get(segment_id)
20
+ Kentaa::Api::Resources::Segment.new(config, id: segment_id)
26
21
  else
27
- client = Kentaa::Api::Clients::Sites.new(config)
28
- client.current
22
+ Kentaa::Api::Resources::Site.new(config, id: site_id)
29
23
  end
30
24
  end
31
25
 
@@ -50,7 +44,7 @@ module Kentaa
50
44
  end
51
45
 
52
46
  def owner
53
- @owner ||= Kentaa::Api::Resources::User.new(config, data[:owner])
47
+ @owner ||= Kentaa::Api::Resources::User.new(config, data: data[:owner])
54
48
  end
55
49
 
56
50
  def team_captain?
@@ -126,7 +120,7 @@ module Kentaa
126
120
  end
127
121
 
128
122
  def activity
129
- @activity ||= Kentaa::Api::Resources::Activity.new(config, data[:activity])
123
+ @activity ||= Kentaa::Api::Resources::Activity.new(config, data: data[:activity])
130
124
  end
131
125
 
132
126
  def previous_participations
@@ -142,11 +136,11 @@ module Kentaa
142
136
  end
143
137
 
144
138
  def registration_fee
145
- @registration_fee ||= Kentaa::Api::Resources::RegistrationFee.new(config, data[:registration_fee])
139
+ @registration_fee ||= Kentaa::Api::Resources::RegistrationFee.new(config, data: data[:registration_fee])
146
140
  end
147
141
 
148
142
  def location
149
- @location ||= Kentaa::Api::Resources::Location.new(config, data[:location])
143
+ @location ||= Kentaa::Api::Resources::Location.new(config, data: data[:location])
150
144
  end
151
145
 
152
146
  def photos
@@ -155,7 +149,7 @@ module Kentaa
155
149
 
156
150
  if data[:photos]
157
151
  data[:photos].each do |photo|
158
- photos << Kentaa::Api::Resources::Photo.new(config, photo)
152
+ photos << Kentaa::Api::Resources::Photo.new(config, data: photo)
159
153
  end
160
154
  end
161
155
 
@@ -169,7 +163,7 @@ module Kentaa
169
163
 
170
164
  if data[:videos]
171
165
  data[:videos].each do |video|
172
- videos << Kentaa::Api::Resources::Video.new(config, video)
166
+ videos << Kentaa::Api::Resources::Video.new(config, data: video)
173
167
  end
174
168
  end
175
169
 
@@ -183,7 +177,7 @@ module Kentaa
183
177
 
184
178
  if data[:questions]
185
179
  data[:questions].each do |question|
186
- questions << Kentaa::Api::Resources::Question.new(config, question)
180
+ questions << Kentaa::Api::Resources::Question.new(config, data: question)
187
181
  end
188
182
  end
189
183
 
@@ -192,12 +186,18 @@ module Kentaa
192
186
  end
193
187
 
194
188
  def consent
195
- @consent ||= Kentaa::Api::Resources::Consent.new(config, data[:consent]) if data[:consent]
189
+ @consent ||= Kentaa::Api::Resources::Consent.new(config, data: data[:consent]) if data[:consent]
196
190
  end
197
191
 
198
192
  def external_reference
199
193
  data[:external_reference]
200
194
  end
195
+
196
+ protected
197
+
198
+ def load_resource(options)
199
+ request.get("/actions/#{id}", options)
200
+ end
201
201
  end
202
202
  end
203
203
  end
@@ -3,14 +3,19 @@
3
3
  module Kentaa
4
4
  module Api
5
5
  module Resources
6
- class Actions < Base
6
+ class Actions < List
7
7
  include Enumerable
8
- include Kentaa::Api::Resources::Pagination
9
8
 
10
9
  def each(&block)
11
10
  actions.each(&block)
12
11
  end
13
12
 
13
+ protected
14
+
15
+ def load_resource(options)
16
+ request.get("/actions", options)
17
+ end
18
+
14
19
  private
15
20
 
16
21
  def actions
@@ -19,7 +24,7 @@ module Kentaa
19
24
 
20
25
  if data
21
26
  data.each do |action|
22
- actions << Kentaa::Api::Resources::Action.new(config, action)
27
+ actions << Kentaa::Api::Resources::Action.new(config, data: action)
23
28
  end
24
29
  end
25
30
 
@@ -3,9 +3,7 @@
3
3
  module Kentaa
4
4
  module Api
5
5
  module Resources
6
- class Activity < Base
7
- include Kentaa::Api::Resources::Resource
8
-
6
+ class Activity < Resource
9
7
  def name
10
8
  data[:name]
11
9
  end