kentaa-api 0.1.1 → 0.2.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +13 -12
  5. data/lib/kentaa/api.rb +42 -39
  6. data/lib/kentaa/api/client.rb +10 -10
  7. data/lib/kentaa/api/{requests → clients}/actions.rb +4 -4
  8. data/lib/kentaa/api/{requests → clients}/all.rb +1 -1
  9. data/lib/kentaa/api/clients/base.rb +19 -0
  10. data/lib/kentaa/api/{requests → clients}/donations.rb +4 -4
  11. data/lib/kentaa/api/{requests → clients}/newsletter_subscriptions.rb +4 -4
  12. data/lib/kentaa/api/{requests → clients}/projects.rb +4 -4
  13. data/lib/kentaa/api/{requests → clients}/segments.rb +4 -4
  14. data/lib/kentaa/api/{requests → clients}/sites.rb +2 -2
  15. data/lib/kentaa/api/{requests → clients}/teams.rb +4 -4
  16. data/lib/kentaa/api/{requests → clients}/users.rb +4 -4
  17. data/lib/kentaa/api/config.rb +39 -0
  18. data/lib/kentaa/api/exception.rb +8 -0
  19. data/lib/kentaa/api/finder.rb +35 -0
  20. data/lib/kentaa/api/request.rb +15 -24
  21. data/lib/kentaa/api/{responses → resources}/action.rb +34 -10
  22. data/lib/kentaa/api/{responses → resources}/actions.rb +3 -3
  23. data/lib/kentaa/api/{responses → resources}/activity.rb +2 -2
  24. data/lib/kentaa/api/{responses → resources}/address.rb +2 -2
  25. data/lib/kentaa/api/{responses → resources}/banner.rb +2 -2
  26. data/lib/kentaa/api/{responses → resources}/base.rb +6 -6
  27. data/lib/kentaa/api/{responses → resources}/consent.rb +1 -1
  28. data/lib/kentaa/api/{responses → resources}/donation.rb +45 -6
  29. data/lib/kentaa/api/{responses → resources}/donations.rb +3 -3
  30. data/lib/kentaa/api/{responses → resources}/location.rb +1 -1
  31. data/lib/kentaa/api/{responses → resources}/newsletter_subscription.rb +24 -3
  32. data/lib/kentaa/api/{responses → resources}/newsletter_subscriptions.rb +3 -3
  33. data/lib/kentaa/api/{responses → resources}/pagination.rb +1 -1
  34. data/lib/kentaa/api/{responses → resources}/photo.rb +2 -2
  35. data/lib/kentaa/api/{responses → resources}/project.rb +25 -7
  36. data/lib/kentaa/api/{responses → resources}/projects.rb +3 -3
  37. data/lib/kentaa/api/{responses → resources}/question.rb +2 -2
  38. data/lib/kentaa/api/{responses → resources}/registration_fee.rb +1 -1
  39. data/lib/kentaa/api/{responses → resources}/resource.rb +1 -1
  40. data/lib/kentaa/api/{responses → resources}/reward.rb +2 -2
  41. data/lib/kentaa/api/{responses → resources}/segment.rb +11 -3
  42. data/lib/kentaa/api/{responses → resources}/segments.rb +3 -3
  43. data/lib/kentaa/api/{responses → resources}/site.rb +7 -3
  44. data/lib/kentaa/api/{responses → resources}/status.rb +4 -4
  45. data/lib/kentaa/api/{responses → resources}/team.rb +28 -7
  46. data/lib/kentaa/api/{responses → resources}/teams.rb +3 -3
  47. data/lib/kentaa/api/{responses → resources}/user.rb +11 -3
  48. data/lib/kentaa/api/{responses → resources}/users.rb +3 -3
  49. data/lib/kentaa/api/{responses → resources}/video.rb +2 -2
  50. data/lib/kentaa/api/response.rb +12 -0
  51. data/lib/kentaa/api/version.rb +1 -1
  52. metadata +44 -41
  53. data/lib/kentaa/api/requests/base.rb +0 -15
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- module Responses
5
+ module Resources
6
6
  class Donations < Base
7
7
  include Enumerable
8
- include Kentaa::Api::Responses::Pagination
8
+ include Kentaa::Api::Resources::Pagination
9
9
 
10
10
  def each(&block)
11
11
  donations.each(&block)
@@ -19,7 +19,7 @@ module Kentaa
19
19
 
