kentaa-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +33 -0
  5. data/.travis.yml +7 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +163 -0
  9. data/Rakefile +8 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/kentaa-api.gemspec +30 -0
  13. data/lib/kentaa/api/client.rb +37 -0
  14. data/lib/kentaa/api/http.rb +47 -0
  15. data/lib/kentaa/api/requests/actions.rb +19 -0
  16. data/lib/kentaa/api/requests/all.rb +24 -0
  17. data/lib/kentaa/api/requests/base.rb +13 -0
  18. data/lib/kentaa/api/requests/donations.rb +19 -0
  19. data/lib/kentaa/api/requests/newsletter_subscriptions.rb +14 -0
  20. data/lib/kentaa/api/requests/projects.rb +19 -0
  21. data/lib/kentaa/api/requests/segments.rb +19 -0
  22. data/lib/kentaa/api/requests/sites.rb +12 -0
  23. data/lib/kentaa/api/requests/teams.rb +19 -0
  24. data/lib/kentaa/api/responses/action.rb +114 -0
  25. data/lib/kentaa/api/responses/actions.rb +34 -0
  26. data/lib/kentaa/api/responses/address.rb +33 -0
  27. data/lib/kentaa/api/responses/banner.rb +29 -0
  28. data/lib/kentaa/api/responses/base.rb +21 -0
  29. data/lib/kentaa/api/responses/donation.rb +142 -0
  30. data/lib/kentaa/api/responses/donations.rb +34 -0
  31. data/lib/kentaa/api/responses/newsletter_subscription.rb +33 -0
  32. data/lib/kentaa/api/responses/newsletter_subscriptions.rb +34 -0
  33. data/lib/kentaa/api/responses/owner.rb +37 -0
  34. data/lib/kentaa/api/responses/pagination.rb +47 -0
  35. data/lib/kentaa/api/responses/photo.rb +17 -0
  36. data/lib/kentaa/api/responses/project.rb +102 -0
  37. data/lib/kentaa/api/responses/projects.rb +34 -0
  38. data/lib/kentaa/api/responses/question.rb +21 -0
  39. data/lib/kentaa/api/responses/resource.rb +21 -0
  40. data/lib/kentaa/api/responses/reward.rb +29 -0
  41. data/lib/kentaa/api/responses/segment.rb +70 -0
  42. data/lib/kentaa/api/responses/segments.rb +34 -0
  43. data/lib/kentaa/api/responses/site.rb +82 -0
  44. data/lib/kentaa/api/responses/team.rb +128 -0
  45. data/lib/kentaa/api/responses/teams.rb +34 -0
  46. data/lib/kentaa/api/responses/video.rb +17 -0
  47. data/lib/kentaa/api/version.rb +5 -0
  48. data/lib/kentaa/api.rb +40 -0
  49. metadata +153 -0
