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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b6fdaf28cb966314b02ab13f42c9c228a1ffedc3
4
+ data.tar.gz: 55b33406270da3c4d00cf7bcfb5c128b7101af92
5
+ SHA512:
6
+ metadata.gz: 6065be812cc0caa5758d9e4afbcbc1fc4ceda6f7bbba77225ffd5274a71a7e33c5d4d15973e04692e08664cd367027894e60c7b1dc493db98b07e46516765594
7
+ data.tar.gz: e0f51e23b4eb13700cedabebfa70ae3e99733340b3dc3ebd088bb164d1e356c6afc15ae20e05933bfea59351f0dc96ba0e3d2234d46f1879488cd8f7870858cf
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ .ruby-version
15
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,33 @@
1
+ # Kentaa-API RuboCop configuration
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.3
5
+ DisplayCopNames: true
6
+ DisplayStyleGuide: true
7
+
8
+ Metrics/AbcSize:
9
+ Enabled: false
10
+
11
+ Metrics/BlockLength:
12
+ Enabled: false
13
+
14
+ Metrics/LineLength:
15
+ Enabled: false
16
+
17
+ Metrics/MethodLength:
18
+ Enabled: false
19
+
20
+ Style/Documentation:
21
+ Enabled: false
22
+
23
+ Style/FrozenStringLiteralComment:
24
+ Enabled: false
25
+
26
+ Style/SafeNavigation:
27
+ Enabled: false
28
+
29
+ Style/StringLiterals:
30
+ Enabled: false
31
+
32
+ Style/SymbolArray:
33
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ rvm:
5
+ - 2.2.7
6
+ - 2.3.4
7
+ - 2.4.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kentaa-api.gemspec
4
+ gemspec
5
+
6
+ gem 'rubocop', '~> 0.48.1'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Peter Postma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # Kentaa API
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/kentaa-api.svg)](https://badge.fury.io/rb/kentaa-api)
4
+ [![Build Status](https://travis-ci.org/KentaaNL/kentaa-api.svg?branch=master)](https://travis-ci.org/KentaaNL/kentaa-api)
5
+ [![Code Climate](https://codeclimate.com/github/KentaaNL/kentaa-api/badges/gpa.svg)](https://codeclimate.com/github/KentaaNL/kentaa-api)
6
+
7
+ This gem provides a Ruby library for communicating with the [Kentaa API](https://api.kentaa.nl/v1/doc).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'kentaa-api'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install kentaa-api
24
+
25
+ ## Usage
26
+
27
+ ### Initialization
28
+
29
+ Create the client with your API key:
30
+
31
+ ```ruby
32
+ require 'kentaa/api'
33
+
34
+ client = Kentaa::Api::Client.new('your_api_key')
35
+ ```
36
+
37
+ ### Retrieving data
38
+
39
+ All endpoints use the same convention for retrieving data. The methods `list` and `all` are used for retrieving multiple resources. The method `get` is used for retrieving a single resource.
40
+
41
+ The `list` method on the endpoint returns an [Enumerable](https://ruby-doc.org/core-2.3.4/Enumerable.html) object:
42
+
43
+ ```ruby
44
+ actions = client.actions.list
45
+
46
+ actions.each { |a| puts a.title }
47
+ actions.first
48
+ ```
49
+
50
+ The results might be part of a paginated set. You can query the next page by doing:
51
+
52
+ ```ruby
53
+ actions = client.actions.list(page: actions.next_page) if actions.next_page?
54
+ ```
55
+
56
+ See also `Kentaa::Api::Responses::Pagination` for the available methods for pagination.
57
+
58
+ The `all` method on the endpoint returns an [Enumerator](https://ruby-doc.org/core-2.3.4/Enumerator.html) and will iterate automatically through all pages to retrieve the requested data.
59
+
60
+ ```ruby
61
+ actions = client.actions.all
62
+
63
+ actions.each { |a| puts a.title }
64
+ actions.first(100)
65
+ ```
66
+
67
+ ### Requests
68
+
69
+ Below a summary of the supported requests per endpoint.
70
+
71
+ #### Actions
72
+
73
+ ```ruby
74
+ actions = client.actions.list # get actions (paginated)
75
+ actions = client.actions.all # get all actions (non-paginated)
76
+
77
+ action = client.actions.get(1) # query action by ID
78
+ action = client.actions.get("john-doe") # query action by slug
79
+ ```
80
+
81
+ See also the [Kentaa API documention](https://api.kentaa.nl/v1/doc/actions).
82
+
83
+ #### Donations
84
+
85
+ ```ruby
86
+ donations = client.donations.list # get donations (paginated)
87
+ donations = client.donations.all # get all donations (non-paginated)
88
+
89
+ donation = client.donations.get(1) # query donation by ID
90
+ ```
91
+
92
+ See also the [Kentaa API documention](https://api.kentaa.nl/v1/doc/donations).
93
+
94
+ #### Newsletter subscriptions
95
+
96
+ ```ruby
97
+ newsletter_subscriptions = client.newsletter_subscriptions.all # get newsletter subscriptions (paginated)
98
+ newsletter_subscriptions = client.newsletter_subscriptions.list # get all newsletter subscriptions (non-paginated)
99
+ ```
100
+
101
+ See also the [Kentaa API documention](https://api.kentaa.nl/v1/doc/newsletter-subscriptions).
102
+
103
+ #### Projects
104
+
105
+ ```ruby
106
+ projects = client.projects.list # get projects (paginated)
107
+ projects = client.projects.all # get all projects (non-paginated)
108
+
109
+ project = client.projects.get(1) # query project by ID
110
+ project = client.projects.get("project") # query project by slug
111
+ ```
112
+
113
+ See also the [Kentaa API documention](https://api.kentaa.nl/v1/doc/projects).
114
+
115
+ #### Segments
116
+
117
+ ```ruby
118
+ segments = client.segments.list # get segments (paginated)
119
+ segments = client.segments.all # get all segments (non-paginated)
120
+
121
+ segment = client.segments.get(1) # query segment by ID
122
+ ```
123
+
124
+ See also the [Kentaa API documention](https://api.kentaa.nl/v1/doc/segments).
125
+
126
+ #### Sites
127
+
128
+ The only method here is `current`, since there is only one site.
129
+
130
+ ```ruby
131
+ site = client.sites.current # get the current site
132
+ ```
133
+
134
+ See also the [Kentaa API documention](https://api.kentaa.nl/v1/doc/sites).
135
+
136
+ #### Teams
137
+
138
+ ```ruby
139
+ teams = client.teams.list # get teams (paginated)
140
+ teams = client.teams.all # get all teams (non-paginated)
141
+
142
+ team = client.teams.get(1) # query team by ID
143
+ team = client.teams.get("team") # query team by slug
144
+ ```
145
+
146
+ See also the [Kentaa API documention](https://api.kentaa.nl/v1/doc/teams).
147
+
148
+
149
+ ## Development
150
+
151
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
152
+
153
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
154
+
155
+ ## Contributing
156
+
157
+ Bug reports and pull requests are welcome on GitHub at https://github.com/KentaaNL/kentaa-api.
158
+
159
+
160
+ ## License
161
+
162
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
163
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:rubocop)
7
+
8
+ task default: [:spec, :rubocop]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kentaa/api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'kentaa/api/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "kentaa-api"
9
+ spec.version = Kentaa::Api::VERSION
10
+ spec.authors = ["Kentaa"]
11
+ spec.email = ["support@kentaa.nl"]
12
+
13
+ spec.summary = "Ruby library for communicating with the Kentaa API"
14
+ spec.homepage = "https://www.kentaa.nl"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.required_ruby_version = ">= 2.0.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "webmock", "~> 2.3", ">= 2.3.2"
30
+ end
@@ -0,0 +1,37 @@
1
+ module Kentaa
2
+ module Api
3
+ class Client
4
+ def initialize(api_key, options = {})
5
+ @http = Kentaa::Api::Http.new(api_key, options)
6
+ end
7
+
8
+ def actions
9
+ Kentaa::Api::Requests::Actions.new(@http)
10
+ end
11
+
12
+ def donations
13
+ Kentaa::Api::Requests::Donations.new(@http)
14
+ end
15
+
16
+ def newsletter_subscriptions
17
+ Kentaa::Api::Requests::NewsletterSubscriptions.new(@http)
18
+ end
19
+
20
+ def projects
21
+ Kentaa::Api::Requests::Projects.new(@http)
22
+ end
23
+
24
+ def segments
25
+ Kentaa::Api::Requests::Segments.new(@http)
26
+ end
27
+
28
+ def sites
29
+ Kentaa::Api::Requests::Sites.new(@http)
30
+ end
31
+
32
+ def teams
33
+ Kentaa::Api::Requests::Teams.new(@http)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,47 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ module Kentaa
6
+ module Api
7
+ class Http
8
+ LIVE_URL = "https://api.kentaa.nl/v1/".freeze
9
+ TEST_URL = "https://api.kentaa.staatklaar.nu/v1/".freeze
10
+
11
+ def initialize(api_key, options = {})
12
+ @api_key = api_key
13
+ @options = options
14
+ end
15
+
16
+ def get(path, params = {})
17
+ uri = URI.parse(File.join(api_url, path))
18
+ uri.query = URI.encode_www_form(params) unless params.empty?
19
+
20
+ request = Net::HTTP::Get.new(uri)
21
+ request["X-Api-Key"] = @api_key
22
+
23
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
24
+ http.request(request)
25
+ end
26
+
27
+ begin
28
+ JSON.parse(response.body, symbolize_names: true)
29
+ rescue JSON::ParserError => ex
30
+ {
31
+ message: "Unable to parse JSON: #{ex.message}"
32
+ }
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def api_url
39
+ if @options[:test]
40
+ TEST_URL
41
+ else
42
+ LIVE_URL
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ module Kentaa
2
+ module Api
3
+ module Requests
4
+ class Actions < Base
5
+ include Kentaa::Api::Requests::All
6
+
7
+ def list(options = {})
8
+ response = http.get("/actions", options)
9
+ Kentaa::Api::Responses::Actions.new(response)
10
+ end
11
+
12
+ def get(id)
13
+ response = http.get("/actions/#{id}")
14
+ Kentaa::Api::Responses::Action.new(response)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module Kentaa
2
+ module Api
3
+ module Requests
4
+ module All
5
+ def all(options = {})
6
+ enumerator = Enumerator.new do |yielder|
7
+ page = 1
8
+
9
+ loop do
10
+ response = list(options.merge(page: page))
11
+ response.each { |item| yielder.yield item } unless response.error?
12
+
13
+ raise StopIteration unless response.next_page?
14
+
15
+ page = response.next_page
16
+ end
17
+ end
18
+
19
+ enumerator.lazy
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ module Kentaa
2
+ module Api
3
+ module Requests
4
+ class Base
5
+ attr_reader :http
6
+
7
+ def initialize(http)
8
+ @http = http
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ module Kentaa
2
+ module Api
3
+ module Requests
4
+ class Donations < Base
5
+ include Kentaa::Api::Requests::All
6
+
7
+ def list(options = {})
8
+ response = http.get("/donations", options)
9
+ Kentaa::Api::Responses::Donations.new(response)
10
+ end
11
+
12
+ def get(id)
13
+ response = http.get("/donations/#{id}")
14
+ Kentaa::Api::Responses::Donation.new(response)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module Kentaa
2
+ module Api
3
+ module Requests
4
+ class NewsletterSubscriptions < Base
5
+ include Kentaa::Api::Requests::All
6
+
7
+ def list(options = {})
8
+ response = http.get("/newsletter-subscriptions", options)
9
+ Kentaa::Api::Responses::NewsletterSubscriptions.new(response)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ module Kentaa
2
+ module Api
3
+ module Requests
4
+ class Projects < Base
5
+ include Kentaa::Api::Requests::All
6
+
7
+ def list(options = {})
8
+ response = http.get("/projects", options)
9
+ Kentaa::Api::Responses::Projects.new(response)
10
+ end
11
+
12
+ def get(id)
13
+ response = http.get("/projects/#{id}")
14
+ Kentaa::Api::Responses::Project.new(response)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Kentaa
2
+ module Api
3
+ module Requests
4
+ class Segments < Base
5
+ include Kentaa::Api::Requests::All
6
+
7
+ def list(options = {})
8
+ response = http.get("/segments", options)
9
+ Kentaa::Api::Responses::Segments.new(response)
10
+ end
11
+
12
+ def get(id)
13
+ response = http.get("/segments/#{id}")
14
+ Kentaa::Api::Responses::Segment.new(response)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ module Kentaa
2
+ module Api
3
+ module Requests
4
+ class Sites < Base
5
+ def current
6
+ response = http.get("/sites/current")
7
+ Kentaa::Api::Responses::Site.new(response)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module Kentaa
2
+ module Api
3
+ module Requests
4
+ class Teams < Base
5
+ include Kentaa::Api::Requests::All
6
+
7
+ def list(options = {})
8
+ response = http.get("/teams", options)
9
+ Kentaa::Api::Responses::Teams.new(response)
10
+ end
11
+
12
+ def get(id)
13
+ response = http.get("/teams/#{id}")
14
+ Kentaa::Api::Responses::Team.new(response)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end