20
20
  if data
21
21
  data.each do |donation|
22
- donations << Kentaa::Api::Responses::Donation.new(donation)
22
+ donations << Kentaa::Api::Resources::Donation.new(config, donation)
23
23
  end
24
24
  end
25
25
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- module Responses
5
+ module Resources
6
6
  class Location < Base
7
7
  def zip_code
8
8
  data[:zip_code]
@@ -2,9 +2,26 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- module Responses
5
+ module Resources
6
6
  class NewsletterSubscription < Base
7
- include Kentaa::Api::Responses::Resource
7
+ include Kentaa::Api::Resources::Resource
8
+
9
+ def object_key
10
+ "NewsletterSubscription_#{id}"
11
+ end
12
+
13
+ def entity
14
+ if project_id
15
+ client = Kentaa::Api::Clients::Projects.new(config)
16
+ client.get(project_id)
17
+ elsif segment_id
18
+ client = Kentaa::Api::Clients::Segments.new(config)
19
+ client.get(segment_id)
20
+ else
21
+ client = Kentaa::Api::Clients::Sites.new(config)
22
+ client.current
23
+ end
24
+ end
8
25
 
9
26
  def first_name
10
27
  data[:first_name]
@@ -22,6 +39,10 @@ module Kentaa
22
39
  [first_name, infix, last_name].compact.join(" ")
23
40
  end
24
41
 
42
+ def site_id
43
+ data[:site_id]
44
+ end
45
+
25
46
  def segment_id
26
47
  data[:segment_id]
27
48
  end
@@ -43,7 +64,7 @@ module Kentaa
43
64
  end
44
65
 
45
66
  def consent
46
- @consent ||= Kentaa::Api::Responses::Consent.new(data[:consent]) if data[:consent]
67
+ @consent ||= Kentaa::Api::Resources::Consent.new(config, data[:consent]) if data[:consent]
47
68
  end
48
69
  end
49
70
  end
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- module Responses
5
+ module Resources
6
6
  class NewsletterSubscriptions < Base
7
7
  include Enumerable
8
- include Kentaa::Api::Responses::Pagination
8
+ include Kentaa::Api::Resources::Pagination
9
9
 
10
10
  def each(&block)
11
11
  newsletter_subscriptions.each(&block)
@@ -19,7 +19,7 @@ module Kentaa
19
19
 
20
20
  if data
21
21
  data.each do |newsletter_subscription|
22
- newsletter_subscriptions << Kentaa::Api::Responses::NewsletterSubscription.new(newsletter_subscription)
22
+ newsletter_subscriptions << Kentaa::Api::Resources::NewsletterSubscription.new(config, newsletter_subscription)
23
23
  end
24
24
  end
25
25
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- module Responses
5
+ module Resources
6
6
  module Pagination
7
7
  attr_accessor :body
8
8
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- module Responses
5
+ module Resources
6
6
  class Photo < Base
7
- include Kentaa::Api::Responses::Resource
7
+ include Kentaa::Api::Resources::Resource
8
8
 
9
9
  def url
10
10
  data[:url]
@@ -5,14 +5,32 @@ require 'time'
5
5
 
6
6
  module Kentaa
7
7
  module Api
8
- module Responses
8
+ module Resources
9
9
  class Project < Base
10
- include Kentaa::Api::Responses::Resource
10
+ include Kentaa::Api::Resources::Resource
11
+
12
+ def object_key
13
+ "Project_#{id}"
14
+ end
15
+
16
+ def parent
17
+ if segment_id
18
+ client = Kentaa::Api::Clients::Segments.new(config)
19
+ client.get(segment_id)
20
+ else
21
+ client = Kentaa::Api::Clients::Sites.new(config)
22
+ client.current
23
+ end
24
+ end
11
25
 
12
26
  def slug
13
27
  data[:slug]
14
28
  end
15
29
 
30
+ def site_id
31
+ data[:site_id]
32
+ end
33
+
16
34
  def segment_id
17
35
  data[:segment_id]
18
36
  end
@@ -70,7 +88,7 @@ module Kentaa
70
88
  end
71
89
 
72
90
  def location
73
- @location ||= Kentaa::Api::Responses::Location.new(data[:location])
91
+ @location ||= Kentaa::Api::Resources::Location.new(config, data[:location])
74
92
  end
75
93
 
76
94
  def photos
