kentaa-api 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -10,14 +10,17 @@ module Kentaa
10
10
  actions.each(&block)
11
11
  end
12
12
 
13
- protected
14
-
15
- def load_resource(options)
16
- request.get("/actions", options)
13
+ def create(attributes = {})
14
+ action = Kentaa::Api::Resources::Action.new(config, options)
15
+ action.save(attributes)
17
16
  end
18
17
 
19
18
  private
20
19
 
20
+ def load_resource
21
+ request.get("/actions", options)
22
+ end
23
+
21
24
  def actions
22
25
  @actions ||= begin
23
26
  actions = []
@@ -3,7 +3,17 @@
3
3
  module Kentaa
4
4
  module Api
5
5
  module Resources
6
- class Activity < Resource
6
+ class Activity
7
+ attr_reader :data
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+
13
+ def id
14
+ data[:id]
15
+ end
16
+
7
17
  def name
8
18
  data[:name]
9
19
  end
@@ -3,7 +3,13 @@
3
3
  module Kentaa
4
4
  module Api
5
5
  module Resources
6
- class Address < Resource
6
+ class Address
7
+ attr_reader :data
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+
7
13
  def address
8
14
  data[:address]
9
15
  end
@@ -1,9 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'time'
4
+
3
5
  module Kentaa
4
6
  module Api
5
7
  module Resources
6
- class Banner < Resource
8
+ class Banner
9
+ attr_reader :data
10
+
11
+ def initialize(data)
12
+ @data = data
13
+ end
14
+
15
+ def id
16
+ data[:id]
17
+ end
18
+
19
+ def created_at
20
+ Time.parse(data[:created_at]) if data[:created_at]
21
+ end
22
+
23
+ def updated_at
24
+ Time.parse(data[:updated_at]) if data[:updated_at]
25
+ end
26
+
7
27
  def url
8
28
  data[:url]
9
29
  end
@@ -12,7 +12,7 @@ module Kentaa
12
12
  end
13
13
 
14
14
  def load
15
- @response ||= load_resource(options)
15
+ @response ||= load_resource
16
16
 
17
17
  self
18
18
  end
@@ -28,7 +28,7 @@ module Kentaa
28
28
  class_name.gsub(/([^\^])([A-Z])/, '\1_\2').downcase.to_sym
29
29
  end
30
30
 
31
- def load_resource(_options)
31
+ def load_resource
32
32
  raise NotImplementedError
33
33
  end
34
34
 
@@ -3,7 +3,13 @@
3
3
  module Kentaa
4
4
  module Api
5
5
  module Resources
6
- class Consent < Resource
6
+ class Consent
7
+ attr_reader :data
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+
7
13
  def url
8
14
  data[:url]
9
15
  end
@@ -3,7 +3,13 @@
3
3
  module Kentaa
4
4
  module Api
5
5
  module Resources
6
- class Contact < Resource
6
+ class Contact
7
+ attr_reader :data
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+
7
13
  def first_name
8
14
  data[:first_name]
9
15
  end
@@ -175,7 +175,7 @@ module Kentaa
175
175
 
176
176
  if data[:questions]
177
177
  data[:questions].each do |question|
178
- questions << Kentaa::Api::Resources::Question.new(config, data: question)
178
+ questions << Kentaa::Api::Resources::Question.new(question)
179
179
  end
180
180
  end
181
181
 
@@ -184,11 +184,11 @@ module Kentaa
184
184
  end
185
185
 
186
186
  def reward
187
- @reward ||= Kentaa::Api::Resources::Reward.new(config, data: data[:reward]) if data[:reward]
187
+ @reward ||= Kentaa::Api::Resources::Reward.new(data[:reward]) if data[:reward]
188
188
  end
189
189
 
190
190
  def address
191
- @address ||= Kentaa::Api::Resources::Address.new(config, data: data[:address]) if data[:address]
191
+ @address ||= Kentaa::Api::Resources::Address.new(data[:address]) if data[:address]
192
192
  end
193
193
 
194
194
  def birthday
@@ -204,12 +204,12 @@ module Kentaa
204
204
  end
205
205
 
206
206
  def consent
207
- @consent ||= Kentaa::Api::Resources::Consent.new(config, data: data[:consent]) if data[:consent]
207
+ @consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
208
208
  end
209
209
 
210
- protected
210
+ private
211
211
 
212
- def load_resource(options)
212
+ def load_resource
213
213
  request.get("/donations/#{id}", options)
214
214
  end
215
215
  end
@@ -10,14 +10,12 @@ module Kentaa
10
10
  donations.each(&block)
11
11
  end
12
12
 
13
- protected
13
+ private
14
14
 
