kentaa-api 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/kentaa/api.rb +1 -2
- data/lib/kentaa/api/clients/actions.rb +5 -5
- data/lib/kentaa/api/clients/all.rb +1 -1
- data/lib/kentaa/api/clients/base.rb +0 -4
- data/lib/kentaa/api/clients/donations.rb +5 -5
- data/lib/kentaa/api/clients/newsletter_subscriptions.rb +5 -5
- data/lib/kentaa/api/clients/projects.rb +5 -5
- data/lib/kentaa/api/clients/segments.rb +5 -5
- data/lib/kentaa/api/clients/sites.rb +3 -3
- data/lib/kentaa/api/clients/teams.rb +5 -5
- data/lib/kentaa/api/clients/users.rb +5 -5
- data/lib/kentaa/api/exception.rb +14 -0
- data/lib/kentaa/api/finder.rb +9 -0
- data/lib/kentaa/api/request.rb +8 -2
- data/lib/kentaa/api/resources/action.rb +19 -19
- data/lib/kentaa/api/resources/actions.rb +8 -3
- data/lib/kentaa/api/resources/activity.rb +1 -3
- data/lib/kentaa/api/resources/address.rb +1 -3
- data/lib/kentaa/api/resources/banner.rb +1 -3
- data/lib/kentaa/api/resources/base.rb +35 -11
- data/lib/kentaa/api/resources/consent.rb +1 -1
- data/lib/kentaa/api/resources/donation.rb +16 -17
- data/lib/kentaa/api/resources/donations.rb +8 -3
- data/lib/kentaa/api/resources/{pagination.rb → list.rb} +9 -3
- data/lib/kentaa/api/resources/location.rb +1 -1
- data/lib/kentaa/api/resources/newsletter_subscription.rb +11 -10
- data/lib/kentaa/api/resources/newsletter_subscriptions.rb +8 -3
- data/lib/kentaa/api/resources/photo.rb +1 -3
- data/lib/kentaa/api/resources/project.rb +14 -12
- data/lib/kentaa/api/resources/projects.rb +8 -3
- data/lib/kentaa/api/resources/question.rb +1 -3
- data/lib/kentaa/api/resources/registration_fee.rb +1 -1
- data/lib/kentaa/api/resources/resource.rb +12 -3
- data/lib/kentaa/api/resources/reward.rb +1 -3
- data/lib/kentaa/api/resources/segment.rb +8 -4
- data/lib/kentaa/api/resources/segments.rb +8 -3
- data/lib/kentaa/api/resources/site.rb +8 -4
- data/lib/kentaa/api/resources/team.rb +15 -14
- data/lib/kentaa/api/resources/teams.rb +8 -3
- data/lib/kentaa/api/resources/user.rb +8 -4
- data/lib/kentaa/api/resources/users.rb +8 -3
- data/lib/kentaa/api/resources/video.rb +1 -3
- data/lib/kentaa/api/response.rb +2 -2
- data/lib/kentaa/api/version.rb +1 -1
- metadata +4 -6
- data/lib/kentaa/api/resources/status.rb +0 -27
@@ -4,29 +4,53 @@ module Kentaa
|
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
6
|
class Base
|
7
|
-
attr_reader :config, :
|
7
|
+
attr_reader :config, :options
|
8
8
|
|
9
|
-
def initialize(config,
|
9
|
+
def initialize(config, options = {})
|
10
10
|
@config = config
|
11
|
+
@options = options
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
def load
|
15
|
+
@response ||= load_resource(options)
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
else
|
18
|
-
@data = response
|
19
|
-
end
|
17
|
+
self
|
18
|
+
end
|
20
19
|
|
21
|
-
|
20
|
+
def loaded?
|
21
|
+
!@response.nil?
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def attribute_key
|
27
|
-
class_name = self.class.name.split(
|
27
|
+
class_name = self.class.name.split('::').last
|
28
28
|
class_name.gsub(/([^\^])([A-Z])/, '\1_\2').downcase.to_sym
|
29
29
|
end
|
30
|
+
|
31
|
+
def load_resource(_options)
|
32
|
+
raise NotImplementedError
|
33
|
+
end
|
34
|
+
|
35
|
+
def data
|
36
|
+
@data ||= begin
|
37
|
+
load unless loaded?
|
38
|
+
|
39
|
+
@response.body[attribute_key] || {}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def body
|
44
|
+
@body ||= begin
|
45
|
+
load unless loaded?
|
46
|
+
|
47
|
+
@response.body
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def request
|
52
|
+
@request ||= Kentaa::Api::Request.new(config)
|
53
|
+
end
|
30
54
|
end
|
31
55
|
end
|
32
56
|
end
|
@@ -6,29 +6,22 @@ require 'time'
|
|
6
6
|
module Kentaa
|
7
7
|
module Api
|
8
8
|
module Resources
|
9
|
-
class Donation <
|
10
|
-
include Kentaa::Api::Resources::Resource
|
11
|
-
|
9
|
+
class Donation < Resource
|
12
10
|
def object_key
|
13
11
|
"Donation_#{id}"
|
14
12
|
end
|
15
13
|
|
16
14
|
def entity
|
17
15
|
if action_id
|
18
|
-
|
19
|
-
client.get(action_id)
|
16
|
+
Kentaa::Api::Resources::Action.new(config, id: action_id)
|
20
17
|
elsif team_id
|
21
|
-
|
22
|
-
client.get(team_id)
|
18
|
+
Kentaa::Api::Resources::Team.new(config, id: team_id)
|
23
19
|
elsif project_id
|
24
|
-
|
25
|
-
client.get(project_id)
|
20
|
+
Kentaa::Api::Resources::Project.new(config, id: project_id)
|
26
21
|
elsif segment_id
|
27
|
-
|
28
|
-
client.get(segment_id)
|
22
|
+
Kentaa::Api::Resources::Segment.new(config, id: segment_id)
|
29
23
|
else
|
30
|
-
|
31
|
-
client.current
|
24
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id)
|
32
25
|
end
|
33
26
|
end
|
34
27
|
|
@@ -174,7 +167,7 @@ module Kentaa
|
|
174
167
|
|
175
168
|
if data[:questions]
|
176
169
|
data[:questions].each do |question|
|
177
|
-
questions << Kentaa::Api::Resources::Question.new(config, question)
|
170
|
+
questions << Kentaa::Api::Resources::Question.new(config, data: question)
|
178
171
|
end
|
179
172
|
end
|
180
173
|
|
@@ -183,11 +176,11 @@ module Kentaa
|
|
183
176
|
end
|
184
177
|
|
185
178
|
def reward
|
186
|
-
@reward ||= Kentaa::Api::Resources::Reward.new(config, data[:reward]) if data[:reward]
|
179
|
+
@reward ||= Kentaa::Api::Resources::Reward.new(config, data: data[:reward]) if data[:reward]
|
187
180
|
end
|
188
181
|
|
189
182
|
def address
|
190
|
-
@address ||= Kentaa::Api::Resources::Address.new(config, data[:address]) if data[:address]
|
183
|
+
@address ||= Kentaa::Api::Resources::Address.new(config, data: data[:address]) if data[:address]
|
191
184
|
end
|
192
185
|
|
193
186
|
def birthday
|
@@ -203,7 +196,13 @@ module Kentaa
|
|
203
196
|
end
|
204
197
|
|
205
198
|
def consent
|
206
|
-
@consent ||= Kentaa::Api::Resources::Consent.new(config, data[:consent]) if data[:consent]
|
199
|
+
@consent ||= Kentaa::Api::Resources::Consent.new(config, data: data[:consent]) if data[:consent]
|
200
|
+
end
|
201
|
+
|
202
|
+
protected
|
203
|
+
|
204
|
+
def load_resource(options)
|
205
|
+
request.get("/donations/#{id}", options)
|
207
206
|
end
|
208
207
|
end
|
209
208
|
end
|
@@ -3,14 +3,19 @@
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
|
-
class Donations <
|
6
|
+
class Donations < List
|
7
7
|
include Enumerable
|
8
|
-
include Kentaa::Api::Resources::Pagination
|
9
8
|
|
10
9
|
def each(&block)
|
11
10
|
donations.each(&block)
|
12
11
|
end
|
13
12
|
|
13
|
+
protected
|
14
|
+
|
15
|
+
def load_resource(options)
|
16
|
+
request.get("/donations", options)
|
17
|
+
end
|
18
|
+
|
14
19
|
private
|
15
20
|
|
16
21
|
def donations
|
@@ -19,7 +24,7 @@ module Kentaa
|
|
19
24
|
|
20
25
|
if data
|
21
26
|
data.each do |donation|
|
22
|
-
donations << Kentaa::Api::Resources::Donation.new(config, donation)
|
27
|
+
donations << Kentaa::Api::Resources::Donation.new(config, data: donation)
|
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
|
-
|
7
|
-
attr_accessor :body
|
8
|
-
|
6
|
+
class List < Base
|
9
7
|
def links
|
10
8
|
body[:links]
|
11
9
|
end
|
@@ -45,6 +43,14 @@ module Kentaa
|
|
45
43
|
def previous_page?
|
46
44
|
current_page && current_page > 1
|
47
45
|
end
|
46
|
+
|
47
|
+
def next
|
48
|
+
self.class.new(config, options.merge(page: next_page)) if next_page?
|
49
|
+
end
|
50
|
+
|
51
|
+
def previous
|
52
|
+
self.class.new(config, options.merge(page: previous_page)) if previous_page?
|
53
|
+
end
|
48
54
|
end
|
49
55
|
end
|
50
56
|
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
|
|
@@ -64,7 +59,13 @@ module Kentaa
|
|
64
59
|
end
|
65
60
|
|
66
61
|
def consent
|
67
|
-
@consent ||= Kentaa::Api::Resources::Consent.new(config, data[:consent]) if data[:consent]
|
62
|
+
@consent ||= Kentaa::Api::Resources::Consent.new(config, data: data[:consent]) if data[:consent]
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
|
67
|
+
def load_resource(options)
|
68
|
+
request.get("/newsletter-subscriptions/#{id}", options)
|
68
69
|
end
|
69
70
|
end
|
70
71
|
end
|
@@ -3,14 +3,19 @@
|
|
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)
|
12
11
|
end
|
13
12
|
|
13
|
+
protected
|
14
|
+
|
15
|
+
def load_resource(options)
|
16
|
+
request.get("/newsletter-subscriptions", options)
|
17
|
+
end
|
18
|
+
|
14
19
|
private
|
15
20
|
|
16
21
|
def newsletter_subscriptions
|
@@ -19,7 +24,7 @@ module Kentaa
|
|
19
24
|
|
20
25
|
if data
|
21
26
|
data.each do |newsletter_subscription|
|
22
|
-
newsletter_subscriptions << Kentaa::Api::Resources::NewsletterSubscription.new(config, newsletter_subscription)
|
27
|
+
newsletter_subscriptions << Kentaa::Api::Resources::NewsletterSubscription.new(config, data: newsletter_subscription)
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
@@ -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(config, data[:location])
|
87
|
+
@location ||= Kentaa::Api::Resources::Location.new(config, data: 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(config, photo)
|
96
|
+
photos << Kentaa::Api::Resources::Photo.new(config, data: 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(config, video)
|
110
|
+
videos << Kentaa::Api::Resources::Video.new(config, data: 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(config, question)
|
124
|
+
questions << Kentaa::Api::Resources::Question.new(config, data: question)
|
129
125
|
end
|
130
126
|
end
|
131
127
|
|
@@ -134,12 +130,18 @@ module Kentaa
|
|
134
130
|
end
|
135
131
|
|
136
132
|
def consent
|
137
|
-
@consent ||= Kentaa::Api::Resources::Consent.new(config, data[:consent]) if data[:consent]
|
133
|
+
@consent ||= Kentaa::Api::Resources::Consent.new(config, data: data[:consent]) if data[:consent]
|
138
134
|
end
|
139
135
|
|
140
136
|
def external_reference
|
141
137
|
data[:external_reference]
|
142
138
|
end
|
139
|
+
|
140
|
+
protected
|
141
|
+
|
142
|
+
def load_resource(options)
|
143
|
+
request.get("/projects/#{id}", options)
|
144
|
+
end
|
143
145
|
end
|
144
146
|
end
|
145
147
|
end
|
@@ -3,14 +3,19 @@
|
|
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)
|
12
11
|
end
|
13
12
|
|
13
|
+
protected
|
14
|
+
|
15
|
+
def load_resource(options)
|
16
|
+
request.get("/projects", options)
|
17
|
+
end
|
18
|
+
|
14
19
|
private
|
15
20
|
|
16
21
|
def projects
|
@@ -19,7 +24,7 @@ module Kentaa
|
|
19
24
|
|
20
25
|
if data
|
21
26
|
data.each do |project|
|
22
|
-
projects << Kentaa::Api::Resources::Project.new(config, project)
|
27
|
+
projects << Kentaa::Api::Resources::Project.new(config, data: project)
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|