@@ -79,7 +97,7 @@ module Kentaa
79
97
 
80
98
  if data[:photos]
81
99
  data[:photos].each do |photo|
82
- photos << Kentaa::Api::Responses::Photo.new(photo)
100
+ photos << Kentaa::Api::Resources::Photo.new(config, photo)
83
101
  end
84
102
  end
85
103
 
@@ -93,7 +111,7 @@ module Kentaa
93
111
 
94
112
  if data[:videos]
95
113
  data[:videos].each do |video|
96
- videos << Kentaa::Api::Responses::Video.new(video)
114
+ videos << Kentaa::Api::Resources::Video.new(config, video)
97
115
  end
98
116
  end
99
117
 
@@ -107,7 +125,7 @@ module Kentaa
107
125
 
108
126
  if data[:questions]
109
127
  data[:questions].each do |question|
110
- questions << Kentaa::Api::Responses::Question.new(question)
128
+ questions << Kentaa::Api::Resources::Question.new(config, question)
111
129
  end
112
130
  end
113
131
 
@@ -116,7 +134,7 @@ module Kentaa
116
134
  end
117
135
 
118
136
  def consent
119
- @consent ||= Kentaa::Api::Responses::Consent.new(data[:consent]) if data[:consent]
137
+ @consent ||= Kentaa::Api::Resources::Consent.new(config, data[:consent]) if data[:consent]
120
138
  end
121
139
 
122
140
  def external_reference
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- module Responses
5
+ module Resources
6
6
  class Projects < Base
7
7
  include Enumerable
8
- include Kentaa::Api::Responses::Pagination
8
+ include Kentaa::Api::Resources::Pagination
9
9
 
10
10
  def each(&block)
11
11
  projects.each(&block)
@@ -19,7 +19,7 @@ module Kentaa
19
19
 
20
20
  if data
21
21
  data.each do |project|
22
- projects << Kentaa::Api::Responses::Project.new(project)
22
+ projects << Kentaa::Api::Resources::Project.new(config, project)
23
23
  end
24
24
  end
25
25
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- module Responses
5
+ module Resources
6
6
  class Question < Base
7
- include Kentaa::Api::Responses::Resource
7
+ include Kentaa::Api::Resources::Resource
8
8
 
9
9
  def question
10
10
  data[:question]
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- module Responses
5
+ module Resources
6
6
  class RegistrationFee < Base
7
7
  def amount
8
8
  data[:amount]
@@ -4,7 +4,7 @@ require 'time'
4
4
 
5
5
  module Kentaa
6
6
  module Api
7
- module Responses
7
+ module Resources
8
8
  module Resource
9
9
  def id
10
10
  data[:id]
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- module Responses
5
+ module Resources
6
6
  class Reward < Base
7
- include Kentaa::Api::Responses::Resource
7
+ include Kentaa::Api::Resources::Resource
8
8
 
9
9
  def type
10
10
  data[:type]
@@ -5,9 +5,17 @@ require 'time'
5
5
 
6
6
  module Kentaa
7
7
  module Api
8
- module Responses
8
+ module Resources
9
9
  class Segment < Base
10
- include Kentaa::Api::Responses::Resource
10
+ include Kentaa::Api::Resources::Resource
11
+
12
+ def object_key
13
+ "Segment_#{id}"
14
+ end
15
+
16
+ def site_id
17
+ data[:site_id]
18
+ end
11
19
 
12
20
  def subdomain
13
21
  data[:subdomain]
@@ -55,7 +63,7 @@ module Kentaa
55
63
 
56
64
  if data[:banners]
57
65
  data[:banners].each do |banner|
58
- banners << Kentaa::Api::Responses::Banner.new(banner)
66
+ banners << Kentaa::Api::Resources::Banner.new(config, banner)
59
67
  end
60
68
  end
61
69
 
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- module Responses
5
+ module Resources
6
6
  class Segments < Base
7
7
  include Enumerable
8
- include Kentaa::Api::Responses::Pagination
8
+ include Kentaa::Api::Resources::Pagination
9
9
 
10
10
  def each(&block)
11
11
  segments.each(&block)
@@ -19,7 +19,7 @@ module Kentaa
19
19
 
20
20
  if data
21
21
  data.each do |segment|
22
- segments << Kentaa::Api::Responses::Segment.new(segment)
22
+ segments << Kentaa::Api::Resources::Segment.new(config, segment)
23
23
  end