15
- def load_resource(options)
15
+ def load_resource
16
16
  request.get("/donations", options)
17
17
  end
18
18
 
19
- private
20
-
21
19
  def donations
22
20
  @donations ||= begin
23
21
  donations = []
@@ -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
@@ -51,6 +51,23 @@ module Kentaa
51
51
  def previous
52
52
  self.class.new(config, options.merge(page: previous_page)) if previous_page?
53
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
54
71
  end
55
72
  end
56
73
  end
@@ -3,7 +3,13 @@
3
3
  module Kentaa
4
4
  module Api
5
5
  module Resources
6
- class Location < Resource
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,112 @@
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)
17
+ elsif team_id
18
+ Kentaa::Api::Resources::Team.new(config, id: team_id)
19
+ elsif project_id
20
+ Kentaa::Api::Resources::Project.new(config, id: project_id)
21
+ elsif segment_id
22
+ Kentaa::Api::Resources::Segment.new(config, id: segment_id)
23
+ else
24
+ Kentaa::Api::Resources::Site.new(config, id: site_id)
25
+ end
26
+ end
27
+
28
+ def site_id
29
+ data[:site_id]
30
+ end
31
+
32
+ def segment_id
33
+ data[:segment_id]
34
+ end
35
+
36
+ def project_id
37
+ data[:project_id]
38
+ end
39
+
40
+ def team_id
41
+ data[:team_id]
42
+ end
43
+
44
+ def action_id
45
+ data[:action_id]
46
+ end
47
+
48
+ def first_name
49
+ data[:first_name]
50
+ end
51
+
52
+ def infix
53
+ data[:infix]
54
+ end
55
+
56
+ def last_name
57
+ data[:last_name]
58
+ end
59
+
60
+ def name
61
+ [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
62
+ end
63
+
64
+ def anonymous?
65
+ data[:anonymous]
66
+ end
67
+
68
+ def email
69
+ data[:email]
70
+ end
71
+
72
+ def message
73
+ data[:message]
74
+ end
75
+
76
+ def currency
77
+ data[:currency]
78
+ end
79
+
80
+ def amount
81
+ BigDecimal(data[:amount])
82
+ end
83
+
84
+ def countable?
85
+ data[:countable]
86
+ end
87
+
88
+ def target_url
89
+ data[:target_url]
90
+ end
91
+
92
+ private
93
+
94
+ def load_resource
95
+ request.get("/manual-donations/#{id}", options)
96
+ end
97
+
98
+ def create_resource(attributes)
99
+ request.post("/manual-donations", options, attributes)
100
+ end
101
+
102
+ def update_resource(attributes)
103
+ request.patch("/manual-donations/#{id}", options, attributes)
104
+ end
105
+
106
+ def delete_resource
107
+ request.delete("/manual-donations/#{id}", options)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kentaa
4
+ module Api
5
+ module Resources
6
+ class ManualDonations < List
7
+ include Enumerable
8
+
9
+ def each(&block)
10
+ manual_donations.each(&block)
11
+ end
12
+
13
+ def create(attributes = {})
14
+ donation = Kentaa::Api::Resources::ManualDonation.new(config, options)
15
+ donation.save(attributes)
16
+ end
17
+
18
+ private
19
+
20
+ def load_resource
21
+ request.get("/manual-donations", options)
22
+ end
23
+
24
+ def manual_donations
25
+ @manual_donations ||= begin
26
+ manual_donations = []
27
+
28
+ if data
29
+ data.each do |manual_donation|
30
+ manual_donations << Kentaa::Api::Resources::ManualDonation.new(config, data: manual_donation)
31
+ end
32
+ end
33
+
34
+ manual_donations
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -59,12 +59,12 @@ module Kentaa
59
59
  end
60
60
 
61
61
  def consent
62
- @consent ||= Kentaa::Api::Resources::Consent.new(config, data: data[:consent]) if data[:consent]
62
+ @consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
63
63
  end
64
64
 
65
- protected
65
+ private
66
66
 
67
- def load_resource(options)
67
+ def load_resource
68
68
  request.get("/newsletter-subscriptions/#{id}", options)
69
69
  end
70
70
  end
@@ -10,14 +10,12 @@ module Kentaa
10
10
  newsletter_subscriptions.each(&block)
11
11
  end
12
12
 
13
- protected
13
+ private
14
14
 
15
- def load_resource(options)
15
+ def load_resource
16
16
  request.get("/newsletter-subscriptions", options)
17
17
  end
18
18
 
19
- private
20
-
21
19
  def newsletter_subscriptions
22
20
  @newsletter_subscriptions ||= begin
23
21
  newsletter_subscriptions = []