kentaa-api 0.7.2 → 0.9.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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +106 -5
  3. data/lib/kentaa/api/client.rb +16 -0
  4. data/lib/kentaa/api/resources/action.rb +39 -3
  5. data/lib/kentaa/api/resources/activity.rb +26 -6
  6. data/lib/kentaa/api/resources/avatar.rb +30 -0
  7. data/lib/kentaa/api/resources/company.rb +11 -1
  8. data/lib/kentaa/api/resources/company_package.rb +9 -1
  9. data/lib/kentaa/api/resources/contact.rb +4 -0
  10. data/lib/kentaa/api/resources/donation.rb +22 -0
  11. data/lib/kentaa/api/resources/location.rb +8 -0
  12. data/lib/kentaa/api/resources/logo.rb +23 -0
  13. data/lib/kentaa/api/resources/manual_donation.rb +4 -0
  14. data/lib/kentaa/api/resources/news.rb +77 -0
  15. data/lib/kentaa/api/resources/order.rb +112 -0
  16. data/lib/kentaa/api/resources/order_item.rb +34 -0
  17. data/lib/kentaa/api/resources/payment.rb +101 -0
  18. data/lib/kentaa/api/resources/product.rb +42 -0
  19. data/lib/kentaa/api/resources/project.rb +40 -0
  20. data/lib/kentaa/api/resources/question.rb +4 -0
  21. data/lib/kentaa/api/resources/registration_fee.rb +7 -1
  22. data/lib/kentaa/api/resources/resource.rb +6 -2
  23. data/lib/kentaa/api/resources/reward.rb +6 -0
  24. data/lib/kentaa/api/resources/security_activity.rb +29 -0
  25. data/lib/kentaa/api/resources/segment.rb +16 -0
  26. data/lib/kentaa/api/resources/site.rb +38 -0
  27. data/lib/kentaa/api/resources/team.rb +12 -0
  28. data/lib/kentaa/api/resources/theme.rb +23 -0
  29. data/lib/kentaa/api/resources/ticket.rb +35 -0
  30. data/lib/kentaa/api/resources/user.rb +16 -0
  31. data/lib/kentaa/api/response.rb +3 -1
  32. data/lib/kentaa/api/util.rb +4 -5
  33. data/lib/kentaa/api/version.rb +1 -1
  34. data/lib/kentaa/api.rb +11 -1
  35. metadata +56 -4
