power_api 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +104 -0
  3. data/.circleci/setup-rubygems.sh +3 -0
  4. data/.rubocop.yml +0 -1
  5. data/.ruby-version +1 -1
  6. data/CHANGELOG.md +6 -1
  7. data/Gemfile.lock +170 -150
  8. data/README.md +39 -31
  9. data/app/controllers/power_api/base_controller.rb +0 -1
  10. data/lib/power_api/version.rb +1 -1
  11. data/power_api.gemspec +3 -2
  12. data/spec/dummy/Rakefile +1 -1
  13. data/spec/dummy/app/assets/config/manifest.js +0 -2
  14. data/spec/dummy/app/controllers/application_controller.rb +0 -1
  15. data/spec/dummy/app/{assets/javascripts → javascript/packs}/application.js +2 -0
  16. data/spec/dummy/app/jobs/application_job.rb +5 -0
  17. data/spec/dummy/app/views/layouts/application.html.erb +3 -2
  18. data/spec/dummy/bin/rails +2 -2
  19. data/spec/dummy/bin/rake +2 -2
  20. data/spec/dummy/bin/setup +7 -12
  21. data/spec/dummy/config.ru +2 -1
  22. data/spec/dummy/config/application.rb +12 -16
  23. data/spec/dummy/config/boot.rb +1 -1
  24. data/spec/dummy/config/cable.yml +2 -2
  25. data/spec/dummy/config/database.yml +8 -16
  26. data/spec/dummy/config/environment.rb +1 -1
  27. data/spec/dummy/config/environments/development.rb +28 -6
  28. data/spec/dummy/config/environments/production.rb +45 -16
  29. data/spec/dummy/config/environments/test.rb +24 -7
  30. data/spec/dummy/config/initializers/assets.rb +0 -2
  31. data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -3
  32. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  33. data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -1
  34. data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
  35. data/spec/dummy/config/locales/en.yml +1 -1
  36. data/spec/dummy/config/puma.rb +14 -27
  37. data/spec/dummy/config/storage.yml +34 -0
  38. metadata +90 -85
  39. data/.hound.yml +0 -4
  40. data/.travis.yml +0 -16
  41. data/app/controllers/concerns/api/versioned.rb +0 -36
  42. data/spec/dummy/app/assets/javascripts/cable.js +0 -13
  43. data/spec/dummy/app/controllers/concerns/api/versioned_spec.rb +0 -64
  44. data/spec/dummy/bin/bundle +0 -3
  45. data/spec/dummy/bin/update +0 -29
  46. data/spec/dummy/bin/yarn +0 -11
  47. data/spec/dummy/config/secrets.yml +0 -32
  48. data/spec/dummy/config/spring.rb +0 -6