24
24
  end
25
25
 
@@ -5,9 +5,13 @@ require 'time'
5
5
 
6
6
  module Kentaa
7
7
  module Api
8
- module Responses
8
+ module Resources
9
9
  class Site < Base
10
- include Kentaa::Api::Responses::Resource
10
+ include Kentaa::Api::Resources::Resource
11
+
12
+ def object_key
13
+ "Site_#{id}"
14
+ end
11
15
 
12
16
  def host
13
17
  data[:host]
@@ -71,7 +75,7 @@ module Kentaa
71
75
 
72
76
  if data[:banners]
73
77
  data[:banners].each do |banner|
74
- banners << Kentaa::Api::Responses::Banner.new(banner)
78
+ banners << Kentaa::Api::Resources::Banner.new(config, banner)
75
79
  end
76
80
  end
77
81
 
@@ -2,16 +2,16 @@
2
2
 
3
3
  module Kentaa
4
4
  module Api
5
- module Responses
5
+ module Resources
6
6
  module Status
7
7
  attr_accessor :response
8
8
 
9
9
  def success?
10
- (response.code == 200 || response.code == 201) && !message
10
+ response.success?
11
11
  end
12
12
 
13
13
  def error?
14
- !success?
14
+ response.error?
15
15
  end
16
16
 
17
17
  def body
@@ -19,7 +19,7 @@ module Kentaa
19
19
  end
20
20
 
21
21
  def message
22
- body[:message] if body
22
+ response.message
23
23
  end
24
24
  end
25
25
  end
@@ -5,14 +5,35 @@ require 'time'
5
5
 
6
6
  module Kentaa
7
7
  module Api
8
- module Responses
8
+ module Resources
9
9
  class Team < Base
10
- include Kentaa::Api::Responses::Resource
10
+ include Kentaa::Api::Resources::Resource
11
+
12
+ def object_key
13
+ "Team_#{id}"
14
+ end
15
+
16
+ def parent
17
+ if project_id
18
+ client = Kentaa::Api::Clients::Projects.new(config)
19
+ client.get(project_id)
20
+ elsif segment_id
21
+ client = Kentaa::Api::Clients::Segments.new(config)
22
+ client.get(segment_id)
23
+ else
24
+ client = Kentaa::Api::Clients::Sites.new(config)
25
+ client.current
26
+ end
27
+ end
11
28
 
12
29
  def slug
13
30
  data[:slug]
14
31
  end
15
32
 
33
+ def site_id
34
+ data[:site_id]
35
+ end
36
+
16
37
  def segment_id
17
38
  data[:segment_id]
18
39
  end
@@ -22,7 +43,7 @@ module Kentaa
22
43
  end
23
44
 
24
45
  def owner
25
- @owner ||= Kentaa::Api::Responses::User.new(data[:owner])
46
+ @owner ||= Kentaa::Api::Resources::User.new(config, data[:owner])
26
47
  end
27
48
 
28
49
  def members
@@ -31,7 +52,7 @@ module Kentaa
31
52
 
32
53
  if data[:members]
33
54
  data[:members].each do |member|
34
- members << Kentaa::Api::Responses::Action.new(member)
55
+ members << Kentaa::Api::Resources::Action.new(config, member)
35
56
  end
36
57
  end
37
58
 
@@ -101,7 +122,7 @@ module Kentaa
101
122
 
102
123
  if data[:photos]
103
124
  data[:photos].each do |photo|
104
- photos << Kentaa::Api::Responses::Photo.new(photo)
125
+ photos << Kentaa::Api::Resources::Photo.new(config, photo)
105
126
  end
106
127
  end
107
128
 
@@ -115,7 +136,7 @@ module Kentaa
115
136
 
116
137
  if data[:videos]
117
138
  data[:videos].each do |video|
118
- videos << Kentaa::Api::Responses::Video.new(video)
139
+ videos << Kentaa::Api::Resources::Video.new(config, video)
119
140
  end
120
141
  end
121
142
 
@@ -129,7 +150,7 @@ module Kentaa
129
150
 
130
151
  if data[:questions]
131
152
  data[:questions].each do |question|
132
- questions << Kentaa::Api::Responses::Question.new(question)
153
+ questions << Kentaa::Api::Resources::Question.new(config, question)
133
154
  end
134
155
  end
135
156