@@ -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 Order < Resource
10
+ def entity
11
+ if action_id
12
+ Kentaa::Api::Resources::Action.new(config, id: action_id, options: options)
13
+ else
14
+ Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
15
+ end
16
+ end
17
+
18
+ def site
19
+ Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
20
+ end
21
+
22
+ def public_id
23
+ data[:public_id]
24
+ end
25
+
26
+ def site_id
27
+ data[:site_id]
28
+ end
29
+
30
+ def segment_id
31
+ data[:segment_id]
32
+ end
33
+
34
+ def project_id
35
+ data[:project_id]
36
+ end
37
+
38
+ def action_id
39
+ data[:action_id]
40
+ end
41
+
42
+ def first_name
43
+ data[:first_name]
44
+ end
45
+
46
+ def infix
47
+ data[:infix]
48
+ end
49
+
50
+ def last_name
51
+ data[:last_name]
52
+ end
53
+
54
+ def name
55
+ [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(' ')
56
+ end
57
+
58
+ def company
59
+ data[:company]
60
+ end
61
+
62
+ def currency
63
+ data[:currency]
64
+ end
65
+
66
+ def total_amount
67
+ BigDecimal(data[:total_amount])
68
+ end
69
+
70
+ def invoicenumber
71
+ data[:invoicenumber]
72
+ end
73
+
74
+ def payment_status
75
+ data[:payment_status]
76
+ end
77
+
78
+ def address
79
+ @address ||= Kentaa::Api::Resources::Address.new(data[:address]) if data[:address]
80
+ end
81
+
82
+ def phone
83
+ data[:phone]
84
+ end
85
+
86
+ def locale
87
+ data[:locale]
88
+ end
89
+
90
+ def items
91
+ @items ||= begin
92
+ items = []
93
+
94
+ if data[:items]
95
+ data[:items].each do |item|
96
+ items << Kentaa::Api::Resources::OrderItem.new(item)
97
+ end
98
+ end
99
+
100
+ items
101
+ end
102
+ end
103
+
104
+ private
105
+
106
+ def load_resource
107
+ request.get("/orders/#{id}", options)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bigdecimal'
4
+ require 'time'
5
+
6
+ module Kentaa
7
+ module Api
8
+ module Resources
9
+ class OrderItem
10
+ attr_reader :data
11
+
12
+ def initialize(data)
13
+ @data = data
14
+ end
15
+
16
+ def product
17
+ Kentaa::Api::Resources::Product.new(data[:product])
18
+ end
19
+
20
+ def quantity
21
+ data[:quantity]
22
+ end
23
+
24
+ def amount
25
+ BigDecimal(data[:amount])
26
+ end
27
+
28
+ def currency
29
+ data[:currency]
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bigdecimal'
4
+
5
+ module Kentaa
6
+ module Api
7
+ module Resources
8
+ class Payment < Resource
9
+ def object_key
10
+ "Payment_#{id}"
11
+ end
12
+
13
+ def site
14
+ Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
15
+ end
16
+
17
+ def site_id
18
+ data[:site_id]
19
+ end
20
+
21
+ def currency
22
+ data[:currency]
23
+ end
24
+
25
+ def amount
26
+ BigDecimal(data[:amount])
27
+ end
28
+
29
+ def invoicenumber
30
+ data[:invoicenumber]
31
+ end
32
+
33
+ def payment_method
34
+ data[:payment_method]
35
+ end
36
+
37
+ def payment_status
38
+ data[:payment_status]
39
+ end
40
+
41
+ def transaction_id
42
+ data[:transaction_id]
43
+ end
44
+
45
+ def payment_id
46
+ data[:payment_id]
47
+ end
48
+
49
+ def account_iban
50
+ data[:account_iban]
51
+ end
52
+
53
+ def account_bic
54
+ data[:account_bic]
55
+ end
56
+
57
+ def account_name
58
+ data[:account_name]
59
+ end
60
+
61
+ def description
62
+ data[:description]
63
+ end
64
+
65
+ def donations
66
+ @donations ||= begin
67
+ donations = []
68
+
69
+ if data[:donations]
70
+ data[:donations].each do |donation|
71
+ donations << Kentaa::Api::Resources::Donation.new(config, data: donation, options: options)
72
+ end
73
+ end
74
+
75
+ donations
76
+ end
77
+ end
78
+
79
+ def orders
80
+ @orders ||= begin
81
+ orders = []
82
+
83
+ if data[:orders]
84
+ data[:orders].each do |order|
85
+ orders << Kentaa::Api::Resources::Order.new(config, data: order, options: options)
86
+ end
87
+ end
88
+
89
+ orders
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ def load_resource
96
+ request.get("/payments/#{id}", options)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bigdecimal'
4
+ require 'time'
5
+
6
+ module Kentaa
7
+ module Api
8
+ module Resources
9
+ class Product
10
+ attr_reader :data
11
+
12
+ def initialize(data)
13
+ @data = data
14
+ end
15
+
16
+ def id
17
+ data[:id]
18
+ end
19
+
20
+ def title
21
+ data[:title]
22
+ end
23
+
24
+ def variant_id
25
+ data[:variant_id]
26
+ end
27
+
28
+ def variant_title
29
+ data[:variant_title]
30
+ end
31
+
32
+ def price
33
+ BigDecimal(data[:price])
34
+ end
35
+
36
+ def currency
37
+ data[:currency]
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -23,6 +23,10 @@ module Kentaa
23
23
  Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
24
24
  end
25
25
 
26
+ def public_id
27
+ data[:public_id]
28
+ end
29
+
26
30
  def slug
27
31
  data[:slug]
28
32
  end
@@ -63,6 +67,14 @@ module Kentaa
63
67
  data[:visible]
64
68
  end
65
69
 
70
+ def publishable?
71
+ data[:publishable]
72
+ end
73
+
74
+ def published_at
75
+ Time.parse(data[:published_at]) if data[:published_at]
76
+ end
77
+
66
78
  def countable?
67
79
  data[:countable]
68
80
  end
@@ -87,6 +99,10 @@ module Kentaa
87
99
  data[:donate_url]
88
100
  end
89
101
 
102
+ def has_target_amount?
103
+ data[:has_target_amount]
104
+ end
105
+
90
106
  def location
91
107
  @location ||= Kentaa::Api::Resources::Location.new(data[:location]) if data[:location]
92
108
  end
@@ -181,6 +197,30 @@ module Kentaa
181
197
  @newsletter_subscriptions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::NewsletterSubscription, endpoint_path: "/projects/#{id}/newsletter-subscriptions")
182
198
  end
183
199
 