data/.hound.yml DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- ruby:
3
- enabled: true
4
- config_file: ".rubocop.yml"
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.5.0
5
- script:
6
- - RAILS_ENV=test bundle exec rake db:create db:migrate
7
- - bundle exec rspec spec
8
- before_install: gem install bundler -v 1.17.3
9
- deploy:
10
- provider: rubygems
11
- api_key:
12
- secure: GaNPiRBIHwFsuZGh+3HGiW+tdpjRIh9j4hAeXy8qqIDyXuOknjbdjYFE40RJHuxfyc76Ajx0Wi6ybHYyD6BEQcG7iLZKHVbzr/EAQCQejCCO1TkuNS8loVXNh65EPcl1XbJPURBliG1fSCOSPHRnXMK7SxUX0flnewvgLo0ZDRNY5hkc/Pyt+MBElUnzgmikrolhOzUHCMyzo9BPlem0ToCCtJuruM5EQQhPRrbPuYkJlGty4cqcyyLtPQwe0sgARbiAbYIa+vxi0mvYxf0s2HZwpBqIa3BkgL6ozdOVBk2a0hgjEQbkeGSRCo+R4fgtb4QHB5OamTKO6HF5ceECNe76eR4P8GYp6LBNj3R/sUJb8Fmp/7xs9q5JYkJ6+RKJzpLWFOd7U0xAsC9D3r/PDJHAuzjbiAi/f9C0nD0UQgPtLXeytp85W71bRd7Dommk785kphporaM7xteUWYMK0Jmo02zRa8qdo+fqFJQQ7lFovSHQO+boIBI3MnOHhlz54XFnkPJkfM9NIrCq2zOlxtJgW4B1Zuw93z7zFUfPOEekMoqAXR/tCKpdV1e5XhikSCNSWv1EHPZaB+IsaOzWEPY8rcA/l47gWXoa9Mgv8rTzj489EzoXrqXv/8yb6TSBOezTypt6MNYqiABnRv43mo2CvtlG5ERQM3izWC6vo00=
13
- gem: power_api
14
- on:
15
- tags: true
16
- repo: platanus/power_api
@@ -1,36 +0,0 @@
1
- module Api::Versioned
2
- extend ActiveSupport::Concern
3
-
4
- DEFAULT_API_VERSIONS = 1
5
-
6
- included do
7
- before_action :check_api_version!
8
- after_action :add_version_to_content_type
9
- end
10
-
11
- private
12
-
13
- def available_api_versions
14
- ENV.fetch("AVAILABLE_API_VERSIONS", DEFAULT_API_VERSIONS)
15
- end
16
-
17
- def check_api_version!
18
- return if (1..available_api_versions) === version_number
19
-
20
- raise ::PowerApi::InvalidVersion.new("invalid API version")
21
- end
22
-
23
- def version_number
24
- @version_number ||= begin
25
- v = request.headers["Accept"].to_s.match(/version=(\d+)/)&.captures&.first.to_i
26
- v.zero? ? DEFAULT_API_VERSIONS : v
27
- end
28
- end
29
-
30
- def add_version_to_content_type
31
- content_type_header = response.headers["Content-Type"]
32
- parts = !content_type_header ? [] : content_type_header.to_s.split(";").map(&:strip)
33
- parts << "version=#{@version_number}"
34
- response.headers["Content-Type"] = parts.join("; ")
35
- end
36
- end
@@ -1,13 +0,0 @@
1
- // Action Cable provides the framework to deal with WebSockets in Rails.
2
- // You can generate new channels where WebSocket features live using the `rails generate channel` command.
3
- //
4
- //= require action_cable
5
- //= require_self
6
- //= require_tree ./channels
7
-
8
- (function() {
9
- this.App || (this.App = {});
10
-
11
- App.cable = ActionCable.createConsumer();
12
-
13
- }).call(this);
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Api::Versioned', type: :controller do
4
- let(:available_versions) { 1 }
5
- let(:headers) do
6
- {}
7
- end
8
-
9
- before do
10
- allow(ENV).to receive(:fetch).with(
11
- "AVAILABLE_API_VERSIONS", 1
12
- ).and_return(available_versions)
13
-
14
- routes.draw { get :action, to: "anonymous#action" }
15
- request.headers.merge!(headers) unless headers.blank?
16
- get :action
17
- end
18
-
19
- controller do
20
- include ::Api::Versioned
21
- include ::Api::Error
22
-
23
- def action
24
- head :ok
25
- end
26
- end
27
-
28
- context "with default version" do
29
- it { expect(response.status).to eq(200) }
30
- it { expect(response.headers["Content-Type"]).to eq("text/html; version=1") }
31
-
32
- context "with invalid version header" do
33
- let(:headers) do
34
- {
35
- "Accept" => "version=2"
36
- }
37
- end
38
-
39
- it { expect(response.status).to eq(400) }
40
- end
41
- end
42
-
43
- context "with multiple versions" do
44
- let(:available_versions) { 2 }
45
- let(:headers) do
46
- {
47
- "Accept" => "version=2"
48
- }
49
- end
50
-
51
- it { expect(response.status).to eq(200) }
52
- it { expect(response.headers["Content-Type"]).to eq("text/html; version=2") }
53
-
54
- context "with invalid version header" do
55
- let(:headers) do
56
- {
57
- "Accept" => "version=3"
58
- }
59
- end
60
-
61
- it { expect(response.status).to eq(400) }
62
- end
63
- end
64
- end
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
- load Gem.bin_path('bundler', 'bundle')
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'pathname'
3
- require 'fileutils'
4
- include FileUtils
5
-
6
- # path to your application root.
7
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
-
9
- def system!(*args)
10
- system(*args) || abort("\n== Command #{args} failed ==")
11
- end
12
-
13
- chdir APP_ROOT do
14
- # This script is a way to update your development environment automatically.
15
- # Add necessary update steps to this file.
16
-
17
- puts '== Installing dependencies =='
18
- system! 'gem install bundler --conservative'
19
- system('bundle check') || system!('bundle install')
20
-
21
- puts "\n== Updating database =="
22
- system! 'bin/rails db:migrate'
23
-
24
- puts "\n== Removing old logs and tempfiles =="
25
- system! 'bin/rails log:clear tmp:clear'
26
-
27
- puts "\n== Restarting application server =="
28
- system! 'bin/rails restart'
29
- end
data/spec/dummy/bin/yarn DELETED
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env ruby
2
- VENDOR_PATH = File.expand_path('..', __dir__)
3
- Dir.chdir(VENDOR_PATH) do
4
- begin
5
- exec "yarnpkg #{ARGV.join(" ")}"
6
- rescue Errno::ENOENT
7
- $stderr.puts "Yarn executable was not detected in the system."
8
- $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9
- exit 1
10
- end
11
- end
@@ -1,32 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key is used for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
-
6
- # Make sure the secret is at least 30 characters and all random,
7
- # no regular words or you'll be exposed to dictionary attacks.
8
- # You can use `rails secret` to generate a secure secret key.
9
-
10
- # Make sure the secrets in this file are kept private
11
- # if you're sharing your code publicly.
12
-
13
- # Shared secrets are available across all environments.
14
-
15
- # shared:
16
- # api_key: a1B2c3D4e5F6
17
-
18
- # Environmental secrets are only available for that specific environment.
19
-
20
- development:
21
- secret_key_base: a5a2020513b8f39701d582ebbaa944f8f08e785d753734480a55bcead376273d016b61f2669d3897ef16eeac08c714aaca718ea9750ece793be7dba48f0d8dd1
22
-
23
- test:
24
- secret_key_base: 6417e0708df89fc50a8099e9655f044b679843ceda904b88c23a7c4762143ee8dfa411d5310ab048023f542b0139b976b67e76ad839bab1e418f5c06b368429c
25
-
26
- # Do not keep production secrets in the unencrypted secrets file.
27
- # Instead, either read values from the environment.
28
- # Or, use `bin/rails secrets:setup` to configure encrypted secrets
29
- # and move the `production:` environment over there.
30
-
31
- production:
32
- secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -1,6 +0,0 @@
1
- %w(
2
- .ruby-version
3
- .rbenv-vars
4
- tmp/restart.txt
5
- tmp/caching-dev.txt
6
- ).each { |path| Spring.watch(path) }