kentaa-api 0.6.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kentaa
4
+ module Api
5
+ module Resources
6
+ class CompanyPackage
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 amount
26
+ data[:amount]
27
+ end
28
+
29
+ def title
30
+ data[:title]
31
+ end
32
+
33
+ def description
34
+ data[:description]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,25 +1,102 @@
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
8
  class Consent
9
+ STATUS_GRANTED = 'granted'
10
+ STATUS_REVOKED = 'revoked'
11
+
12
+ TYPE_TERMS_CONDITIONS = 'terms_conditions'
13
+ TYPE_PROCESSING_PERSONAL_DATA = 'processing_personal_data'
14
+ TYPE_PROCESSING_PERSONAL_SENSITIVE_DATA = 'processing_personal_sensitive_data'
15
+ TYPE_NEWSLETTER_SUBSCRIPTION = 'newsletter_subscription'
16
+ TYPE_NEWS_ITEM_SUBSCRIPTION = 'news_item_subscription'
17
+ TYPE_CONTACT_PHONE = 'contact_phone'
18
+ TYPE_CONTACT_PHONE_COMMERCIAL = 'contact_phone_commercial'
19
+
7
20
  attr_reader :data
8
21
 
9
22
  def initialize(data)
10
23
  @data = data
11
24
  end
12
25
 
13
- def url
14
- data[:url]
26
+ def consent_type
27
+ data[:consent_type]
28
+ end
29
+
30
+ def terms_conditions?
31
+ consent_type == TYPE_TERMS_CONDITIONS
32
+ end
33
+
34
+ def processing_personal_data?
35
+ consent_type == TYPE_PROCESSING_PERSONAL_DATA
36
+ end
37
+
38
+ def processing_personal_sensitive_data?
39
+ consent_type == TYPE_PROCESSING_PERSONAL_SENSITIVE_DATA
40
+ end
41
+
42
+ def newsletter_subscription?
43
+ consent_type == TYPE_NEWSLETTER_SUBSCRIPTION
44
+ end
45
+
46
+ def news_item_subscription?
47
+ consent_type == TYPE_NEWS_ITEM_SUBSCRIPTION
48
+ end
49
+
50
+ def contact_phone?
51
+ consent_type == TYPE_CONTACT_PHONE
52
+ end
53
+
54
+ def contact_phone_commercial?
55
+ consent_type == TYPE_CONTACT_PHONE_COMMERCIAL
56
+ end
57
+
58
+ def consent_status
59
+ data[:consent_status]
60
+ end
61
+
62
+ def granted?
63
+ consent_status == STATUS_GRANTED
64
+ end
65
+
66
+ def revoked?
67
+ consent_status == STATUS_REVOKED
68
+ end
69
+
70
+ def granted_at
71
+ Time.parse(data[:granted_at])
72
+ end
73
+
74
+ def revoked_at
75
+ Time.parse(data[:revoked_at]) if data[:revoked_at]
76
+ end
77
+
78
+ def consent_text
79
+ data[:consent_text]
15
80
  end
16
81
 
17
82
  def text
18
- data[:text]
83
+ data[:text] || data[:consent_text]
84
+ end
85
+
86
+ def url
87
+ data[:url]
19
88
  end
20
89
 
21
90
  def version
22
- data[:version]
91
+ data[:version] || data[:terms_conditions_version]
92
+ end
93
+
94
+ def terms_conditions_version
95
+ data[:terms_conditions_version]
96
+ end
97
+
98
+ def privacy_version
99
+ data[:privacy_version]
23
100
  end
24
101
  end
25
102
  end
@@ -23,7 +23,7 @@ module Kentaa
23
23
  end
24
24
 
25
25
  def name