200
+ def activities
201
+ @activities ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Activity, endpoint_path: "/projects/#{id}/activities")
202
+ end
203
+
204
+ def news
205
+ @news ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::News, endpoint_path: "/projects/#{id}/news")
206
+ end
207
+
208
+ def orders
209
+ @orders ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Order, endpoint_path: "/projects/#{id}/orders")
210
+ end
211
+
212
+ def publish
213
+ request.post("/projects/#{id}/publish")
214
+ end
215
+
216
+ def hide
217
+ request.post("/projects/#{id}/hide")
218
+ end
219
+
220
+ def show
221
+ request.post("/projects/#{id}/show")
222
+ end
223
+
184
224
  private
185
225
 
186
226
  def load_resource
@@ -29,6 +29,10 @@ module Kentaa
29
29
  def answer
30
30
  data[:answer]
31
31
  end
32
+
33
+ def external_reference
34
+ data[:external_reference]
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -4,8 +4,14 @@ module Kentaa
4
4
  module Api
5
5
  module Resources
6
6
  class RegistrationFee
7
+ attr_reader :data
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+
7
13
  def amount
8
- data[:amount]
14
+ BigDecimal(data[:amount])
9
15
  end
10
16
 
11
17
  def title
@@ -26,6 +26,10 @@ module Kentaa
26
26
  self
27
27
  end
28
28
 
29
+ def create(attributes)
30
+ save(attributes)
31
+ end
32
+
29
33
  def save(attributes)
30
34
  if id
31
35
  @response = update_resource(attributes)
@@ -53,11 +57,11 @@ module Kentaa
53
57
 
54
58
  private
55
59
 
56
- def create_resource
60
+ def create_resource(_attributes)
57
61
  raise NotImplementedError
58
62
  end
59
63
 
60
- def update_resource
64
+ def update_resource(_attributes)
61
65
  raise NotImplementedError
62
66
  end
63
67
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'bigdecimal'
4
+
3
5
  module Kentaa
4
6
  module Api
5
7
  module Resources
@@ -18,6 +20,10 @@ module Kentaa
18
20
  data[:type]
19
21
  end
20
22
 
23
+ def amount
24
+ BigDecimal(data[:amount])
25
+ end
26
+
21
27
  def title
22
28
  data[:title]
23
29
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ module Kentaa
6
+ module Api
7
+ module Resources
8
+ class SecurityActivity
9
+ attr_reader :data
10
+
11
+ def initialize(data)
12
+ @data = data
13
+ end
14
+
15
+ def last_login_at
16
+ Time.parse(data[:last_login_at]) if data[:last_login_at]
17
+ end
18
+
19
+ def reset_password_email_sent_at
20
+ Time.parse(data[:reset_password_email_sent_at]) if data[:reset_password_email_sent_at]
21
+ end
22
+
23
+ def last_password_reset_at
24
+ Time.parse(data[:last_password_reset_at]) if data[:last_password_reset_at]
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -19,6 +19,10 @@ module Kentaa
19
19
  Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
20
20
  end
21
21
 
22
+ def public_id
23
+ data[:public_id]
24
+ end
25
+
22
26
  def site_id
23
27
  data[:site_id]
24
28
  end
@@ -105,6 +109,18 @@ module Kentaa
105
109
  @newsletter_subscriptions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::NewsletterSubscription, endpoint_path: "/segments/#{id}/newsletter-subscriptions")
106
110
  end
107
111
 
112
+ def activities
113
+ @activities ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Activity, endpoint_path: "/segments/#{id}/activities")
114
+ end
115
+
116
+ def news
117
+ @news ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::News, endpoint_path: "/segments/#{id}/news")
118
+ end
119
+
120
+ def orders
121
+ @orders ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Order, endpoint_path: "/segments/#{id}/orders")
122
+ end
123
+
108
124
  private
109
125
 
110
126
  def load_resource
@@ -11,6 +11,10 @@ module Kentaa
11
11
  "Site_#{id}"
12
12
  end
13
13
 
14
+ def public_id
15
+ data[:public_id]
16
+ end
17
+
14
18
  def host
15
19
  data[:host]
16
20
  end
@@ -81,10 +85,36 @@ module Kentaa
81
85
  end
82
86
  end
83
87
 
88
+ def logos
89
+ @logos ||= begin
90
+ logos = []
91
+
92
+ if data[:logos]
93
+ data[:logos].map do |logo|
94
+ logos << Kentaa::Api::Resources::Logo.new(logo)
95
+ end
96
+ end
97
+
98
+ logos
99
+ end
100
+ end
101
+
84
102
  def external_reference
85
103
  data[:external_reference]
86
104
  end
87
105
 
