kentaa-api 0.1.1 → 0.2.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 +13 -12
- data/lib/kentaa/api.rb +42 -39
- data/lib/kentaa/api/client.rb +10 -10
- data/lib/kentaa/api/{requests → clients}/actions.rb +4 -4
- data/lib/kentaa/api/{requests → clients}/all.rb +1 -1
- data/lib/kentaa/api/clients/base.rb +19 -0
- data/lib/kentaa/api/{requests → clients}/donations.rb +4 -4
- data/lib/kentaa/api/{requests → clients}/newsletter_subscriptions.rb +4 -4
- data/lib/kentaa/api/{requests → clients}/projects.rb +4 -4
- data/lib/kentaa/api/{requests → clients}/segments.rb +4 -4
- data/lib/kentaa/api/{requests → clients}/sites.rb +2 -2
- data/lib/kentaa/api/{requests → clients}/teams.rb +4 -4
- data/lib/kentaa/api/{requests → clients}/users.rb +4 -4
- data/lib/kentaa/api/config.rb +39 -0
- data/lib/kentaa/api/exception.rb +8 -0
- data/lib/kentaa/api/finder.rb +35 -0
- data/lib/kentaa/api/request.rb +15 -24
- data/lib/kentaa/api/{responses → resources}/action.rb +34 -10
- data/lib/kentaa/api/{responses → resources}/actions.rb +3 -3
- data/lib/kentaa/api/{responses → resources}/activity.rb +2 -2
- data/lib/kentaa/api/{responses → resources}/address.rb +2 -2
- data/lib/kentaa/api/{responses → resources}/banner.rb +2 -2
- data/lib/kentaa/api/{responses → resources}/base.rb +6 -6
- data/lib/kentaa/api/{responses → resources}/consent.rb +1 -1
- data/lib/kentaa/api/{responses → resources}/donation.rb +45 -6
- data/lib/kentaa/api/{responses → resources}/donations.rb +3 -3
- data/lib/kentaa/api/{responses → resources}/location.rb +1 -1
- data/lib/kentaa/api/{responses → resources}/newsletter_subscription.rb +24 -3
- data/lib/kentaa/api/{responses → resources}/newsletter_subscriptions.rb +3 -3
- data/lib/kentaa/api/{responses → resources}/pagination.rb +1 -1
- data/lib/kentaa/api/{responses → resources}/photo.rb +2 -2
- data/lib/kentaa/api/{responses → resources}/project.rb +25 -7
- data/lib/kentaa/api/{responses → resources}/projects.rb +3 -3
- data/lib/kentaa/api/{responses → resources}/question.rb +2 -2
- data/lib/kentaa/api/{responses → resources}/registration_fee.rb +1 -1
- data/lib/kentaa/api/{responses → resources}/resource.rb +1 -1
- data/lib/kentaa/api/{responses → resources}/reward.rb +2 -2
- data/lib/kentaa/api/{responses → resources}/segment.rb +11 -3
- data/lib/kentaa/api/{responses → resources}/segments.rb +3 -3
- data/lib/kentaa/api/{responses → resources}/site.rb +7 -3
- data/lib/kentaa/api/{responses → resources}/status.rb +4 -4
- data/lib/kentaa/api/{responses → resources}/team.rb +28 -7
- data/lib/kentaa/api/{responses → resources}/teams.rb +3 -3
- data/lib/kentaa/api/{responses → resources}/user.rb +11 -3
- data/lib/kentaa/api/{responses → resources}/users.rb +3 -3
- data/lib/kentaa/api/{responses → resources}/video.rb +2 -2
- data/lib/kentaa/api/response.rb +12 -0
- data/lib/kentaa/api/version.rb +1 -1
- metadata +44 -41
- data/lib/kentaa/api/requests/base.rb +0 -15
@@ -2,18 +2,18 @@
|
|
2
2
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
|
-
module
|
5
|
+
module Clients
|
6
6
|
class Users < Base
|
7
|
-
include Kentaa::Api::
|
7
|
+
include Kentaa::Api::Clients::All
|
8
8
|
|
9
9
|
def list(options = {})
|
10
10
|
response = request.get("/users", options)
|
11
|
-
Kentaa::Api::
|
11
|
+
Kentaa::Api::Resources::Users.new(config, response)
|
12
12
|
end
|
13
13
|
|
14
14
|
def get(id)
|
15
15
|
response = request.get("/users/#{id}")
|
16
|
-
Kentaa::Api::
|
16
|
+
Kentaa::Api::Resources::User.new(config, response)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kentaa
|
4
|
+
module Api
|
5
|
+
class Config
|
6
|
+
LIVE_URL = "https://api.kentaa.nl/v1"
|
7
|
+
TEST_URL = "https://api.kentaa.staatklaar.nu/v1"
|
8
|
+
DEV_URL = "http://api.lvh.me:3000/v1"
|
9
|
+
|
10
|
+
attr_accessor :api_key, :options
|
11
|
+
|
12
|
+
def initialize(api_key, options = {})
|
13
|
+
@api_key = api_key
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def api_url
|
18
|
+
case environment
|
19
|
+
when :test
|
20
|
+
TEST_URL
|
21
|
+
when :development
|
22
|
+
DEV_URL
|
23
|
+
when :live
|
24
|
+
LIVE_URL
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def environment
|
29
|
+
if options[:test]
|
30
|
+
:test
|
31
|
+
elsif options[:dev]
|
32
|
+
:development
|
33
|
+
else
|
34
|
+
:live
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kentaa
|
4
|
+
module Api
|
5
|
+
class Finder
|
6
|
+
attr_reader :config
|
7
|
+
|
8
|
+
def initialize(config)
|
9
|
+
@config = config
|
10
|
+
end
|
11
|
+
|
12
|
+
def by_object_key(object_key)
|
13
|
+
klass, id = object_key.split("_")
|
14
|
+
|
15
|
+
case klass
|
16
|
+
when "Action"
|
17
|
+
client = Kentaa::Api::Clients::Actions.new(config)
|
18
|
+
client.get(id)
|
19
|
+
when "Project"
|
20
|
+
client = Kentaa::Api::Clients::Projects.new(config)
|
21
|
+
client.get(id)
|
22
|
+
when "Segment"
|
23
|
+
client = Kentaa::Api::Clients::Segments.new(config)
|
24
|
+
client.get(id)
|
25
|
+
when "Site"
|
26
|
+
client = Kentaa::Api::Clients::Sites.new(config)
|
27
|
+
client.current
|
28
|
+
when "Team"
|
29
|
+
client = Kentaa::Api::Clients::Teams.new(config)
|
30
|
+
client.get(id)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/kentaa/api/request.rb
CHANGED
@@ -1,46 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'json'
|
4
3
|
require 'net/http'
|
5
4
|
require 'uri'
|
6
5
|
|
7
6
|
module Kentaa
|
8
7
|
module Api
|
9
8
|
class Request
|
10
|
-
|
11
|
-
TEST_URL = "https://api.kentaa.staatklaar.nu/v1/"
|
12
|
-
DEV_URL = "http://api.lvh.me:3000/v1"
|
9
|
+
attr_reader :config
|
13
10
|
|
14
|
-
def initialize(
|
15
|
-
@
|
16
|
-
@options = options
|
11
|
+
def initialize(config)
|
12
|
+
@config = config
|
17
13
|
end
|
18
14
|
|
19
15
|
def get(path, params = {})
|
20
|
-
uri = URI.parse(File.join(api_url, path))
|
16
|
+
uri = URI.parse(File.join(config.api_url, path))
|
21
17
|
uri.query = URI.encode_www_form(params) unless params.empty?
|
22
18
|
|
23
19
|
request = Net::HTTP::Get.new(uri)
|
24
|
-
request["X-Api-Key"] =
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
request["X-Api-Key"] = config.api_key
|
21
|
+
|
22
|
+
begin
|
23
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
24
|
+
http.request(request)
|
25
|
+
end
|
26
|
+
# Try to catch some common exceptions Net::HTTP might raise.
|
27
|
+
rescue Errno::ETIMEDOUT, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EHOSTUNREACH,
|
28
|
+
IOError, SocketError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::OpenTimeout,
|
29
|
+
Net::ProtocolError, Net::ReadTimeout, OpenSSL::SSL::SSLError => e
|
30
|
+
raise Kentaa::Api::Exception, e.message
|
28
31
|
end
|
29
32
|
|
30
33
|
Kentaa::Api::Response.new(response)
|
31
34
|
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def api_url
|
36
|
-
if @options[:test]
|
37
|
-
TEST_URL
|
38
|
-
elsif @options[:dev]
|
39
|
-
DEV_URL
|
40
|
-
else
|
41
|
-
LIVE_URL
|
42
|
-
end
|
43
|
-
end
|
44
35
|
end
|
45
36
|
end
|
46
37
|
end
|
@@ -5,14 +5,38 @@ require 'time'
|
|
5
5
|
|
6
6
|
module Kentaa
|
7
7
|
module Api
|
8
|
-
module
|
8
|
+
module Resources
|
9
9
|
class Action < Base
|
10
|
-
include Kentaa::Api::
|
10
|
+
include Kentaa::Api::Resources::Resource
|
11
|
+
|
12
|
+
def object_key
|
13
|
+
"Action_#{id}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def parent
|
17
|
+
if team_id
|
18
|
+
client = Kentaa::Api::Clients::Teams.new(config)
|
19
|
+
client.get(team_id)
|
20
|
+
elsif project_id
|
21
|
+
client = Kentaa::Api::Clients::Projects.new(config)
|
22
|
+
client.get(project_id)
|
23
|
+
elsif segment_id
|
24
|
+
client = Kentaa::Api::Clients::Segments.new(config)
|
25
|
+
client.get(segment_id)
|
26
|
+
else
|
27
|
+
client = Kentaa::Api::Clients::Sites.new(config)
|
28
|
+
client.current
|
29
|
+
end
|
30
|
+
end
|
11
31
|
|
12
32
|
def slug
|
13
33
|
data[:slug]
|
14
34
|
end
|
15
35
|
|
36
|
+
def site_id
|
37
|
+
data[:site_id]
|
38
|
+
end
|
39
|
+
|
16
40
|
def segment_id
|
17
41
|
data[:segment_id]
|
18
42
|
end
|
@@ -26,7 +50,7 @@ module Kentaa
|
|
26
50
|
end
|
27
51
|
|
28
52
|
def owner
|
29
|
-
@owner ||= Kentaa::Api::
|
53
|
+
@owner ||= Kentaa::Api::Resources::User.new(config, data[:owner])
|
30
54
|
end
|
31
55
|
|
32
56
|
def team_captain?
|
@@ -102,7 +126,7 @@ module Kentaa
|
|
102
126
|
end
|
103
127
|
|
104
128
|
def activity
|
105
|
-
@activity ||= Kentaa::Api::
|
129
|
+
@activity ||= Kentaa::Api::Resources::Activity.new(config, data[:activity])
|
106
130
|
end
|
107
131
|
|
108
132
|
def previous_participations
|
@@ -118,11 +142,11 @@ module Kentaa
|
|
118
142
|
end
|
119
143
|
|
120
144
|
def registration_fee
|
121
|
-
@registration_fee ||= Kentaa::Api::
|
145
|
+
@registration_fee ||= Kentaa::Api::Resources::RegistrationFee.new(config, data[:registration_fee])
|
122
146
|
end
|
123
147
|
|
124
148
|
def location
|
125
|
-
@location ||= Kentaa::Api::
|
149
|
+
@location ||= Kentaa::Api::Resources::Location.new(config, data[:location])
|
126
150
|
end
|
127
151
|
|
128
152
|
def photos
|
@@ -131,7 +155,7 @@ module Kentaa
|
|
131
155
|
|
132
156
|
if data[:photos]
|
133
157
|
data[:photos].each do |photo|
|
134
|
-
photos << Kentaa::Api::
|
158
|
+
photos << Kentaa::Api::Resources::Photo.new(config, photo)
|
135
159
|
end
|
136
160
|
end
|
137
161
|
|
@@ -145,7 +169,7 @@ module Kentaa
|
|
145
169
|
|
146
170
|
if data[:videos]
|
147
171
|
data[:videos].each do |video|
|
148
|
-
videos << Kentaa::Api::
|
172
|
+
videos << Kentaa::Api::Resources::Video.new(config, video)
|
149
173
|
end
|
150
174
|
end
|
151
175
|
|
@@ -159,7 +183,7 @@ module Kentaa
|
|
159
183
|
|
160
184
|
if data[:questions]
|
161
185
|
data[:questions].each do |question|
|
162
|
-
questions << Kentaa::Api::
|
186
|
+
questions << Kentaa::Api::Resources::Question.new(config, question)
|
163
187
|
end
|
164
188
|
end
|
165
189
|
|
@@ -168,7 +192,7 @@ module Kentaa
|
|
168
192
|
end
|
169
193
|
|
170
194
|
def consent
|
171
|
-
@consent ||= Kentaa::Api::
|
195
|
+
@consent ||= Kentaa::Api::Resources::Consent.new(config, data[:consent]) if data[:consent]
|
172
196
|
end
|
173
197
|
|
174
198
|
def external_reference
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
|
-
module
|
5
|
+
module Resources
|
6
6
|
class Actions < Base
|
7
7
|
include Enumerable
|
8
|
-
include Kentaa::Api::
|
8
|
+
include Kentaa::Api::Resources::Pagination
|
9
9
|
|
10
10
|
def each(&block)
|
11
11
|
actions.each(&block)
|
@@ -19,7 +19,7 @@ module Kentaa
|
|
19
19
|
|
20
20
|
if data
|
21
21
|
data.each do |action|
|
22
|
-
actions << Kentaa::Api::
|
22
|
+
actions << Kentaa::Api::Resources::Action.new(config, action)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'json'
|
4
|
-
|
5
3
|
module Kentaa
|
6
4
|
module Api
|
7
|
-
module
|
5
|
+
module Resources
|
8
6
|
class Base
|
9
|
-
attr_reader :data
|
7
|
+
attr_reader :config, :data
|
8
|
+
|
9
|
+
def initialize(config, response)
|
10
|
+
@config = config
|
10
11
|
|
11
|
-
def initialize(response)
|
12
12
|
if response.respond_to?(:body)
|
13
|
-
extend Kentaa::Api::
|
13
|
+
extend Kentaa::Api::Resources::Status
|
14
14
|
|
15
15
|
@response = response
|
16
16
|
@data = response.body[attribute_key]
|
@@ -5,9 +5,36 @@ require 'time'
|
|
5
5
|
|
6
6
|
module Kentaa
|
7
7
|
module Api
|
8
|
-
module
|
8
|
+
module Resources
|
9
9
|
class Donation < Base
|
10
|
-
include Kentaa::Api::
|
10
|
+
include Kentaa::Api::Resources::Resource
|
11
|
+
|
12
|
+
def object_key
|
13
|
+
"Donation_#{id}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def entity
|
17
|
+
if action_id
|
18
|
+
client = Kentaa::Api::Clients::Actions.new(config)
|
19
|
+
client.get(action_id)
|
20
|
+
elsif team_id
|
21
|
+
client = Kentaa::Api::Clients::Teams.new(config)
|
22
|
+
client.get(team_id)
|
23
|
+
elsif project_id
|
24
|
+
client = Kentaa::Api::Clients::Projects.new(config)
|
25
|
+
client.get(project_id)
|
26
|
+
elsif segment_id
|
27
|
+
client = Kentaa::Api::Clients::Segments.new(config)
|
28
|
+
client.get(segment_id)
|
29
|
+
else
|
30
|
+
client = Kentaa::Api::Clients::Sites.new(config)
|
31
|
+
client.current
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def site_id
|
36
|
+
data[:site_id]
|
37
|
+
end
|
11
38
|
|
12
39
|
def segment_id
|
13
40
|
data[:segment_id]
|
@@ -125,6 +152,18 @@ module Kentaa
|
|
125
152
|
data[:payment_description]
|
126
153
|
end
|
127
154
|
|
155
|
+
def account_iban
|
156
|
+
data[:account_iban]
|
157
|
+
end
|
158
|
+
|
159
|
+
def account_bic
|
160
|
+
data[:account_bic]
|
161
|
+
end
|
162
|
+
|
163
|
+
def account_name
|
164
|
+
data[:account_name]
|
165
|
+
end
|
166
|
+
|
128
167
|
def target_url
|
129
168
|
data[:target_url]
|
130
169
|
end
|
@@ -135,7 +174,7 @@ module Kentaa
|
|
135
174
|
|
136
175
|
if data[:questions]
|
137
176
|
data[:questions].each do |question|
|
138
|
-
questions << Kentaa::Api::
|
177
|
+
questions << Kentaa::Api::Resources::Question.new(config, question)
|
139
178
|
end
|
140
179
|
end
|
141
180
|
|
@@ -144,11 +183,11 @@ module Kentaa
|
|
144
183
|
end
|
145
184
|
|
146
185
|
def reward
|
147
|
-
@reward ||= Kentaa::Api::
|
186
|
+
@reward ||= Kentaa::Api::Resources::Reward.new(config, data[:reward]) if data[:reward]
|
148
187
|
end
|
149
188
|
|
150
189
|
def address
|
151
|
-
@address ||= Kentaa::Api::
|
190
|
+
@address ||= Kentaa::Api::Resources::Address.new(config, data[:address]) if data[:address]
|
152
191
|
end
|
153
192
|
|
154
193
|
def birthday
|
@@ -164,7 +203,7 @@ module Kentaa
|
|
164
203
|
end
|
165
204
|
|
166
205
|
def consent
|
167
|
-
@consent ||= Kentaa::Api::
|
206
|
+
@consent ||= Kentaa::Api::Resources::Consent.new(config, data[:consent]) if data[:consent]
|
168
207
|
end
|
169
208
|
end
|
170
209
|
end
|