26
- [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
26
+ [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(' ')
27
27
  end
28
28
 
29
29
  def email
@@ -16,6 +16,8 @@ module Kentaa
16
16
  Kentaa::Api::Resources::Action.new(config, id: action_id, options: options)
17
17
  elsif team_id
18
18
  Kentaa::Api::Resources::Team.new(config, id: team_id, options: options)
19
+ elsif company_id
20
+ Kentaa::Api::Resources::Company.new(config, id: company_id, options: options)
19
21
  elsif project_id
20
22
  Kentaa::Api::Resources::Project.new(config, id: project_id, options: options)
21
23
  elsif segment_id
@@ -27,6 +29,10 @@ module Kentaa
27
29
  end
28
30
  end
29
31
 
32
+ def recurring_donor
33
+ Kentaa::Api::Resources::RecurringDonor.new(config, id: recurring_donor_id, options: options) if recurring_donor_id
34
+ end
35
+
30
36
  def site
31
37
  Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
32
38
  end
@@ -47,6 +53,10 @@ module Kentaa
47
53
  data[:project_id]
48
54
  end
49
55
 
56
+ def company_id
57
+ data[:company_id]
58
+ end
59
+
50
60
  def team_id
51
61
  data[:team_id]
52
62
  end
@@ -55,6 +65,10 @@ module Kentaa
55
65
  data[:action_id]
56
66
  end
57
67
 
68
+ def recurring_donor_id
69
+ data[:recurring_donor_id]
70
+ end
71
+
58
72
  def first_name
59
73
  data[:first_name]
60
74
  end
@@ -68,7 +82,7 @@ module Kentaa
68
82
  end
69
83
 
70
84
  def name
71
- [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
85
+ [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(' ')
72
86
  end
73
87
 
74
88
  def company
@@ -79,6 +93,10 @@ module Kentaa
79
93
  data[:anonymous]
80
94
  end
81
95
 
96
+ def contact_details_type
97
+ data[:contact_details_type]
98
+ end
99
+
82
100
  def email
83
101
  data[:email]
84
102
  end
@@ -99,6 +117,10 @@ module Kentaa
99
117
  data[:locale]
100
118
  end
101
119
 
120
+ def frequency_type
121
+ data[:frequency_type]
122
+ end
123
+
102
124
  def currency
103
125
  data[:currency]
104
126
  end
@@ -214,9 +236,25 @@ module Kentaa
214
236
  end
215
237
 
216
238
  def consent
239
+ Kentaa::Api::Deprecation.warn('#consent is deprecated. Please use #consents instead.', caller)
240
+
217
241
  @consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
218
242
  end
219
243
 
244
+ def consents
245
+ @consents ||= begin
246
+ consents = []
247
+
248
+ if data[:consents]
249
+ data[:consents].each do |consent|
250
+ consents << Kentaa::Api::Resources::Consent.new(consent)
251
+ end
252
+ end
253
+
254
+ consents
255
+ end
256
+ end
257
+
220
258
  private
221
259
 
222
260
  def load_resource
@@ -16,6 +16,8 @@ module Kentaa
16
16
  Kentaa::Api::Resources::Action.new(config, id: action_id, options: options)
17
17
  elsif team_id
18
18
  Kentaa::Api::Resources::Team.new(config, id: team_id, options: options)
19
+ elsif company_id
20
+ Kentaa::Api::Resources::Company.new(config, id: company_id, options: options)
19
21
  elsif project_id
20
22
  Kentaa::Api::Resources::Project.new(config, id: project_id, options: options)
21
23
  elsif segment_id
@@ -43,6 +45,10 @@ module Kentaa
43
45
  data[:segment_id]
44
46
  end
45
47
 
48
+ def company_id
49
+ data[:company_id]
50
+ end
51
+
46
52
  def project_id
47
53
  data[:project_id]
48
54
  end
@@ -68,7 +74,7 @@ module Kentaa
68
74
  end
69
75
 
70
76
  def name
71
- [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
77
+ [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(' ')
72
78
  end
73
79
 
74
80
  def anonymous?
@@ -106,7 +112,7 @@ module Kentaa
106
112
  end
107
113
 
108
114
  def create_resource(attributes)
109
- request.post("/manual-donations", options, attributes)
115
+ request.post('/manual-donations', options, attributes)
110
116
  end
111
117
 
112
118
  def update_resource(attributes)
@@ -37,7 +37,7 @@ module Kentaa
37
37
  end
38
38
 
39
39
  def name
40
- [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
40
+ [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(' ')
41
41
  end
42
42
 
43
43
  def site_id
@@ -69,9 +69,25 @@ module Kentaa
69
69
  end
70
70
 
71
71
  def consent
72
+ Kentaa::Api::Deprecation.warn('#consent is deprecated. Please use #consents instead.', caller)
73
+
72
74
  @consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
73
75
  end
74
76
 
77
+ def consents
78
+ @consents ||= begin
79
+ consents = []
80
+
81
+ if data[:consents]
82
+ data[:consents].each do |consent|
83
+ consents << Kentaa::Api::Resources::Consent.new(consent)
84
+ end
85
+ end
86
+
87
+ consents
88
+ end
89
+ end
90
+
75
91
  private
76
92
 
77
93
  def load_resource
@@ -23,6 +23,10 @@ module Kentaa
23
23
  data[:title]
24
24
  end
25
25
 
26
+ def description
27
+ data[:description]
28
+ end
29
+
26
30
  def performance_type
27
31
  data[:performance_type]
28
32
  end
@@ -39,6 +43,10 @@ module Kentaa
39
43
  data[:unit]
40
44
  end
41
45
 
46
+ def photos(options = {})
47
+ @photos ||= Kentaa::Api::Resources::List.new(config, options.merge(resource_class: Kentaa::Api::Resources::PerformancePhoto, endpoint_path: "/actions/#{action_id}/performances/#{id}/photos"))
48
+ end
49
+
42
50
  private
43
51
 
44
52
  def load_resource
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kentaa
4
+ module Api
5
+ module Resources
6
+ class PerformancePhoto < Resource
7
+ class << self
8
+ def attribute_key
9
+ 'photo'
10
+ end
11
+ end
12
+
13
+ def object_key
14
+ "ActionPerformancePhoto_#{id}"
15
+ end
16
+
17
+ def image_url
18
+ data[:image_url]
19
+ end
20
+
21
+ private
22
+
23
+ def load_resource
24
+ request.get("#{endpoint_path}/#{id}", options)
25
+ end
26
+
27
+ def create_resource(attributes)
28
+ io = attributes.fetch(:io)
29
+ content_type = attributes.fetch(:content_type)
30
+
31
+ request.post(endpoint_path, options, io, content_type: content_type)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -134,9 +134,25 @@ module Kentaa
134
134
  end
135
135
 
136
136
  def consent
137
+ Kentaa::Api::Deprecation.warn('#consent is deprecated. Please use #consents instead.', caller)
138
+
137
139
  @consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
138
140
  end
139
141
 
142
+ def consents
143
+ @consents ||= begin
144
+ consents = []
145
+
146
+ if data[:consents]
147
+ data[:consents].each do |consent|
148
+ consents << Kentaa::Api::Resources::Consent.new(consent)
149
+ end
150
+ end
151
+
152
+ consents
153
+ end
154
+ end
155
+
140
156
  def contact
141
157
  @contact ||= Kentaa::Api::Resources::Contact.new(data[:contact]) if data[:contact]
142
158
  end
@@ -44,7 +44,7 @@ module Kentaa
44
44
  end
45
45
 
46
46
  def name
47
- [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
47
+ [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(' ')
48
48
  end
49
49
 
50
50
  def company
@@ -86,21 +86,21 @@ module Kentaa
86
86
  end
87
87
 
88
88
  def donations
89
- @donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Donation, endpoint_path: "/donations")
89
+ @donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Donation, endpoint_path: '/donations')
90
90
  end
91
91
 
92
92
  def manual_donations
93
- @manual_donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::ManualDonation, endpoint_path: "/manual-donations")
93
+ @manual_donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::ManualDonation, endpoint_path: '/manual-donations')
94
94
  end
95
95
 
96
96
  def newsletter_subscriptions
97
- @newsletter_subscriptions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::NewsletterSubscription, endpoint_path: "/newsletter-subscriptions")
97
+ @newsletter_subscriptions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::NewsletterSubscription, endpoint_path: '/newsletter-subscriptions')
98
98
  end
99
99
 
100
100
  private
101
101
 
102
102
  def load_resource
103
- request.get("/sites/current", options)
103
+ request.get('/sites/current', options)
104
104
  end
105
105
  end
106
106
  end
@@ -31,7 +31,7 @@ module Kentaa
31
31
  end
32
32
 
33
33
  def name
34
- [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
34
+ [first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(' ')
35
35
  end
36
36
 
37
37
  def email
@@ -91,9 +91,29 @@ module Kentaa
91
91
  end
92
92
 
93
93
  def consent
94
+ Kentaa::Api::Deprecation.warn('#consent is deprecated. Please use #consents instead.', caller)
95
+
94
96
  @consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
95
97
  end
96
98
 
99
+ def consents
100
+ @consents ||= begin
101
+ consents = []
102
+
103
+ if data[:consents]
104
+ data[:consents].each do |consent|
105
+ consents << Kentaa::Api::Resources::Consent.new(consent)
106
+ end
107
+ end
108
+
109
+ consents
110
+ end
111
+ end
112
+
113
+ def actions
114
+ @actions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Action, endpoint_path: "/users/#{id}/actions")
115
+ end
116
+
97
117
  private
98
118
 
99
119
  def load_resource
@@ -101,7 +121,7 @@ module Kentaa
101
121
  end
102
122
 
103
123
  def create_resource(attributes)
104
- request.post("/users", options, attributes)
124
+ request.post('/users', options, attributes)
105
125
  end
106
126
 
107
127
  def update_resource(attributes)
@@ -5,7 +5,7 @@ module Kentaa
5
5
  module Resources
6
6
  class Users < List
7
7
  def initialize(config, options = {})
8
- super(config, options.merge(resource_class: Kentaa::Api::Resources::User, endpoint_path: "/users"))
8
+ super(config, options.merge(resource_class: Kentaa::Api::Resources::User, endpoint_path: '/users'))
9
9
  end
10
10
 
11
11
  def auth(attributes, options = {})
@@ -6,7 +6,11 @@ module Kentaa
6
6
  module_function
7
7
 
8
8
  def pluralize(string)
9
- "#{string}s"
9
+ if string[-1] == 'y'
10
+ "#{string.chop}ies"
11
+ else
12
+ "#{string}s"
13
+ end
10
14
  end
11
15
  end
12
16
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- VERSION = "0.6.0"
5
+ VERSION = '0.7.1'
6
6
  end
7
7
  end
data/lib/kentaa/api.rb CHANGED
@@ -1,41 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "api/resources/base"
4
- require_relative "api/resources/error"
5
- require_relative "api/resources/list"
6
- require_relative "api/resources/resource"
3
+ require_relative 'api/resources/base'
4
+ require_relative 'api/resources/error'
5
+ require_relative 'api/resources/list'
6
+ require_relative 'api/resources/resource'
7
7
 
8
- require_relative "api/resources/action"
9
- require_relative "api/resources/activity"
10
- require_relative "api/resources/address"
11
- require_relative "api/resources/banner"
12
- require_relative "api/resources/consent"
13
- require_relative "api/resources/contact"
14
- require_relative "api/resources/donation_form"
15
- require_relative "api/resources/donation"
16
- require_relative "api/resources/location"
17
- require_relative "api/resources/manual_donation"
18
- require_relative "api/resources/newsletter_subscription"
19
- require_relative "api/resources/performance"
20
- require_relative "api/resources/photo"
21
- require_relative "api/resources/project"
22
- require_relative "api/resources/recurring_donor"
23
- require_relative "api/resources/registration_fee"
24
- require_relative "api/resources/reward"
25
- require_relative "api/resources/question"
26
- require_relative "api/resources/segment"
27
- require_relative "api/resources/site"
28
- require_relative "api/resources/sites"
29
- require_relative "api/resources/team"
30
- require_relative "api/resources/user"
31
- require_relative "api/resources/users"
32
- require_relative "api/resources/video"
8
+ require_relative 'api/resources/action'
9
+ require_relative 'api/resources/activity'
10
+ require_relative 'api/resources/address'
11
+ require_relative 'api/resources/banner'
12
+ require_relative 'api/resources/billing'
13
+ require_relative 'api/resources/company'
14
+ require_relative 'api/resources/company_package'
15
+ require_relative 'api/resources/consent'
16
+ require_relative 'api/resources/contact'
17
+ require_relative 'api/resources/donation_form'
18
+ require_relative 'api/resources/donation'
19
+ require_relative 'api/resources/location'
20
+ require_relative 'api/resources/manual_donation'
21
+ require_relative 'api/resources/newsletter_subscription'
22
+ require_relative 'api/resources/performance'
23
+ require_relative 'api/resources/performance_photo'
24
+ require_relative 'api/resources/photo'
25
+ require_relative 'api/resources/project'
26
+ require_relative 'api/resources/recurring_donor'
27
+ require_relative 'api/resources/registration_fee'
28
+ require_relative 'api/resources/reward'
29
+ require_relative 'api/resources/question'
30
+ require_relative 'api/resources/segment'
31
+ require_relative 'api/resources/site'
32
+ require_relative 'api/resources/sites'
33
+ require_relative 'api/resources/team'
34
+ require_relative 'api/resources/user'
35
+ require_relative 'api/resources/users'
36
+ require_relative 'api/resources/video'
33
37
 
34
- require_relative "api/client"
35
- require_relative "api/config"
36
- require_relative "api/exception"
37
- require_relative "api/request"
38
- require_relative "api/response"
39
- require_relative "api/util"
38
+ require_relative 'api/client'
39
+ require_relative 'api/config'
40
+ require_relative 'api/deprecation'
41
+ require_relative 'api/exception'
42
+ require_relative 'api/request'
43
+ require_relative 'api/response'
44
+ require_relative 'api/util'
40
45
 
41
- require_relative "api/version"
46
+ require_relative 'api/version'