106
+ def background_image_url
107
+ data[:background_image_url]
108
+ end
109
+
110
+ def sign_up_flow_background_image_url
111
+ data[:sign_up_flow_background_image_url]
112
+ end
113
+
114
+ def theme
115
+ @theme ||= Kentaa::Api::Resources::Theme.new(data[:theme])
116
+ end
117
+
88
118
  def donations
89
119
  @donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Donation, endpoint_path: '/donations')
90
120
  end
@@ -97,6 +127,14 @@ module Kentaa
97
127
  @newsletter_subscriptions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::NewsletterSubscription, endpoint_path: '/newsletter-subscriptions')
98
128
  end
99
129
 
130
+ def orders
131
+ @orders ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Order, endpoint_path: '/orders')
132
+ end
133
+
134
+ def activities
135
+ @activities ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Activity, endpoint_path: '/activities')
136
+ end
137
+
100
138
  private
101
139
 
102
140
  def load_resource
@@ -25,6 +25,10 @@ module Kentaa
25
25
  Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
26
26
  end
27
27
 
28
+ def public_id
29
+ data[:public_id]
30
+ end
31
+
28
32
  def slug
29
33
  data[:slug]
30
34
  end
@@ -71,6 +75,10 @@ module Kentaa
71
75
  data[:description]
72
76
  end
73
77
 
78
+ def total_team_members
79
+ data[:total_team_members]
80
+ end
81
+
74
82
  def target_amount
75
83
  data[:target_amount]
76
84
  end
@@ -169,6 +177,10 @@ module Kentaa
169
177
  @manual_donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::ManualDonation, endpoint_path: "/teams/#{id}/manual-donations")
170
178
  end
171
179
 
180
+ def news
181
+ @news ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::News, endpoint_path: "/teams/#{id}/news")
182
+ end
183
+
172
184
  private
173
185
 
174
186
  def load_resource
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kentaa
4
+ module Api
5
+ module Resources
6
+ class Theme
7
+ attr_reader :data
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+
13
+ def primary_color
14
+ data[:primary_color]
15
+ end
16
+
17
+ def contrast_color
18
+ data[:contrast_color]
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kentaa
4
+ module Api
5
+ module Resources
6
+ class Ticket
7
+ attr_reader :data
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+
13
+ def id
14
+ data[:id]
15
+ end
16
+
17
+ def created_at
18
+ Time.parse(data[:created_at]) if data[:created_at]
19
+ end
20
+
21
+ def updated_at
22
+ Time.parse(data[:updated_at]) if data[:updated_at]
23
+ end
24
+
25
+ def ticket_number
26
+ data[:ticket_number]
27
+ end
28
+
29
+ def ticket_url
30
+ data[:ticket_url]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -14,6 +14,10 @@ module Kentaa
14
14
  Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
15
15
  end
16
16
 
17
+ def public_id
18
+ data[:public_id]
19
+ end
20
+
17
21
  def site_id
18
22
  data[:site_id]
19
23
  end
@@ -90,6 +94,10 @@ module Kentaa
90
94
  data[:locale]
91
95
  end
92
96
 
97
+ def security_activity
98
+ @security_activity ||= Kentaa::Api::Resources::SecurityActivity.new(data[:security_activity]) if data[:security_activity]
99
+ end
100
+
93
101
  def consent
94
102
  Kentaa::Api::Deprecation.warn('#consent is deprecated. Please use #consents instead.', caller)
95
103
 
@@ -114,6 +122,14 @@ module Kentaa
114
122
  @actions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Action, endpoint_path: "/users/#{id}/actions")
115
123
  end
116
124
 
125
+ def avatar
126
+ @avatar ||= Kentaa::Api::Resources::Avatar.new(config, options: options.merge(endpoint_path: "/users/#{id}"))
127
+ end
128
+
129
+ def reset_password
130
+ request.post("/users/#{id}/reset-password")
131
+ end
132
+
117
133
  private
118
134
 
119
135
  def load_resource
@@ -5,6 +5,8 @@ require 'json'
5
5
  module Kentaa
6
6
  module Api
7
7
  class Response
8
+ SUCCESS_CODES = [200, 201, 204].freeze
9
+
8
10
  attr_reader :response, :body
9
11
 
10
12
  def initialize(response)
@@ -13,7 +15,7 @@ module Kentaa
13
15
  end
14
16
 
15
17
  def success?
16
- (http_code == 200 || http_code == 201 || http_code == 204) && !message
18
+ SUCCESS_CODES.include?(http_code) && !message
17
19
  end
18
20
 
19
21
  def error?