kentaa-api 0.2.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -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, id: nil, data: nil, options: {})
|
12
|
+
super(config, options)
|
13
|
+
|
14
|
+
if data
|
15
|
+
@data = data || {}
|
16
|
+
@id = @data.fetch(:id) if @data.key?(:id)
|
17
|
+
elsif id
|
18
|
+
@id = 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
|
+
nil
|
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,13 +6,19 @@ 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
|
15
13
|
|
14
|
+
def parent
|
15
|
+
site
|
16
|
+
end
|
17
|
+
|
18
|
+
def site
|
19
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
|
20
|
+
end
|
21
|
+
|
16
22
|
def site_id
|
17
23
|
data[:site_id]
|
18
24
|
end
|
@@ -63,7 +69,7 @@ module Kentaa
|
|
63
69
|
|
64
70
|
if data[:banners]
|
65
71
|
data[:banners].each do |banner|
|
66
|
-
banners << Kentaa::Api::Resources::Banner.new(
|
72
|
+
banners << Kentaa::Api::Resources::Banner.new(banner)
|
67
73
|
end
|
68
74
|
end
|
69
75
|
|
@@ -74,6 +80,24 @@ module Kentaa
|
|
74
80
|
def external_reference
|
75
81
|
data[:external_reference]
|
76
82
|
end
|
83
|
+
|
84
|
+
def donations
|
85
|
+
@donations ||= Kentaa::Api::Resources::Donations.new(config, segment_id: id)
|
86
|
+
end
|
87
|
+
|
88
|
+
def manual_donations
|
89
|
+
@manual_donations ||= Kentaa::Api::Resources::ManualDonations.new(config, segment_id: id)
|
90
|
+
end
|
91
|
+
|
92
|
+
def newsletter_subscriptions
|
93
|
+
@newsletter_subscriptions ||= Kentaa::Api::Resources::NewsletterSubscriptions.new(config, segment_id: id)
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def load_resource
|
99
|
+
request.get("/segments/#{id}", options)
|
100
|
+
end
|
77
101
|
end
|
78
102
|
end
|
79
103
|
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, options: options)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
@@ -6,9 +6,7 @@ require 'time'
|
|
6
6
|
module Kentaa
|
7
7
|
module Api
|
8
8
|
module Resources
|
9
|
-
class Site <
|
10
|
-
include Kentaa::Api::Resources::Resource
|
11
|
-
|
9
|
+
class Site < Resource
|
12
10
|
def object_key
|
13
11
|
"Site_#{id}"
|
14
12
|
end
|
@@ -75,7 +73,7 @@ module Kentaa
|
|
75
73
|
|
76
74
|
if data[:banners]
|
77
75
|
data[:banners].each do |banner|
|
78
|
-
banners << Kentaa::Api::Resources::Banner.new(
|
76
|
+
banners << Kentaa::Api::Resources::Banner.new(banner)
|
79
77
|
end
|
80
78
|
end
|
81
79
|
|
@@ -86,6 +84,24 @@ module Kentaa
|
|
86
84
|
def external_reference
|
87
85
|
data[:external_reference]
|
88
86
|
end
|
87
|
+
|
88
|
+
def donations
|
89
|
+
@donations ||= Kentaa::Api::Resources::Donations.new(config)
|
90
|
+
end
|
91
|
+
|
92
|
+
def manual_donations
|
93
|
+
@manual_donations ||= Kentaa::Api::Resources::ManualDonations.new(config)
|
94
|
+
end
|
95
|
+
|
96
|
+
def newsletter_subscriptions
|
97
|
+
@newsletter_subscriptions ||= Kentaa::Api::Resources::NewsletterSubscriptions.new(config)
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def load_resource
|
103
|
+
request.get("/sites/current", options)
|
104
|
+
end
|
89
105
|
end
|
90
106
|
end
|
91
107
|
end
|
@@ -6,26 +6,25 @@ require 'time'
|
|
6
6
|
module Kentaa
|
7
7
|
module Api
|
8
8
|
module Resources
|
9
|
-
class Team <
|
10
|
-
include Kentaa::Api::Resources::Resource
|
11
|
-
|
9
|
+
class Team < Resource
|
12
10
|
def object_key
|
13
11
|
"Team_#{id}"
|
14
12
|
end
|
15
13
|
|
16
14
|
def parent
|
17
15
|
if project_id
|
18
|
-
|
19
|
-
client.get(project_id)
|
16
|
+
Kentaa::Api::Resources::Project.new(config, id: project_id, options: options)
|
20
17
|
elsif segment_id
|
21
|
-
|
22
|
-
client.get(segment_id)
|
18
|
+
Kentaa::Api::Resources::Segment.new(config, id: segment_id, options: options)
|
23
19
|
else
|
24
|
-
|
25
|
-
client.current
|
20
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
|
26
21
|
end
|
27
22
|
end
|
28
23
|
|
24
|
+
def site
|
25
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
|
26
|
+
end
|
27
|
+
|
29
28
|
def slug
|
30
29
|
data[:slug]
|
31
30
|
end
|
@@ -43,7 +42,7 @@ module Kentaa
|
|
43
42
|
end
|
44
43
|
|
45
44
|
def owner
|
46
|
-
@owner ||= Kentaa::Api::Resources::User.new(config, data[:owner])
|
45
|
+
@owner ||= Kentaa::Api::Resources::User.new(config, data: data[:owner], options: options)
|
47
46
|
end
|
48
47
|
|
49
48
|
def members
|
@@ -52,7 +51,7 @@ module Kentaa
|
|
52
51
|
|
53
52
|
if data[:members]
|
54
53
|
data[:members].each do |member|
|
55
|
-
members << Kentaa::Api::Resources::Action.new(config, member)
|
54
|
+
members << Kentaa::Api::Resources::Action.new(config, data: member, options: options)
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
@@ -122,7 +121,7 @@ module Kentaa
|
|
122
121
|
|
123
122
|
if data[:photos]
|
124
123
|
data[:photos].each do |photo|
|
125
|
-
photos << Kentaa::Api::Resources::Photo.new(
|
124
|
+
photos << Kentaa::Api::Resources::Photo.new(photo)
|
126
125
|
end
|
127
126
|
end
|
128
127
|
|
@@ -136,7 +135,7 @@ module Kentaa
|
|
136
135
|
|
137
136
|
if data[:videos]
|
138
137
|
data[:videos].each do |video|
|
139
|
-
videos << Kentaa::Api::Resources::Video.new(
|
138
|
+
videos << Kentaa::Api::Resources::Video.new(video)
|
140
139
|
end
|
141
140
|
end
|
142
141
|
|
@@ -150,7 +149,7 @@ module Kentaa
|
|
150
149
|
|
151
150
|
if data[:questions]
|
152
151
|
data[:questions].each do |question|
|
153
|
-
questions << Kentaa::Api::Resources::Question.new(
|
152
|
+
questions << Kentaa::Api::Resources::Question.new(question)
|
154
153
|
end
|
155
154
|
end
|
156
155
|
|
@@ -161,6 +160,20 @@ module Kentaa
|
|
161
160
|
def external_reference
|
162
161
|
data[:external_reference]
|
163
162
|
end
|
163
|
+
|
164
|
+
def donations
|
165
|
+
@donations ||= Kentaa::Api::Resources::Donations.new(config, team_id: id)
|
166
|
+
end
|
167
|
+
|
168
|
+
def manual_donations
|
169
|
+
@manual_donations ||= Kentaa::Api::Resources::ManualDonations.new(config, team_id: id)
|
170
|
+
end
|
171
|
+
|
172
|
+
private
|
173
|
+
|
174
|
+
def load_resource
|
175
|
+
request.get("/teams/#{id}", options)
|
176
|
+
end
|
164
177
|
end
|
165
178
|
end
|
166
179
|
end
|
@@ -3,9 +3,8 @@
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
|
-
class Teams <
|
6
|
+
class Teams < List
|
7
7
|
include Enumerable
|
8
|
-
include Kentaa::Api::Resources::Pagination
|
9
8
|
|
10
9
|
def each(&block)
|
11
10
|
teams.each(&block)
|
@@ -13,13 +12,17 @@ module Kentaa
|
|
13
12
|
|
14
13
|
private
|
15
14
|
|
15
|
+
def load_resource
|
16
|
+
request.get("/teams", options)
|
17
|
+
end
|
18
|
+
|
16
19
|
def teams
|
17
20
|
@teams ||= begin
|
18
21
|
teams = []
|
19
22
|
|
20
23
|
if data
|
21
24
|
data.each do |team|
|
22
|
-
teams << Kentaa::Api::Resources::Team.new(config, team)
|
25
|
+
teams << Kentaa::Api::Resources::Team.new(config, data: team, options: options)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
@@ -5,13 +5,15 @@ require 'time'
|
|
5
5
|
module Kentaa
|
6
6
|
module Api
|
7
7
|
module Resources
|
8
|
-
class User <
|
9
|
-
include Kentaa::Api::Resources::Resource
|
10
|
-
|
8
|
+
class User < Resource
|
11
9
|
def object_key
|
12
10
|
"User_#{id}"
|
13
11
|
end
|
14
12
|
|
13
|
+
def site
|
14
|
+
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
|
15
|
+
end
|
16
|
+
|
15
17
|
def site_id
|
16
18
|
data[:site_id]
|
17
19
|
end
|
@@ -77,7 +79,7 @@ module Kentaa
|
|
77
79
|
end
|
78
80
|
|
79
81
|
def birthday
|
80
|
-
|
82
|
+
Date.parse(data[:birthday]) if data[:birthday]
|
81
83
|
end
|
82
84
|
|
83
85
|
def gender
|
@@ -89,7 +91,27 @@ module Kentaa
|
|
89
91
|
end
|
90
92
|
|
91
93
|
def consent
|
92
|
-
@consent ||= Kentaa::Api::Resources::Consent.new(
|
94
|
+
@consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
|
95
|
+
end
|
96
|
+
|
97
|
+
def auth(attributes)
|
98
|
+
@response = request.post("/users/auth", options, attributes)
|
99
|
+
|
100
|
+
self
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def load_resource
|
106
|
+
request.get("/users/#{id}", options)
|
107
|
+
end
|
108
|
+
|
109
|
+
def create_resource(attributes)
|
110
|
+
request.post("/users", options, attributes)
|
111
|
+
end
|
112
|
+
|
113
|
+
def update_resource(attributes)
|
114
|
+
request.patch("/users/#{id}", options, attributes)
|
93
115
|
end
|
94
116
|
end
|
95
117
|
end
|
@@ -3,23 +3,36 @@
|
|
3
3
|
module Kentaa
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
|
-
class Users <
|
6
|
+
class Users < List
|
7
7
|
include Enumerable
|
8
|
-
include Kentaa::Api::Resources::Pagination
|
9
8
|
|
10
9
|
def each(&block)
|
11
10
|
users.each(&block)
|
12
11
|
end
|
13
12
|
|
13
|
+
def create(attributes = {})
|
14
|
+
user = Kentaa::Api::Resources::User.new(config, options: options)
|
15
|
+
user.save(attributes)
|
16
|
+
end
|
17
|
+
|
18
|
+
def auth(attributes = {})
|
19
|
+
user = Kentaa::Api::Resources::User.new(config, options: options)
|
20
|
+
user.auth(attributes)
|
21
|
+
end
|
22
|
+
|
14
23
|
private
|
15
24
|
|
25
|
+
def load_resource
|
26
|
+
request.get("/users", options)
|
27
|
+
end
|
28
|
+
|
16
29
|
def users
|
17
30
|
@users ||= begin
|
18
31
|
users = []
|
19
32
|
|
20
33
|
if data
|
21
34
|
data.each do |user|
|
22
|
-
users << Kentaa::Api::Resources::User.new(config, user)
|
35
|
+
users << Kentaa::Api::Resources::User.new(config, data: user, options: options)
|
23
36
|
end
|
24
37
|
end
|
25
38
|
|