kentaa-api 0.2.0 → 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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +14 -3
- data/.travis.yml +5 -4
- data/Gemfile +3 -2
- data/Gemfile.lock +19 -14
- data/README.md +12 -12
- data/kentaa-api.gemspec +2 -2
- data/lib/kentaa/api.rb +6 -4
- data/lib/kentaa/api/client.rb +4 -0
- data/lib/kentaa/api/clients/actions.rb +19 -6
- data/lib/kentaa/api/clients/base.rb +0 -4
- data/lib/kentaa/api/clients/donations.rb +9 -6
- data/lib/kentaa/api/clients/manual_donations.rb +39 -0
- data/lib/kentaa/api/clients/newsletter_subscriptions.rb +9 -6
- data/lib/kentaa/api/clients/projects.rb +9 -6
- data/lib/kentaa/api/clients/segments.rb +9 -6
- data/lib/kentaa/api/clients/sites.rb +3 -3
- data/lib/kentaa/api/clients/teams.rb +9 -6
- data/lib/kentaa/api/clients/users.rb +19 -6
- data/lib/kentaa/api/exception.rb +18 -0
- data/lib/kentaa/api/finder.rb +9 -0
- data/lib/kentaa/api/request.rb +46 -5
- data/lib/kentaa/api/resources/action.rb +36 -20
- data/lib/kentaa/api/resources/actions.rb +11 -3
- data/lib/kentaa/api/resources/activity.rb +10 -2
- data/lib/kentaa/api/resources/address.rb +6 -2
- data/lib/kentaa/api/resources/banner.rb +20 -2
- data/lib/kentaa/api/resources/base.rb +35 -11
- data/lib/kentaa/api/resources/consent.rb +7 -1
- data/lib/kentaa/api/resources/contact.rb +83 -0
- data/lib/kentaa/api/resources/donation.rb +25 -18
- data/lib/kentaa/api/resources/donations.rb +6 -3
- data/lib/kentaa/api/resources/error.rb +23 -0
- data/lib/kentaa/api/resources/{pagination.rb → list.rb} +26 -3
- data/lib/kentaa/api/resources/location.rb +7 -1
- data/lib/kentaa/api/resources/manual_donation.rb +112 -0
- data/lib/kentaa/api/resources/manual_donations.rb +40 -0
- data/lib/kentaa/api/resources/newsletter_subscription.rb +12 -11
- data/lib/kentaa/api/resources/newsletter_subscriptions.rb +6 -3
- data/lib/kentaa/api/resources/photo.rb +20 -2
- data/lib/kentaa/api/resources/project.rb +26 -12
- data/lib/kentaa/api/resources/projects.rb +6 -3
- data/lib/kentaa/api/resources/question.rb +10 -2
- data/lib/kentaa/api/resources/registration_fee.rb +1 -1
- data/lib/kentaa/api/resources/resource.rb +50 -3
- data/lib/kentaa/api/resources/reward.rb +10 -2
- data/lib/kentaa/api/resources/segment.rb +16 -4
- data/lib/kentaa/api/resources/segments.rb +6 -3
- data/lib/kentaa/api/resources/site.rb +16 -4
- data/lib/kentaa/api/resources/team.rb +23 -14
- data/lib/kentaa/api/resources/teams.rb +6 -3
- data/lib/kentaa/api/resources/user.rb +17 -5
- data/lib/kentaa/api/resources/users.rb +11 -3
- data/lib/kentaa/api/resources/video.rb +20 -2
- data/lib/kentaa/api/response.rb +21 -3
- data/lib/kentaa/api/version.rb +1 -1
- metadata +16 -14
- data/lib/kentaa/api/clients/all.rb +0 -26
- data/lib/kentaa/api/resources/status.rb +0 -27
@@ -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
|
@@ -3,23 +3,18 @@
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
|
-
class NewsletterSubscription <
|
7
|
-
include Kentaa::Api::Resources::Resource
|
8
|
-
|
6
|
+
class NewsletterSubscription < Resource
|
9
7
|
def object_key
|
10
8
|
"NewsletterSubscription_#{id}"
|
11
9
|
end
|
12
10
|
|
13
11
|
def entity
|
14
12
|
if project_id
|
15
|
-
|
16
|
-
client.get(project_id)
|
13
|
+
Kentaa::Api::Resources::Project.new(config, id: project_id)
|
17
14
|
elsif segment_id
|
18
|
-
|
19
|
-
client.get(segment_id)
|
15
|
+
Kentaa::Api::Resources::Segment.new(config, id: segment_id)
|
20
16
|
else
|
21
|
-
|
22
|
-
client.current
|
17
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id)
|
23
18
|
end
|
24
19
|
end
|
25
20
|
|
@@ -36,7 +31,7 @@ module Kentaa
|
|
36
31
|
end
|
37
32
|
|
38
33
|
def name
|
39
|
-
[first_name, infix, last_name].
|
34
|
+
[first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
|
40
35
|
end
|
41
36
|
|
42
37
|
def site_id
|
@@ -64,7 +59,13 @@ module Kentaa
|
|
64
59
|
end
|
65
60
|
|
66
61
|
def consent
|
67
|
-
@consent ||= Kentaa::Api::Resources::Consent.new(
|
62
|
+
@consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def load_resource
|
68
|
+
request.get("/newsletter-subscriptions/#{id}", options)
|
68
69
|
end
|
69
70
|
end
|
70
71
|
end
|
@@ -3,9 +3,8 @@
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
|
-
class NewsletterSubscriptions <
|
6
|
+
class NewsletterSubscriptions < List
|
7
7
|
include Enumerable
|
8
|
-
include Kentaa::Api::Resources::Pagination
|
9
8
|
|
10
9
|
def each(&block)
|
11
10
|
newsletter_subscriptions.each(&block)
|
@@ -13,13 +12,17 @@ module Kentaa
|
|
13
12
|
|
14
13
|
private
|
15
14
|
|
15
|
+
def load_resource
|
16
|
+
request.get("/newsletter-subscriptions", options)
|
17
|
+
end
|
18
|
+
|
16
19
|
def newsletter_subscriptions
|
17
20
|
@newsletter_subscriptions ||= begin
|
18
21
|
newsletter_subscriptions = []
|
19
22
|
|
20
23
|
if data
|
21
24
|
data.each do |newsletter_subscription|
|
22
|
-
newsletter_subscriptions << Kentaa::Api::Resources::NewsletterSubscription.new(config, newsletter_subscription)
|
25
|
+
newsletter_subscriptions << Kentaa::Api::Resources::NewsletterSubscription.new(config, data: newsletter_subscription)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
@@ -1,10 +1,28 @@
|
|
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 Photo
|
7
|
-
|
8
|
+
class Photo
|
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
|
8
26
|
|
9
27
|
def url
|
10
28
|
data[:url]
|
@@ -6,20 +6,16 @@ require 'time'
|
|
6
6
|
module Kentaa
|
7
7
|
module Api
|
8
8
|
module Resources
|
9
|
-
class Project <
|
10
|
-
include Kentaa::Api::Resources::Resource
|
11
|
-
|
9
|
+
class Project < Resource
|
12
10
|
def object_key
|
13
11
|
"Project_#{id}"
|
14
12
|
end
|
15
13
|
|
16
14
|
def parent
|
17
15
|
if segment_id
|
18
|
-
|
19
|
-
client.get(segment_id)
|
16
|
+
Kentaa::Api::Resources::Segment.new(config, id: segment_id)
|
20
17
|
else
|
21
|
-
|
22
|
-
client.current
|
18
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id)
|
23
19
|
end
|
24
20
|
end
|
25
21
|
|
@@ -88,7 +84,7 @@ module Kentaa
|
|
88
84
|
end
|
89
85
|
|
90
86
|
def location
|
91
|
-
@location ||= Kentaa::Api::Resources::Location.new(
|
87
|
+
@location ||= Kentaa::Api::Resources::Location.new(data[:location]) if data[:location]
|
92
88
|
end
|
93
89
|
|
94
90
|
def photos
|
@@ -97,7 +93,7 @@ module Kentaa
|
|
97
93
|
|
98
94
|
if data[:photos]
|
99
95
|
data[:photos].each do |photo|
|
100
|
-
photos << Kentaa::Api::Resources::Photo.new(
|
96
|
+
photos << Kentaa::Api::Resources::Photo.new(photo)
|
101
97
|
end
|
102
98
|
end
|
103
99
|
|
@@ -111,7 +107,7 @@ module Kentaa
|
|
111
107
|
|
112
108
|
if data[:videos]
|
113
109
|
data[:videos].each do |video|
|
114
|
-
videos << Kentaa::Api::Resources::Video.new(
|
110
|
+
videos << Kentaa::Api::Resources::Video.new(video)
|
115
111
|
end
|
116
112
|
end
|
117
113
|
|
@@ -125,7 +121,7 @@ module Kentaa
|
|
125
121
|
|
126
122
|
if data[:questions]
|
127
123
|
data[:questions].each do |question|
|
128
|
-
questions << Kentaa::Api::Resources::Question.new(
|
124
|
+
questions << Kentaa::Api::Resources::Question.new(question)
|
129
125
|
end
|
130
126
|
end
|
131
127
|
|
@@ -134,12 +130,30 @@ module Kentaa
|
|
134
130
|
end
|
135
131
|
|
136
132
|
def consent
|
137
|
-
@consent ||= Kentaa::Api::Resources::Consent.new(
|
133
|
+
@consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
|
134
|
+
end
|
135
|
+
|
136
|
+
def contact
|
137
|
+
@contact ||= Kentaa::Api::Resources::Contact.new(data[:contact]) if data[:contact]
|
138
138
|
end
|
139
139
|
|
140
140
|
def external_reference
|
141
141
|
data[:external_reference]
|
142
142
|
end
|
143
|
+
|
144
|
+
def donations
|
145
|
+
@donations ||= Kentaa::Api::Resources::Donations.new(config, project_id: id)
|
146
|
+
end
|
147
|
+
|
148
|
+
def manual_donations
|
149
|
+
@manual_donations ||= Kentaa::Api::Resources::ManualDonations.new(config, project_id: id)
|
150
|
+
end
|
151
|
+
|
152
|
+
private
|
153
|
+
|
154
|
+
def load_resource
|
155
|
+
request.get("/projects/#{id}", options)
|
156
|
+
end
|
143
157
|
end
|
144
158
|
end
|
145
159
|
end
|
@@ -3,9 +3,8 @@
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
|
-
class Projects <
|
6
|
+
class Projects < List
|
7
7
|
include Enumerable
|
8
|
-
include Kentaa::Api::Resources::Pagination
|
9
8
|
|
10
9
|
def each(&block)
|
11
10
|
projects.each(&block)
|
@@ -13,13 +12,17 @@ module Kentaa
|
|
13
12
|
|
14
13
|
private
|
15
14
|
|
15
|
+
def load_resource
|
16
|
+
request.get("/projects", options)
|
17
|
+
end
|
18
|
+
|
16
19
|
def projects
|
17
20
|
@projects ||= begin
|
18
21
|
projects = []
|
19
22
|
|
20
23
|
if data
|
21
24
|
data.each do |project|
|
22
|
-
projects << Kentaa::Api::Resources::Project.new(config, project)
|
25
|
+
projects << Kentaa::Api::Resources::Project.new(config, data: project)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
@@ -3,8 +3,16 @@
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
|
-
class Question
|
7
|
-
|
6
|
+
class Question
|
7
|
+
attr_reader :data
|
8
|
+
|
9
|
+
def initialize(data)
|
10
|
+
@data = data
|
11
|
+
end
|
12
|
+
|
13
|
+
def id
|
14
|
+
data[:id]
|
15
|
+
end
|
8
16
|
|
9
17
|
def question
|
10
18
|
data[:question]
|
@@ -5,9 +5,42 @@ require 'time'
|
|
5
5
|
module Kentaa
|
6
6
|
module Api
|
7
7
|
module Resources
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
class Resource < Base
|
9
|
+
attr_accessor :id
|
10
|
+
|
11
|
+
def initialize(config, options = {})
|
12
|
+
super(config, options)
|
13
|
+
|
14
|
+
if options.key?(:data)
|
15
|
+
@data = options.delete(:data) || {}
|
16
|
+
@id = @data.fetch(:id) if @data.key?(:id)
|
17
|
+
elsif options.key?(:id)
|
18
|
+
@id = options.delete(:id)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def load
|
23
|
+
super
|
24
|
+
@id = data.fetch(:id) if data.key?(:id)
|
25
|
+
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def save(attributes)
|
30
|
+
if id
|
31
|
+
@response = update_resource(attributes)
|
32
|
+
else
|
33
|
+
@response = create_resource(attributes)
|
34
|
+
@id = data.fetch(:id) if data.key?(:id)
|
35
|
+
end
|
36
|
+
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete
|
41
|
+
delete_resource
|
42
|
+
|
43
|
+
self
|
11
44
|
end
|
12
45
|
|
13
46
|
def created_at
|
@@ -17,6 +50,20 @@ module Kentaa
|
|
17
50
|
def updated_at
|
18
51
|
Time.parse(data[:updated_at]) if data[:updated_at]
|
19
52
|
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def create_resource
|
57
|
+
raise NotImplementedError
|
58
|
+
end
|
59
|
+
|
60
|
+
def update_resource
|
61
|
+
raise NotImplementedError
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete_resource
|
65
|
+
raise NotImplementedError
|
66
|
+
end
|
20
67
|
end
|
21
68
|
end
|
22
69
|
end
|
@@ -3,8 +3,16 @@
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
|
-
class Reward
|
7
|
-
|
6
|
+
class Reward
|
7
|
+
attr_reader :data
|
8
|
+
|
9
|
+
def initialize(data)
|
10
|
+
@data = data
|
11
|
+
end
|
12
|
+
|
13
|
+
def id
|
14
|
+
data[:id]
|
15
|
+
end
|
8
16
|
|
9
17
|
def type
|
10
18
|
data[:type]
|
@@ -6,9 +6,7 @@ require 'time'
|
|
6
6
|
module Kentaa
|
7
7
|
module Api
|
8
8
|
module Resources
|
9
|
-
class Segment <
|
10
|
-
include Kentaa::Api::Resources::Resource
|
11
|
-
|
9
|
+
class Segment < Resource
|
12
10
|
def object_key
|
13
11
|
"Segment_#{id}"
|
14
12
|
end
|
@@ -63,7 +61,7 @@ module Kentaa
|
|
63
61
|
|
64
62
|
if data[:banners]
|
65
63
|
data[:banners].each do |banner|
|
66
|
-
banners << Kentaa::Api::Resources::Banner.new(
|
64
|
+
banners << Kentaa::Api::Resources::Banner.new(banner)
|
67
65
|
end
|
68
66
|
end
|
69
67
|
|
@@ -74,6 +72,20 @@ module Kentaa
|
|
74
72
|
def external_reference
|
75
73
|
data[:external_reference]
|
76
74
|
end
|
75
|
+
|
76
|
+
def donations
|
77
|
+
@donations ||= Kentaa::Api::Resources::Donations.new(config, segment_id: id)
|
78
|
+
end
|
79
|
+
|
80
|
+
def manual_donations
|
81
|
+
@manual_donations ||= Kentaa::Api::Resources::ManualDonations.new(config, segment_id: id)
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def load_resource
|
87
|
+
request.get("/segments/#{id}", options)
|
88
|
+
end
|
77
89
|
end
|
78
90
|
end
|
79
91
|
end
|
@@ -3,9 +3,8 @@
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
|
-
class Segments <
|
6
|
+
class Segments < List
|
7
7
|
include Enumerable
|
8
|
-
include Kentaa::Api::Resources::Pagination
|
9
8
|
|
10
9
|
def each(&block)
|
11
10
|
segments.each(&block)
|
@@ -13,13 +12,17 @@ module Kentaa
|
|
13
12
|
|
14
13
|
private
|
15
14
|
|
15
|
+
def load_resource
|
16
|
+
request.get("/segments", options)
|
17
|
+
end
|
18
|
+
|
16
19
|
def segments
|
17
20
|
@segments ||= begin
|
18
21
|
segments = []
|
19
22
|
|
20
23
|
if data
|
21
24
|
data.each do |segment|
|
22
|
-
segments << Kentaa::Api::Resources::Segment.new(config, segment)
|
25
|
+
segments << Kentaa::Api::Resources::Segment.new(config, data: segment)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|