my_api_client 0.14.0.pre → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +90 -35
  3. data/.envrc.skeleton +1 -0
  4. data/.rubocop.yml +5 -1
  5. data/.rubocop_todo.yml +1 -1
  6. data/CHANGELOG.md +10 -1
  7. data/Gemfile.lock +6 -6
  8. data/example/api_clients/application_api_client.rb +21 -0
  9. data/example/api_clients/my_error_api_client.rb +34 -0
  10. data/example/api_clients/my_errors.rb +27 -0
  11. data/example/api_clients/my_rest_api_client.rb +42 -0
  12. data/example/api_clients/my_status_api_client.rb +22 -0
  13. data/lib/my_api_client/rspec/matchers/request_to.rb +3 -4
  14. data/lib/my_api_client/version.rb +1 -1
  15. data/my_api/.envrc.skeleton +3 -0
  16. data/my_api/.gitignore +14 -0
  17. data/my_api/.jetskeep +1 -0
  18. data/my_api/.rspec +3 -0
  19. data/my_api/.ruby-version +1 -0
  20. data/my_api/Gemfile +23 -0
  21. data/my_api/Gemfile.lock +243 -0
  22. data/my_api/Procfile +7 -0
  23. data/my_api/README.md +48 -0
  24. data/my_api/Rakefile +4 -0
  25. data/my_api/app/controllers/application_controller.rb +5 -0
  26. data/my_api/app/controllers/error_controller.rb +21 -0
  27. data/my_api/app/controllers/rest_controller.rb +60 -0
  28. data/my_api/app/controllers/status_controller.rb +11 -0
  29. data/my_api/app/helpers/application_helper.rb +5 -0
  30. data/my_api/app/jobs/application_job.rb +7 -0
  31. data/my_api/app/models/application_item.rb +5 -0
  32. data/my_api/config.ru +7 -0
  33. data/my_api/config/application.rb +73 -0
  34. data/my_api/config/dynamodb.yml +22 -0
  35. data/my_api/config/environments/development.rb +9 -0
  36. data/my_api/config/environments/production.rb +11 -0
  37. data/my_api/config/environments/test.rb +9 -0
  38. data/my_api/config/routes.rb +16 -0
  39. data/my_api/db/.gitkeep +0 -0
  40. data/my_api/public/404.html +67 -0
  41. data/my_api/public/422.html +67 -0
  42. data/my_api/public/500.html +66 -0
  43. data/my_api/public/favicon.ico +0 -0
  44. data/my_api/public/index.html +91 -0
  45. data/my_api/spec/controllers/error_controller_spec.rb +43 -0
  46. data/my_api/spec/controllers/rest_controller_spec.rb +81 -0
  47. data/my_api/spec/controllers/status_controller_spec.rb +47 -0
  48. data/my_api/spec/fixtures/payloads/posts-index.json +51 -0
  49. data/my_api/spec/fixtures/payloads/posts-show.json +53 -0
  50. data/my_api/spec/spec_helper.rb +26 -0
  51. metadata +45 -4
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jets'
4
+ Jets.load_tasks
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The root of the controller
4
+ class ApplicationController < Jets::Controller::Base
5
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # THe error code API
4
+ class ErrorController < ApplicationController
5
+ # GET error/:code
6
+ def show
7
+ render status: :bad_request, json: error_response
8
+ end
9
+
10
+ private
11
+
12
+ def error_response
13
+ code = params[:code].to_i
14
+ {
15
+ error: {
16
+ code: code,
17
+ message: "You requested error code: #{code}",
18
+ },
19
+ }
20
+ end
21
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A REST API
4
+ class RestController < ApplicationController
5
+ # GET rest
6
+ def index
7
+ result = params[:order] == 'desc' ? posts.reverse : posts
8
+ render status: :ok, json: result
9
+ end
10
+
11
+ # GET rest/:id
12
+ def show
13
+ render status: :ok, json: find_post(id: id)
14
+ end
15
+
16
+ # POST rest
17
+ def create
18
+ render status: :created,
19
+ json: create_post(title: params[:title])
20
+ end
21
+
22
+ # POST/PUT/PATCH rest/:id
23
+ def update
24
+ render status: :ok,
25
+ json: update_post(id: id, title: params[:title])
26
+ end
27
+
28
+ # DELETE rest/:id
29
+ def delete
30
+ render status: :no_content
31
+ end
32
+
33
+ private
34
+
35
+ def id
36
+ params[:id].to_i
37
+ end
38
+
39
+ def posts
40
+ [
41
+ { id: 1, title: 'Title 1' },
42
+ { id: 2, title: 'Title 2' },
43
+ { id: 3, title: 'Title 3' },
44
+ ]
45
+ end
46
+
47
+ def find_post(id:)
48
+ posts.find { |p| p[:id] == id }
49
+ end
50
+
51
+ def create_post(title:)
52
+ { id: 4, title: title }
53
+ end
54
+
55
+ def update_post(id:, title:)
56
+ find_post(id: id).tap do |post|
57
+ post[:title] = title
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # THe status API
4
+ class StatusController < ApplicationController
5
+ # GET status/:status
6
+ def show
7
+ status = params[:status].to_i
8
+ render status: status,
9
+ json: { message: "You requested status code: #{status}" }
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The root of the helper module
4
+ module ApplicationHelper
5
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The root of the job class
4
+ class ApplicationJob < Jets::Job::Base
5
+ # Adjust to increase the default timeout for all Job classes
6
+ class_timeout 60
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The root of the model
4
+ class ApplicationItem < Dynomite::Item
5
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is used by Rack-based servers to start the application.
4
+
5
+ require 'jets'
6
+ Jets.boot
7
+ run Jets.application
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ Jets.application.configure do
4
+ config.project_name = 'my_api'
5
+ config.mode = 'api'
6
+
7
+ config.prewarm.enable = true # default is true
8
+ # config.prewarm.rate = '30 minutes' # default is '30 minutes'
9
+ # config.prewarm.concurrency = 2 # default is 2
10
+ # config.prewarm.public_ratio = 3 # default is 3
11
+
12
+ # config.env_extra = 2 # can also set this with JETS_ENV_EXTRA
13
+ # config.autoload_paths = []
14
+
15
+ # config.asset_base_url = 'https://cloudfront.domain.com/assets' # example
16
+
17
+ # config.cors = true # for '*'' # defaults to false
18
+ # config.cors = '*.mydomain.com' # for specific domain
19
+
20
+ # config.function.timeout = 30 # defaults to 30
21
+ # config.function.role = "arn:aws:iam::#{Jets.aws.account}:role/service-role/pre-created"
22
+ # config.function.memory_size = 1536
23
+
24
+ # Default is 'EDGE'
25
+ # https://docs.aws.amazon.com/apigateway/api-reference/link-relation/restapi-create/#endpointConfiguration
26
+ # config.api.endpoint_type = 'PRIVATE'
27
+
28
+ # config.function.environment = {
29
+ # global_app_key1: "global_app_value1",
30
+ # global_app_key2: "global_app_value2",
31
+ # }
32
+ # More examples:
33
+ # config.function.dead_letter_config = { target_arn: "arn" }
34
+ # config.function.vpc_config = {
35
+ # security_group_ids: %w[sg-1 sg-2],
36
+ # subnet_ids: %w[subnet-1 subnet-2],
37
+ # }
38
+ # The config.function settings to the CloudFormation Lambda Function properties.
39
+ # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html
40
+ # Underscored format can be used for keys to make it look more ruby-ish.
41
+
42
+ # Assets settings
43
+ # The config.assets.folders are folders within the public folder that will be set
44
+ # to public-read on s3 and served directly. IE: public/assets public/images public/packs
45
+ # config.assets.folders = %w[assets images packs]
46
+ # config.assets.max_age = 3600 # when to expire assets
47
+ #
48
+ # # IE: "public, max-age=3600" # override max_age for more fine-grain control.
49
+ # config.assets.cache_control = nil
50
+ #
51
+ # IE: https://cloudfront.com/my/base/path, defaults to the s3 bucket url
52
+ # IE: https://s3-us-west-2.amazonaws.com/demo-dev-s3bucket-1inlzkvujq8zb
53
+ # config.assets.base_url = nil
54
+ #
55
+
56
+ # config.api.endpoint_type = 'PRIVATE' # Default is 'EDGE' https://amzn.to/2r0Iu2L
57
+ # config.api.authorization_type = "AWS_IAM" # default is 'NONE' https://amzn.to/2qZ7zLh
58
+
59
+ # More info: http://rubyonjets.com/docs/routing/custom-domain/
60
+ # config.domain.hosted_zone_name = "example.com"
61
+ # us-west-2 REGIONAL endpoint - takes 2 minutes
62
+ # config.domain.cert_arn = "arn:aws:acm:us-west-2:112233445566:certificate/8d8919ce-a710-4050-976b-b33da991e123"
63
+ # us-east-1 EDGE endpoint - takes 10-15 minutes
64
+ # config.domain.cert_arn = "arn:aws:acm:us-east-1:112233445566:certificate/d68472ba-04f8-45ba-b9db-14f839d57123"
65
+ # config.domain.endpoint_type = "EDGE"
66
+
67
+ # By default logger needs to log to $stderr for CloudWatch to receive Lambda messages, but for
68
+ # local testing environment you may want to log these messages to 'test.log' file to keep your
69
+ # testing suite output readable.
70
+ # config.logger = Jets::Logger.new($strerr)
71
+
72
+ config.controllers.default_protect_from_forgery = false
73
+ end
@@ -0,0 +1,22 @@
1
+ # Jets::Config.project_namespace is special value results in using the project namespace. Example :
2
+ # table_namespace: <%= Jets.config.project_namespace %>
3
+ # This is the default value.
4
+
5
+ development:
6
+ table_namespace: <%= Jets.config.table_namespace %>
7
+ # More examples:
8
+ # table_namespace: demo-dev
9
+
10
+ endpoint: http://localhost:8000 # comment out if want to test with real dynamodb
11
+ # on AWS. You can also set the DYNAMODB_ENDPOINT environment variable.
12
+ # You can also are actually deploying a development environment is to
13
+ # change bin/server and export DYNAMODB_ENDPOINT=http://localhost:8000 at the top
14
+ # there.
15
+
16
+ test:
17
+ # table_namespace: proj # do not include the env
18
+ endpoint: http://localhost:8000
19
+ table_namespace: <%= Jets.config.table_namespace %>
20
+
21
+ production:
22
+ table_namespace: <%= Jets.config.table_namespace %>
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ Jets.application.configure do
4
+ # Example:
5
+ # config.function.memory_size = 1536
6
+
7
+ # config.action_mailer.raise_delivery_errors = false
8
+ # Docs: http://rubyonjets.com/docs/email-sending/
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ Jets.application.configure do
4
+ # Example:
5
+ # config.function.memory_size = 2048
6
+
7
+ # Ignore bad email addresses and do not raise email delivery errors.
8
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
9
+ # Docs: http://rubyonjets.com/docs/email-sending/
10
+ # config.action_mailer.raise_delivery_errors = false
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ Jets.application.configure do
4
+ # Tell Action Mailer not to deliver emails to the real world.
5
+ # The :test delivery method accumulates sent emails in the
6
+ # ActionMailer::Base.deliveries array.
7
+ # Docs: http://rubyonjets.com/docs/email-sending/
8
+ config.action_mailer.delivery_method = :test
9
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ Jets.application.routes.draw do
4
+ root 'jets/public#show'
5
+
6
+ resources 'rest', only: %i[index show create update delete]
7
+
8
+ get 'status/:status', to: 'status#show'
9
+ get 'error/:code', to: 'error#show'
10
+
11
+ # The jets/public#show controller can serve static utf8 content out of the public folder.
12
+ # Note, as part of the deploy process Jets uploads files in the public folder to s3
13
+ # and serves them out of s3 directly. S3 is well suited to serve static assets.
14
+ # More info here: https://rubyonjets.com/docs/extras/assets-serving/
15
+ any '*catchall', to: 'jets/public#show'
16
+ end
File without changes
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>