@@ -0,0 +1,114 @@
1
+ require 'bigdecimal'
2
+ require 'time'
3
+
4
+ module Kentaa
5
+ module Api
6
+ module Responses
7
+ class Action < Base
8
+ include Kentaa::Api::Responses::Resource
9
+
10
+ def initialize(response)
11
+ super(response[:action] || response)
12
+ end
13
+
14
+ def slug
15
+ data[:slug]
16
+ end
17
+
18
+ def segment_id
19
+ data[:segment_id]
20
+ end
21
+
22
+ def project_id
23
+ data[:project_id]
24
+ end
25
+
26
+ def team_id
27
+ data[:team_id]
28
+ end
29
+
30
+ def owner
31
+ @owner ||= Kentaa::Api::Responses::Owner.new(data[:owner])
32
+ end
33
+
34
+ def title
35
+ data[:title]
36
+ end
37
+
38
+ def description
39
+ data[:description]
40
+ end
41
+
42
+ def target_amount
43
+ data[:target_amount]
44
+ end
45
+
46
+ def total_amount
47
+ BigDecimal.new(data[:total_amount])
48
+ end
49
+
50
+ def total_donations
51
+ data[:total_donations]
52
+ end
53
+
54
+ def visible?
55
+ data[:visible]
56
+ end
57
+
58
+ def end_date
59
+ Time.parse(data[:end_date]) if data[:end_date]
60
+ end
61
+
62
+ def url
63
+ data[:url]
64
+ end
65
+
66
+ def donate_url
67
+ data[:donate_url]
68
+ end
69
+
70
+ def photos
71
+ @photos ||= begin
72
+ photos = []
73
+
74
+ if data[:photos]
75
+ data[:photos].each do |photo|
76
+ photos << Kentaa::Api::Responses::Photo.new(photo)
77
+ end
78
+ end
79
+
80
+ photos
81
+ end
82
+ end
83
+
84
+ def videos
85
+ @videos ||= begin
86
+ videos = []
87
+
88
+ if data[:videos]
89
+ data[:videos].each do |video|
90
+ videos << Kentaa::Api::Responses::Video.new(video)
91
+ end
92
+ end
93
+
94
+ videos
95
+ end
96
+ end
97
+
98
+ def questions
99
+ @questions ||= begin
100
+ questions = []
101
+
102
+ if data[:questions]
103
+ data[:questions].each do |question|
104
+ questions << Kentaa::Api::Responses::Question.new(question)
105
+ end
106
+ end
107
+
108
+ questions
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,34 @@
1
+ module Kentaa
2
+ module Api
3
+ module Responses
4
+ class Actions < Base
5
+ include Enumerable
6
+ include Kentaa::Api::Responses::Pagination
7
+
8
+ def initialize(response)
9
+ super(response)
10
+ end
11
+
12
+ def each(&block)
13
+ actions.each(&block)
14
+ end
15
+
16
+ private
17
+
18
+ def actions
19
+ @actions ||= begin
20
+ actions = []
21
+
22
+ if data[:actions]
23
+ data[:actions].each do |action|
24
+ actions << Kentaa::Api::Responses::Action.new(action)
25
+ end
26
+ end
27
+
28
+ actions
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ module Kentaa
2
+ module Api
3
+ module Responses
4
+ class Address < Base
5
+ include Kentaa::Api::Responses::Resource
6
+
7
+ def initialize(response)
8
+ super(response)
9
+ end
10
+
11
+ def address
12
+ data[:address]
13
+ end
14
+
15
+ def address2
16
+ data[:address2]
17
+ end
18
+
19
+ def zipcode
20
+ data[:zipcode]
21
+ end
22
+
23
+ def city
24
+ data[:city]
25
+ end
26
+
27
+ def country
28
+ data[:country]
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ module Kentaa
2
+ module Api
3
+ module Responses
4
+ class Banner < Base
5
+ include Kentaa::Api::Responses::Resource
6
+
7
+ def initialize(response)
8
+ super(response)
9
+ end
10
+
11
+ def url
12
+ data[:url]
13
+ end
14
+
15
+ def text
16
+ data[:text]
17
+ end
18
+
19
+ def link
20
+ data[:link]
21
+ end
22
+
23
+ def locale
24
+ data[:locale]
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ module Kentaa
2
+ module Api
3
+ module Responses
4
+ class Base
5
+ attr_reader :data
6
+
7
+ def initialize(data)
8
+ @data = data
9
+ end
10
+
11
+ def error?
12
+ !message.nil?
13
+ end
14
+
15
+ def message
16
+ data[:message]
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,142 @@
1
+ require 'bigdecimal'
2
+ require 'time'
3
+
4
+ module Kentaa
5
+ module Api
6
+ module Responses
7
+ class Donation < Base
8
+ include Kentaa::Api::Responses::Resource
9
+
10
+ def initialize(response)
11
+ super(response[:donation] || response)
12
+ end
13
+
14
+ def segment_id
15
+ data[:segment_id]
16
+ end
17
+
18
+ def project_id
19
+ data[:project_id]
20
+ end
21
+
22
+ def team_id
23
+ data[:team_id]
24
+ end
25
+
26
+ def action_id
27
+ data[:action_id]
28
+ end
29
+
30
+ def first_name
31
+ data[:first_name]
32
+ end
33
+
34
+ def infix
35
+ data[:infix]
36
+ end
37
+
38
+ def last_name
39
+ data[:last_name]
40
+ end
41
+
42
+ def name
43
+ [first_name, infix, last_name].compact.join(" ")
44
+ end
45
+
46
+ def company
47
+ data[:company]
48
+ end
49
+
50
+ def email
51
+ data[:email]
52
+ end
53
+
54
+ def message
55
+ data[:message]
56
+ end
57
+
58
+ def newsletter?
59
+ data[:newsletter]
60
+ end
61
+
62
+ def device_type
63
+ data[:device_type]
64
+ end
65
+
66
+ def locale
67
+ data[:locale]
68
+ end
69
+
70
+ def amount
71
+ BigDecimal.new(data[:amount])
72
+ end
73
+
74
+ def transaction_costs
75
+ BigDecimal.new(data[:transaction_costs]) if data[:transaction_costs]
76
+ end
77
+
78
+ def registration_fee?
79
+ data[:registration_fee]
80
+ end
81
+
82
+ def registration_fee_amount
83
+ BigDecimal.new(data[:registration_fee_amount]) if data[:registration_fee_amount]
84
+ end
85
+
86
+ def total_amount
87
+ BigDecimal.new(data[:total_amount])
88
+ end
89
+
90
+ def invoicenumber
91
+ data[:invoicenumber]
92
+ end
93
+
94
+ def payment_method
95
+ data[:payment_method]
96
+ end
97
+
98
+ def payment_status
99
+ data[:payment_status]
100
+ end
101
+
102
+ def payment_status_at
103
+ Time.parse(data[:payment_status_at]) if data[:payment_status_at]
104
+ end
105
+
106
+ def transaction_id
107
+ data[:transaction_id]
108
+ end
109
+
110
+ def payment_id
111
+ data[:payment_id]
112
+ end
113
+
114
+ def target_url
115
+ data[:target_url]
116
+ end
117
+
118
+ def questions
119
+ @questions ||= begin
120
+ questions = []
121
+
122
+ if data[:questions]
123
+ data[:questions].each do |question|
124
+ questions << Kentaa::Api::Responses::Question.new(question)
125
+ end
126
+ end
127
+
128
+ questions
129
+ end
130
+ end
131
+
132
+ def reward
133
+ @reward ||= Kentaa::Api::Responses::Reward.new(data[:reward]) if data[:reward]
134
+ end
135
+
136
+ def address
137
+ @address ||= Kentaa::Api::Responses::Address.new(data[:address]) if data[:address]
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,34 @@
1
+ module Kentaa
2
+ module Api
3
+ module Responses
4
+ class Donations < Base
5
+ include Enumerable
6
+ include Kentaa::Api::Responses::Pagination
7
+
8
+ def initialize(response)
9
+ super(response)
10
+ end
11
+
12
+ def each(&block)
13
+ donations.each(&block)
14
+ end
15
+
16
+ private
17
+
18
+ def donations
19
+ @donations ||= begin
20
+ donations = []
21
+
22
+ if data[:donations]
23
+ data[:donations].each do |donation|
24
+ donations << Kentaa::Api::Responses::Donation.new(donation)
25
+ end
26
+ end
27
+
28
+ donations
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ module Kentaa
2
+ module Api
3
+ module Responses
4
+ class NewsletterSubscription < Base
5
+ include Kentaa::Api::Responses::Resource
6
+
7
+ def initialize(response)
8
+ super(response)
9
+ end
10
+
11
+ def segment_id
12
+ data[:segment_id]
13
+ end
14
+
15
+ def project_id
16
+ data[:project_id]
17
+ end
18
+
19
+ def email
20
+ data[:email]
21
+ end
22
+
23
+ def locale
24
+ data[:locale]
25
+ end
26
+
27
+ def subscription_url
28
+ data[:subscription_url]
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ module Kentaa
2
+ module Api
3
+ module Responses
4
+ class NewsletterSubscriptions < Base
5
+ include Enumerable
6
+ include Kentaa::Api::Responses::Pagination
7
+
8
+ def initialize(response)
9
+ super(response)
10
+ end
11
+
12
+ def each(&block)
13
+ newsletter_subscriptions.each(&block)
14
+ end
15
+
16
+ private
17
+
18
+ def newsletter_subscriptions
19
+ @newsletter_subscriptions ||= begin
20
+ newsletter_subscriptions = []
21
+
22
+ if data[:newsletter_subscriptions]
23
+ data[:newsletter_subscriptions].each do |newsletter_subscription|
24
+ newsletter_subscriptions << Kentaa::Api::Responses::NewsletterSubscription.new(newsletter_subscription)
25
+ end
26
+ end
27
+
28
+ newsletter_subscriptions
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ module Kentaa
2
+ module Api
3
+ module Responses
4
+ class Owner < Base
5
+ include Kentaa::Api::Responses::Resource
6
+
7
+ def initialize(response)
8
+ super(response)
9
+ end
10
+
11
+ def first_name
12
+ data[:first_name]
13
+ end
14
+
15
+ def infix
16
+ data[:infix]
17
+ end
18
+
19
+ def last_name
20
+ data[:last_name]
21
+ end
22
+
23
+ def name
24
+ [first_name, infix, last_name].compact.join(" ")
25
+ end
26
+
27
+ def email
28
+ data[:email]
29
+ end
30
+
31
+ def avatar_url
32
+ data[:avatar_url]
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,47 @@
1
+ module Kentaa
2
+ module Api
3
+ module Responses
4
+ module Pagination
5
+ def links
6
+ data[:links]
7
+ end
8
+
9
+ def pages
10
+ links[:pages] if links
11
+ end
12
+
13
+ def total_entries
14
+ data[:total_entries]
15
+ end
16
+
17
+ def total_pages
18
+ data[:total_pages]
19
+ end
20
+
21
+ def per_page
22
+ data[:per_page]
23
+ end
24
+
25
+ def current_page
26
+ data[:current_page]
27
+ end
28
+
29
+ def next_page
30
+ current_page + 1 if next_page?
31
+ end
32
+
33
+ def next_page?
34
+ current_page && current_page < total_pages
35
+ end
36
+
37
+ def previous_page
38
+ current_page - 1 if previous_page?
39
+ end
40
+
41
+ def previous_page?
42
+ current_page && current_page > 1
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ module Kentaa
2
+ module Api
3
+ module Responses
4
+ class Photo < Base
5
+ include Kentaa::Api::Responses::Resource
6
+
7
+ def initialize(response)
8
+ super(response)
9
+ end
10
+
11
+ def url
12
+ data[:url]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,102 @@
1
+ require 'bigdecimal'
2
+ require 'time'
3
+
4
+ module Kentaa
5
+ module Api
6
+ module Responses
7
+ class Project < Base
8
+ include Kentaa::Api::Responses::Resource
9
+
10
+ def initialize(response)
11
+ super(response[:project] || response)
12
+ end
13
+
14
+ def slug
15
+ data[:slug]
16
+ end
17
+
18
+ def segment_id
19
+ data[:segment_id]
20
+ end
21
+
22
+ def title
23
+ data[:title]
24
+ end
25
+
26
+ def description
27
+ data[:description]
28
+ end
29
+
30
+ def target_amount
31
+ data[:target_amount]
32
+ end
33
+
34
+ def total_amount
35
+ BigDecimal.new(data[:total_amount])
36
+ end
37
+
38
+ def total_donations
39
+ data[:total_donations]
40
+ end
41
+
42
+ def visible?
43
+ data[:visible]
44
+ end
45
+
46
+ def end_date
47
+ Time.parse(data[:end_date]) if data[:end_date]
48
+ end
49
+
50
+ def url
51
+ data[:url]
52
+ end
53
+
54
+ def donate_url
55
+ data[:donate_url]
56
+ end
57
+
58
+ def photos
59
+ @photos ||= begin
60
+ photos = []
61
+
62
+ if data[:photos]
63
+ data[:photos].each do |photo|
64
+ photos << Kentaa::Api::Responses::Photo.new(photo)
65
+ end
66
+ end
67
+
68
+ photos
69
+ end
70
+ end
71
+
72
+ def videos
73
+ @videos ||= begin
74
+ videos = []
75
+
76
+ if data[:videos]
77
+ data[:videos].each do |video|
78
+ videos << Kentaa::Api::Responses::Video.new(video)
79
+ end
80
+ end
81
+
82
+ videos
83
+ end
84
+ end
85
+
86
+ def questions
87
+ @questions ||= begin
88
+ questions = []
89
+
90
+ if data[:questions]
91
+ data[:questions].each do |question|
92
+ questions << Kentaa::Api::Responses::Question.new(question)
93
+ end
94
+ end
95
+
96
+ questions
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,34 @@
1
+ module Kentaa
2
+ module Api
3
+ module Responses
4
+ class Projects < Base
5
+ include Enumerable
6
+ include Kentaa::Api::Responses::Pagination
7
+
8
+ def initialize(response)
9
+ super(response)
10
+ end
11
+
12
+ def each(&block)
13
+ projects.each(&block)
14
+ end
15
+
16
+ private
17
+
18
+ def projects
19
+ @projects ||= begin
20
+ projects = []
21
+
22
+ if data[:projects]
23
+ data[:projects].each do |project|
24
+ projects << Kentaa::Api::Responses::Project.new(project)
25
+ end
26
+ end
27
+
28
+ projects
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end