kentaa-api 0.2.1 → 0.5.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 +22 -4
- data/.travis.yml +5 -5
- data/Gemfile +4 -2
- data/Gemfile.lock +33 -20
- data/README.md +320 -66
- data/kentaa-api.gemspec +3 -3
- data/lib/kentaa/api.rb +12 -4
- data/lib/kentaa/api/client.rb +12 -0
- data/lib/kentaa/api/clients/actions.rb +19 -6
- data/lib/kentaa/api/clients/base.rb +0 -4
- data/lib/kentaa/api/clients/donation_forms.rb +24 -0
- 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/recurring_donors.rb +24 -0
- 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 +24 -6
- data/lib/kentaa/api/config.rb +4 -0
- data/lib/kentaa/api/exception.rb +21 -0
- data/lib/kentaa/api/finder.rb +9 -0
- data/lib/kentaa/api/request.rb +55 -5
- data/lib/kentaa/api/resources/action.rb +40 -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 +35 -18
- data/lib/kentaa/api/resources/donation_form.rb +100 -0
- data/lib/kentaa/api/resources/donation_forms.rb +35 -0
- 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 +122 -0
- data/lib/kentaa/api/resources/manual_donations.rb +40 -0
- data/lib/kentaa/api/resources/newsletter_subscription.rb +21 -10
- 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 +34 -12
- data/lib/kentaa/api/resources/projects.rb +6 -3
- data/lib/kentaa/api/resources/question.rb +18 -2
- data/lib/kentaa/api/resources/recurring_donor.rb +110 -0
- data/lib/kentaa/api/resources/recurring_donors.rb +35 -0
- 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 +28 -4
- data/lib/kentaa/api/resources/segments.rb +6 -3
- data/lib/kentaa/api/resources/site.rb +20 -4
- data/lib/kentaa/api/resources/team.rb +27 -14
- data/lib/kentaa/api/resources/teams.rb +6 -3
- data/lib/kentaa/api/resources/user.rb +27 -5
- data/lib/kentaa/api/resources/users.rb +16 -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 +24 -16
- data/lib/kentaa/api/clients/all.rb +0 -26
- data/lib/kentaa/api/resources/status.rb +0 -27
data/lib/kentaa/api/finder.rb
CHANGED
@@ -16,6 +16,12 @@ module Kentaa
|
|
16
16
|
when "Action"
|
17
17
|
client = Kentaa::Api::Clients::Actions.new(config)
|
18
18
|
client.get(id)
|
19
|
+
when "Donation"
|
20
|
+
client = Kentaa::Api::Clients::Donations.new(config)
|
21
|
+
client.get(id)
|
22
|
+
when "NewsletterSubscription"
|
23
|
+
client = Kentaa::Api::Clients::NewsletterSubscriptions.new(config)
|
24
|
+
client.get(id)
|
19
25
|
when "Project"
|
20
26
|
client = Kentaa::Api::Clients::Projects.new(config)
|
21
27
|
client.get(id)
|
@@ -28,6 +34,9 @@ module Kentaa
|
|
28
34
|
when "Team"
|
29
35
|
client = Kentaa::Api::Clients::Teams.new(config)
|
30
36
|
client.get(id)
|
37
|
+
when "User"
|
38
|
+
client = Kentaa::Api::Clients::Users.new(config)
|
39
|
+
client.get(id)
|
31
40
|
end
|
32
41
|
end
|
33
42
|
end
|
data/lib/kentaa/api/request.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'logger'
|
3
4
|
require 'net/http'
|
4
5
|
require 'uri'
|
5
6
|
|
@@ -13,16 +14,55 @@ module Kentaa
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def get(path, params = {})
|
17
|
+
request(:get, path, params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(path, params = {}, body = {})
|
21
|
+
request(:post, path, params, body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def patch(path, params = {}, body = {})
|
25
|
+
request(:patch, path, params, body)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete(path, params = {})
|
29
|
+
request(:delete, path, params)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def request(http_method, path, params = {}, body = {})
|
16
35
|
uri = URI.parse(File.join(config.api_url, path))
|
17
36
|
uri.query = URI.encode_www_form(params) unless params.empty?
|
18
37
|
|
19
|
-
|
38
|
+
logger.debug("[Kentaa-API] Request: #{http_method.upcase} #{uri}") if config.debug?
|
39
|
+
|
40
|
+
case http_method
|
41
|
+
when :get
|
42
|
+
request = Net::HTTP::Get.new(uri)
|
43
|
+
when :post
|
44
|
+
request = Net::HTTP::Post.new(uri)
|
45
|
+
request.body = body.to_json
|
46
|
+
when :patch
|
47
|
+
request = Net::HTTP::Patch.new(uri)
|
48
|
+
request.body = body.to_json
|
49
|
+
when :delete
|
50
|
+
request = Net::HTTP::Delete.new(uri)
|
51
|
+
else
|
52
|
+
raise Kentaa::Api::Exception, "Invalid HTTP method: #{http_method}"
|
53
|
+
end
|
54
|
+
|
55
|
+
request["Accept"] = "application/json"
|
56
|
+
request["Content-Type"] = "application/json"
|
20
57
|
request["X-Api-Key"] = config.api_key
|
58
|
+
request["User-Agent"] = "Ruby kentaa-api/#{Kentaa::Api::VERSION}"
|
59
|
+
|
60
|
+
client = Net::HTTP.new(uri.hostname, uri.port)
|
61
|
+
client.use_ssl = uri.scheme == "https"
|
62
|
+
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
21
63
|
|
22
64
|
begin
|
23
|
-
response =
|
24
|
-
http.request(request)
|
25
|
-
end
|
65
|
+
response = Kentaa::Api::Response.new(client.request(request))
|
26
66
|
# Try to catch some common exceptions Net::HTTP might raise.
|
27
67
|
rescue Errno::ETIMEDOUT, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EHOSTUNREACH,
|
28
68
|
IOError, SocketError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::OpenTimeout,
|
@@ -30,7 +70,17 @@ module Kentaa
|
|
30
70
|
raise Kentaa::Api::Exception, e.message
|
31
71
|
end
|
32
72
|
|
33
|
-
Kentaa
|
73
|
+
logger.debug("[Kentaa-API] Response: #{response.http_code}, body: #{response.body}") if config.debug?
|
74
|
+
|
75
|
+
if response.error?
|
76
|
+
raise Kentaa::Api::RequestError, response
|
77
|
+
end
|
78
|
+
|
79
|
+
response
|
80
|
+
end
|
81
|
+
|
82
|
+
def logger
|
83
|
+
@logger ||= Logger.new($stdout)
|
34
84
|
end
|
35
85
|
end
|
36
86
|
end
|
@@ -6,29 +6,27 @@ require 'time'
|
|
6
6
|
module Kentaa
|
7
7
|
module Api
|
8
8
|
module Resources
|
9
|
-
class Action <
|
10
|
-
include Kentaa::Api::Resources::Resource
|
11
|
-
|
9
|
+
class Action < Resource
|
12
10
|
def object_key
|
13
11
|
"Action_#{id}"
|
14
12
|
end
|
15
13
|
|
16
14
|
def parent
|
17
15
|
if team_id
|
18
|
-
|
19
|
-
client.get(team_id)
|
16
|
+
Kentaa::Api::Resources::Team.new(config, id: team_id, options: options)
|
20
17
|
elsif project_id
|
21
|
-
|
22
|
-
client.get(project_id)
|
18
|
+
Kentaa::Api::Resources::Project.new(config, id: project_id, options: options)
|
23
19
|
elsif segment_id
|
24
|
-
|
25
|
-
client.get(segment_id)
|
20
|
+
Kentaa::Api::Resources::Segment.new(config, id: segment_id, options: options)
|
26
21
|
else
|
27
|
-
|
28
|
-
client.current
|
22
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
|
29
23
|
end
|
30
24
|
end
|
31
25
|
|
26
|
+
def site
|
27
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
|
28
|
+
end
|
29
|
+
|
32
30
|
def slug
|
33
31
|
data[:slug]
|
34
32
|
end
|
@@ -50,11 +48,11 @@ module Kentaa
|
|
50
48
|
end
|
51
49
|
|
52
50
|
def owner
|
53
|
-
@owner ||= Kentaa::Api::Resources::User.new(config, data[:owner])
|
51
|
+
@owner ||= Kentaa::Api::Resources::User.new(config, data: data[:owner], options: options)
|
54
52
|
end
|
55
53
|
|
56
54
|
def team_captain?
|
57
|
-
data
|
55
|
+
data.fetch(:team_captain, false)
|
58
56
|
end
|
59
57
|
|
60
58
|
def first_name
|
@@ -126,7 +124,7 @@ module Kentaa
|
|
126
124
|
end
|
127
125
|
|
128
126
|
def activity
|
129
|
-
@activity ||= Kentaa::Api::Resources::Activity.new(
|
127
|
+
@activity ||= Kentaa::Api::Resources::Activity.new(data[:activity])
|
130
128
|
end
|
131
129
|
|
132
130
|
def previous_participations
|
@@ -142,11 +140,11 @@ module Kentaa
|
|
142
140
|
end
|
143
141
|
|
144
142
|
def registration_fee
|
145
|
-
@registration_fee ||= Kentaa::Api::Resources::RegistrationFee.new(
|
143
|
+
@registration_fee ||= Kentaa::Api::Resources::RegistrationFee.new(data[:registration_fee])
|
146
144
|
end
|
147
145
|
|
148
146
|
def location
|
149
|
-
@location ||= Kentaa::Api::Resources::Location.new(
|
147
|
+
@location ||= Kentaa::Api::Resources::Location.new(data[:location])
|
150
148
|
end
|
151
149
|
|
152
150
|
def photos
|
@@ -155,7 +153,7 @@ module Kentaa
|
|
155
153
|
|
156
154
|
if data[:photos]
|
157
155
|
data[:photos].each do |photo|
|
158
|
-
photos << Kentaa::Api::Resources::Photo.new(
|
156
|
+
photos << Kentaa::Api::Resources::Photo.new(photo)
|
159
157
|
end
|
160
158
|
end
|
161
159
|
|
@@ -169,7 +167,7 @@ module Kentaa
|
|
169
167
|
|
170
168
|
if data[:videos]
|
171
169
|
data[:videos].each do |video|
|
172
|
-
videos << Kentaa::Api::Resources::Video.new(
|
170
|
+
videos << Kentaa::Api::Resources::Video.new(video)
|
173
171
|
end
|
174
172
|
end
|
175
173
|
|
@@ -183,7 +181,7 @@ module Kentaa
|
|
183
181
|
|
184
182
|
if data[:questions]
|
185
183
|
data[:questions].each do |question|
|
186
|
-
questions << Kentaa::Api::Resources::Question.new(
|
184
|
+
questions << Kentaa::Api::Resources::Question.new(question)
|
187
185
|
end
|
188
186
|
end
|
189
187
|
|
@@ -192,12 +190,34 @@ module Kentaa
|
|
192
190
|
end
|
193
191
|
|
194
192
|
def consent
|
195
|
-
@consent ||= Kentaa::Api::Resources::Consent.new(
|
193
|
+
@consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
|
196
194
|
end
|
197
195
|
|
198
196
|
def external_reference
|
199
197
|
data[:external_reference]
|
200
198
|
end
|
199
|
+
|
200
|
+
def donations
|
201
|
+
@donations ||= Kentaa::Api::Resources::Donations.new(config, action_id: id)
|
202
|
+
end
|
203
|
+
|
204
|
+
def manual_donations
|
205
|
+
@manual_donations ||= Kentaa::Api::Resources::ManualDonations.new(config, action_id: id)
|
206
|
+
end
|
207
|
+
|
208
|
+
private
|
209
|
+
|
210
|
+
def load_resource
|
211
|
+
request.get("/actions/#{id}", options)
|
212
|
+
end
|
213
|
+
|
214
|
+
def create_resource(attributes)
|
215
|
+
request.post("/actions", options, attributes)
|
216
|
+
end
|
217
|
+
|
218
|
+
def update_resource(attributes)
|
219
|
+
request.patch("/actions/#{id}", options, attributes)
|
220
|
+
end
|
201
221
|
end
|
202
222
|
end
|
203
223
|
end
|
@@ -3,23 +3,31 @@
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
|
-
class Actions <
|
6
|
+
class Actions < List
|
7
7
|
include Enumerable
|
8
|
-
include Kentaa::Api::Resources::Pagination
|
9
8
|
|
10
9
|
def each(&block)
|
11
10
|
actions.each(&block)
|
12
11
|
end
|
13
12
|
|
13
|
+
def create(attributes = {})
|
14
|
+
action = Kentaa::Api::Resources::Action.new(config, options: options)
|
15
|
+
action.save(attributes)
|
16
|
+
end
|
17
|
+
|
14
18
|
private
|
15
19
|
|
20
|
+
def load_resource
|
21
|
+
request.get("/actions", options)
|
22
|
+
end
|
23
|
+
|
16
24
|
def actions
|
17
25
|
@actions ||= begin
|
18
26
|
actions = []
|
19
27
|
|
20
28
|
if data
|
21
29
|
data.each do |action|
|
22
|
-
actions << Kentaa::Api::Resources::Action.new(config, action)
|
30
|
+
actions << Kentaa::Api::Resources::Action.new(config, data: action, options: options)
|
23
31
|
end
|
24
32
|
end
|
25
33
|
|
@@ -3,8 +3,16 @@
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
|
-
class Activity
|
7
|
-
|
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
|
8
16
|
|
9
17
|
def name
|
10
18
|
data[:name]
|
@@ -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 Banner
|
7
|
-
|
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
|
8
26
|
|
9
27
|
def url
|
10
28
|
data[:url]
|
@@ -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
|
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
|
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
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kentaa
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Contact
|
7
|
+
attr_reader :data
|
8
|
+
|
9
|
+
def initialize(data)
|
10
|
+
@data = data
|
11
|
+
end
|
12
|
+
|
13
|
+
def first_name
|
14
|
+
data[:first_name]
|
15
|
+
end
|
16
|
+
|
17
|
+
def infix
|
18
|
+
data[:infix]
|
19
|
+
end
|
20
|
+
|
21
|
+
def last_name
|
22
|
+
data[:last_name]
|
23
|
+
end
|
24
|
+
|
25
|
+
def name
|
26
|
+
[first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
|
27
|
+
end
|
28
|
+
|
29
|
+
def email
|
30
|
+
data[:email]
|
31
|
+
end
|
32
|
+
|
33
|
+
def avatar_url
|
34
|
+
data[:avatar_url]
|
35
|
+
end
|
36
|
+
|
37
|
+
def address
|
38
|
+
data[:address]
|
39
|
+
end
|
40
|
+
|
41
|
+
def address2
|
42
|
+
data[:address2]
|
43
|
+
end
|
44
|
+
|
45
|
+
def street
|
46
|
+
data[:street]
|
47
|
+
end
|
48
|
+
|
49
|
+
def house_number
|
50
|
+
data[:house_number]
|
51
|
+
end
|
52
|
+
|
53
|
+
def house_number_addition
|
54
|
+
data[:house_number_addition]
|
55
|
+
end
|
56
|
+
|
57
|
+
def zipcode
|
58
|
+
data[:zipcode]
|
59
|
+
end
|
60
|
+
|
61
|
+
def city
|
62
|
+
data[:city]
|
63
|
+
end
|
64
|
+
|
65
|
+
def country
|
66
|
+
data[:country]
|
67
|
+
end
|
68
|
+
|
69
|
+
def phone
|
70
|
+
data[:phone]
|
71
|
+
end
|
72
|
+
|
73
|
+
def birthday
|
74
|
+
Date.parse(data[:birthday]) if data[:birthday]
|
75
|
+
end
|
76
|
+
|
77
|
+
def gender
|
78
|
+
data[:gender]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|