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
@@ -4,16 +4,19 @@ module Kentaa
|
|
4
4
|
module Api
|
5
5
|
module Clients
|
6
6
|
class Segments < Base
|
7
|
-
|
7
|
+
def all(options = {})
|
8
|
+
segments = Kentaa::Api::Resources::Segments.new(config, options)
|
9
|
+
segments.all
|
10
|
+
end
|
8
11
|
|
9
12
|
def list(options = {})
|
10
|
-
|
11
|
-
|
13
|
+
segments = Kentaa::Api::Resources::Segments.new(config, options)
|
14
|
+
segments.load
|
12
15
|
end
|
13
16
|
|
14
|
-
def get(id)
|
15
|
-
|
16
|
-
|
17
|
+
def get(id, options = {})
|
18
|
+
segment = Kentaa::Api::Resources::Segment.new(config, options.merge(id: id))
|
19
|
+
segment.load
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -4,9 +4,9 @@ module Kentaa
|
|
4
4
|
module Api
|
5
5
|
module Clients
|
6
6
|
class Sites < Base
|
7
|
-
def current
|
8
|
-
|
9
|
-
|
7
|
+
def current(options = {})
|
8
|
+
site = Kentaa::Api::Resources::Site.new(config, options)
|
9
|
+
site.load
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -4,16 +4,19 @@ module Kentaa
|
|
4
4
|
module Api
|
5
5
|
module Clients
|
6
6
|
class Teams < Base
|
7
|
-
|
7
|
+
def all(options = {})
|
8
|
+
teams = Kentaa::Api::Resources::Teams.new(config, options)
|
9
|
+
teams.all
|
10
|
+
end
|
8
11
|
|
9
12
|
def list(options = {})
|
10
|
-
|
11
|
-
|
13
|
+
teams = Kentaa::Api::Resources::Teams.new(config, options)
|
14
|
+
teams.load
|
12
15
|
end
|
13
16
|
|
14
|
-
def get(id)
|
15
|
-
|
16
|
-
|
17
|
+
def get(id, options = {})
|
18
|
+
team = Kentaa::Api::Resources::Team.new(config, options.merge(id: id))
|
19
|
+
team.load
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -4,16 +4,29 @@ module Kentaa
|
|
4
4
|
module Api
|
5
5
|
module Clients
|
6
6
|
class Users < Base
|
7
|
-
|
7
|
+
def all(options = {})
|
8
|
+
users = Kentaa::Api::Resources::Users.new(config, options)
|
9
|
+
users.all
|
10
|
+
end
|
8
11
|
|
9
12
|
def list(options = {})
|
10
|
-
|
11
|
-
|
13
|
+
users = Kentaa::Api::Resources::Users.new(config, options)
|
14
|
+
users.load
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(id, options = {})
|
18
|
+
user = Kentaa::Api::Resources::User.new(config, options.merge(id: id))
|
19
|
+
user.load
|
20
|
+
end
|
21
|
+
|
22
|
+
def create(attributes = {}, options = {})
|
23
|
+
user = Kentaa::Api::Resources::Users.new(config, options)
|
24
|
+
user.create(attributes)
|
12
25
|
end
|
13
26
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
27
|
+
def update(id, attributes = {}, options = {})
|
28
|
+
user = Kentaa::Api::Resources::User.new(config, options.merge(id: id))
|
29
|
+
user.save(attributes)
|
17
30
|
end
|
18
31
|
end
|
19
32
|
end
|
data/lib/kentaa/api/exception.rb
CHANGED
@@ -4,5 +4,23 @@ module Kentaa
|
|
4
4
|
module Api
|
5
5
|
class Exception < StandardError
|
6
6
|
end
|
7
|
+
|
8
|
+
class RequestError < Kentaa::Api::Exception
|
9
|
+
attr_accessor :response
|
10
|
+
|
11
|
+
def initialize(response)
|
12
|
+
@response = response
|
13
|
+
|
14
|
+
super(response.message)
|
15
|
+
end
|
16
|
+
|
17
|
+
def errors
|
18
|
+
response.errors
|
19
|
+
end
|
20
|
+
|
21
|
+
def http_code
|
22
|
+
response.http_code
|
23
|
+
end
|
24
|
+
end
|
7
25
|
end
|
8
26
|
end
|
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
@@ -13,16 +13,53 @@ module Kentaa
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def get(path, params = {})
|
16
|
+
request(:get, path, params)
|
17
|
+
end
|
18
|
+
|
19
|
+
def post(path, params = {}, body = {})
|
20
|
+
request(:post, path, params, body)
|
21
|
+
end
|
22
|
+
|
23
|
+
def patch(path, params = {}, body = {})
|
24
|
+
request(:patch, path, params, body)
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(path, params = {})
|
28
|
+
request(:delete, path, params)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def request(http_method, path, params = {}, body = {})
|
16
34
|
uri = URI.parse(File.join(config.api_url, path))
|
17
35
|
uri.query = URI.encode_www_form(params) unless params.empty?
|
18
36
|
|
19
|
-
|
37
|
+
case http_method
|
38
|
+
when :get
|
39
|
+
request = Net::HTTP::Get.new(uri)
|
40
|
+
when :post
|
41
|
+
request = Net::HTTP::Post.new(uri)
|
42
|
+
request.body = body.to_json
|
43
|
+
when :patch
|
44
|
+
request = Net::HTTP::Patch.new(uri)
|
45
|
+
request.body = body.to_json
|
46
|
+
when :delete
|
47
|
+
request = Net::HTTP::Delete.new(uri)
|
48
|
+
else
|
49
|
+
raise Kentaa::Api::Exception, "Invalid HTTP method: #{http_method}"
|
50
|
+
end
|
51
|
+
|
52
|
+
request["Accept"] = "application/json"
|
53
|
+
request["Content-Type"] = "application/json"
|
20
54
|
request["X-Api-Key"] = config.api_key
|
55
|
+
request["User-Agent"] = "Ruby kentaa-api/#{Kentaa::Api::VERSION}"
|
56
|
+
|
57
|
+
client = Net::HTTP.new(uri.hostname, uri.port)
|
58
|
+
client.use_ssl = uri.scheme == "https"
|
59
|
+
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
21
60
|
|
22
61
|
begin
|
23
|
-
response =
|
24
|
-
http.request(request)
|
25
|
-
end
|
62
|
+
response = Kentaa::Api::Response.new(client.request(request))
|
26
63
|
# Try to catch some common exceptions Net::HTTP might raise.
|
27
64
|
rescue Errno::ETIMEDOUT, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EHOSTUNREACH,
|
28
65
|
IOError, SocketError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::OpenTimeout,
|
@@ -30,7 +67,11 @@ module Kentaa
|
|
30
67
|
raise Kentaa::Api::Exception, e.message
|
31
68
|
end
|
32
69
|
|
33
|
-
|
70
|
+
if response.error?
|
71
|
+
raise Kentaa::Api::RequestError, response
|
72
|
+
end
|
73
|
+
|
74
|
+
response
|
34
75
|
end
|
35
76
|
end
|
36
77
|
end
|
@@ -6,26 +6,20 @@ 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)
|
20
17
|
elsif project_id
|
21
|
-
|
22
|
-
client.get(project_id)
|
18
|
+
Kentaa::Api::Resources::Project.new(config, id: project_id)
|
23
19
|
elsif segment_id
|
24
|
-
|
25
|
-
client.get(segment_id)
|
20
|
+
Kentaa::Api::Resources::Segment.new(config, id: segment_id)
|
26
21
|
else
|
27
|
-
|
28
|
-
client.current
|
22
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id)
|
29
23
|
end
|
30
24
|
end
|
31
25
|
|
@@ -50,7 +44,7 @@ module Kentaa
|
|
50
44
|
end
|
51
45
|
|
52
46
|
def owner
|
53
|
-
@owner ||= Kentaa::Api::Resources::User.new(config, data[:owner])
|
47
|
+
@owner ||= Kentaa::Api::Resources::User.new(config, data: data[:owner])
|
54
48
|
end
|
55
49
|
|
56
50
|
def team_captain?
|
@@ -74,7 +68,7 @@ module Kentaa
|
|
74
68
|
end
|
75
69
|
|
76
70
|
def name
|
77
|
-
[first_name, infix, last_name].
|
71
|
+
[first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(" ")
|
78
72
|
end
|
79
73
|
|
80
74
|
def fundraiser_page?
|
@@ -126,7 +120,7 @@ module Kentaa
|
|
126
120
|
end
|
127
121
|
|
128
122
|
def activity
|
129
|
-
@activity ||= Kentaa::Api::Resources::Activity.new(
|
123
|
+
@activity ||= Kentaa::Api::Resources::Activity.new(data[:activity])
|
130
124
|
end
|
131
125
|
|
132
126
|
def previous_participations
|
@@ -142,11 +136,11 @@ module Kentaa
|
|
142
136
|
end
|
143
137
|
|
144
138
|
def registration_fee
|
145
|
-
@registration_fee ||= Kentaa::Api::Resources::RegistrationFee.new(
|
139
|
+
@registration_fee ||= Kentaa::Api::Resources::RegistrationFee.new(data[:registration_fee])
|
146
140
|
end
|
147
141
|
|
148
142
|
def location
|
149
|
-
@location ||= Kentaa::Api::Resources::Location.new(
|
143
|
+
@location ||= Kentaa::Api::Resources::Location.new(data[:location])
|
150
144
|
end
|
151
145
|
|
152
146
|
def photos
|
@@ -155,7 +149,7 @@ module Kentaa
|
|
155
149
|
|
156
150
|
if data[:photos]
|
157
151
|
data[:photos].each do |photo|
|
158
|
-
photos << Kentaa::Api::Resources::Photo.new(
|
152
|
+
photos << Kentaa::Api::Resources::Photo.new(photo)
|
159
153
|
end
|
160
154
|
end
|
161
155
|
|
@@ -169,7 +163,7 @@ module Kentaa
|
|
169
163
|
|
170
164
|
if data[:videos]
|
171
165
|
data[:videos].each do |video|
|
172
|
-
videos << Kentaa::Api::Resources::Video.new(
|
166
|
+
videos << Kentaa::Api::Resources::Video.new(video)
|
173
167
|
end
|
174
168
|
end
|
175
169
|
|
@@ -183,7 +177,7 @@ module Kentaa
|
|
183
177
|
|
184
178
|
if data[:questions]
|
185
179
|
data[:questions].each do |question|
|
186
|
-
questions << Kentaa::Api::Resources::Question.new(
|
180
|
+
questions << Kentaa::Api::Resources::Question.new(question)
|
187
181
|
end
|
188
182
|
end
|
189
183
|
|
@@ -192,12 +186,34 @@ module Kentaa
|
|
192
186
|
end
|
193
187
|
|
194
188
|
def consent
|
195
|
-
@consent ||= Kentaa::Api::Resources::Consent.new(
|
189
|
+
@consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
|
196
190
|
end
|
197
191
|
|
198
192
|
def external_reference
|
199
193
|
data[:external_reference]
|
200
194
|
end
|
195
|
+
|
196
|
+
def donations
|
197
|
+
@donations ||= Kentaa::Api::Resources::Donations.new(config, action_id: id)
|
198
|
+
end
|
199
|
+
|
200
|
+
def manual_donations
|
201
|
+
@manual_donations ||= Kentaa::Api::Resources::ManualDonations.new(config, action_id: id)
|
202
|
+
end
|
203
|
+
|
204
|
+
private
|
205
|
+
|
206
|
+
def load_resource
|
207
|
+
request.get("/actions/#{id}", options)
|
208
|
+
end
|
209
|
+
|
210
|
+
def create_resource(attributes)
|
211
|
+
request.post("/actions", options, attributes)
|
212
|
+
end
|
213
|
+
|
214
|
+
def update_resource(attributes)
|
215
|
+
request.patch("/actions/#{id}", options, attributes)
|
216
|
+
end
|
201
217
|
end
|
202
218
|
end
|
203
219
|
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)
|
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)
|
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]
|