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
Binary file
@@ -0,0 +1,91 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Ruby on Jets</title>
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width">
7
+ <style type="text/css" media="screen" charset="utf-8">
8
+ body {
9
+ text-align: center;
10
+ margin: 0;
11
+ }
12
+ img {
13
+ max-width: 320px;
14
+ }
15
+ .container {
16
+ max-width: 648px;
17
+ }
18
+ @media (min-width: 768px) {
19
+ img {
20
+ max-width: none;
21
+ }
22
+ .container {
23
+ max-width: none;
24
+ }
25
+ }
26
+
27
+ .header {
28
+ padding: 20px;
29
+ /*background-color: #b81513;*/
30
+ /*color: white;*/
31
+ }
32
+ .title {
33
+ font-size: 1.5em;
34
+ }
35
+ @media (max-width: 500px) {
36
+ .title {
37
+ font-size: 1.3em;
38
+ }
39
+ }
40
+ .intro {
41
+ text-align: left;
42
+ font-size: large;
43
+ margin: 0 auto;
44
+ padding: 0 20px;
45
+ max-width: 640px;
46
+ }
47
+ pre, code {
48
+ padding: 0;
49
+ margin: 0;
50
+ }
51
+ pre {
52
+ margin-left: 20px;
53
+ width: 99%;
54
+ overflow: auto;
55
+ }
56
+ @media (max-width: 500px) {
57
+ pre {
58
+ margin-left: -30px;
59
+ font-size: 0.8em;
60
+ }
61
+ }
62
+ </style>
63
+ </head>
64
+
65
+ <body>
66
+ <div class="container">
67
+ <header class="header">
68
+ <img src="https://s3.amazonaws.com/jets-public/jets/images/jets.png" class="logo" alt="logo" />
69
+ <h1 class="title">Welcome and congrats!<br /> Jets is running.</h1>
70
+ </header>
71
+ <div class="intro">
72
+ <p>
73
+ To get started:
74
+ </p>
75
+ <div class="code"><pre><code>
76
+ $ jets generate scaffold post title:string
77
+ $ jets db:create db:migrate
78
+ $ jets server
79
+ $ open http://localhost:8888/posts
80
+ $ jets help
81
+ </code></pre></div>
82
+ <p>More on info: <a href="http://rubyonjets.com">rubyonjets.com</a></p>
83
+ <p>Also check out the <a href="http://rubyonjets.com/reference">Jets CLI reference</a>.</p>
84
+ </div>
85
+ <p class="version">
86
+ <strong>Jets version:</strong> 2.3.13<br />
87
+ <strong>Ruby version:</strong> 2.5.3
88
+ </p>
89
+ </div>
90
+ </body>
91
+ </html>
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe ErrorController, type: :controller do
4
+ describe '#show' do
5
+ context 'when request error code 10' do
6
+ let(:code) { 10 }
7
+
8
+ let(:expected_response) do
9
+ {
10
+ error: {
11
+ code: code,
12
+ message: 'You requested error code: 10',
13
+ },
14
+ }.to_json
15
+ end
16
+
17
+ it 'returns 400 Bad request with error code 10' do
18
+ get '/error/:code', code: code
19
+ expect(response.status).to eq 400
20
+ expect(response.body).to eq expected_response
21
+ end
22
+ end
23
+
24
+ context 'when request error code 20' do
25
+ let(:code) { 20 }
26
+
27
+ let(:expected_response) do
28
+ {
29
+ error: {
30
+ code: code,
31
+ message: 'You requested error code: 20',
32
+ },
33
+ }.to_json
34
+ end
35
+
36
+ it 'returns 400 Bad request with error code 20' do
37
+ get '/error/:code', code: code
38
+ expect(response.status).to eq 400
39
+ expect(response.body).to eq expected_response
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe RestController, type: :controller do
4
+ describe '#index' do
5
+ context 'with order = asc' do
6
+ let(:array_of_posts) do
7
+ [
8
+ { id: 1, title: 'Title 1' },
9
+ { id: 2, title: 'Title 2' },
10
+ { id: 3, title: 'Title 3' },
11
+ ].to_json
12
+ end
13
+
14
+ it 'returns an array of posts ordered by id' do
15
+ get '/rest', order: 'asc'
16
+ expect(response.status).to eq 200
17
+ expect(response.body).to eq array_of_posts
18
+ end
19
+ end
20
+
21
+ context 'with order = desc' do
22
+ let(:array_of_posts) do
23
+ [
24
+ { id: 3, title: 'Title 3' },
25
+ { id: 2, title: 'Title 2' },
26
+ { id: 1, title: 'Title 1' },
27
+ ].to_json
28
+ end
29
+
30
+ it 'returns an array of posts reverse ordered by id' do
31
+ get '/rest', order: 'desc'
32
+ expect(response.status).to eq 200
33
+ expect(response.body).to eq array_of_posts
34
+ end
35
+ end
36
+ end
37
+
38
+ describe '#show' do
39
+ let(:post) do
40
+ { id: 1, title: 'Title 1' }.to_json
41
+ end
42
+
43
+ it 'returns a post' do
44
+ get '/rest/:id', id: 1
45
+ expect(response.status).to eq 200
46
+ expect(response.body).to eq post
47
+ end
48
+ end
49
+
50
+ describe '#create' do
51
+ let(:new_post) do
52
+ { id: 4, title: 'New title' }.to_json
53
+ end
54
+
55
+ it 'returns a created post' do
56
+ post '/rest', title: 'New title'
57
+ expect(response.status).to eq 201
58
+ expect(response.body).to eq new_post
59
+ end
60
+ end
61
+
62
+ describe '#update' do
63
+ let(:post) do
64
+ { id: 1, title: 'Modified title' }.to_json
65
+ end
66
+
67
+ it 'returns a updated post' do
68
+ patch '/rest/:id', id: 1, title: 'Modified title'
69
+ expect(response.status).to eq 200
70
+ expect(response.body).to eq post
71
+ end
72
+ end
73
+
74
+ describe '#delete' do
75
+ it 'returns no body' do
76
+ delete '/rest/:id', id: 123
77
+ expect(response.status).to eq 204
78
+ expect(response.body).to be_empty
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe StatusController, type: :controller do
4
+ describe '#show' do
5
+ context 'when request status code 200' do
6
+ let(:status) { 200 }
7
+
8
+ let(:expected_response) do
9
+ { message: 'You requested status code: 200' }.to_json
10
+ end
11
+
12
+ it 'returns 200 OK' do
13
+ get '/status/:status', status: status
14
+ expect(response.status).to eq status
15
+ expect(response.body).to eq expected_response
16
+ end
17
+ end
18
+
19
+ context 'when request status code 400' do
20
+ let(:status) { 400 }
21
+
22
+ let(:expected_response) do
23
+ { message: 'You requested status code: 400' }.to_json
24
+ end
25
+
26
+ it 'returns 400 Bad request' do
27
+ get '/status/:status', status: status
28
+ expect(response.status).to eq status
29
+ expect(response.body).to eq expected_response
30
+ end
31
+ end
32
+
33
+ context 'when request status code 500' do
34
+ let(:status) { 500 }
35
+
36
+ let(:expected_response) do
37
+ { message: 'You requested status code: 500' }.to_json
38
+ end
39
+
40
+ it 'returns 500 Internal server error' do
41
+ get '/status/:status', status: status
42
+ expect(response.status).to eq status
43
+ expect(response.body).to eq expected_response
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,51 @@
1
+ {
2
+ "resource": "/posts",
3
+ "path": "/posts",
4
+ "httpMethod": "GET",
5
+ "headers": {
6
+ "Accept": "*/*",
7
+ "CloudFront-Forwarded-Proto": "https",
8
+ "CloudFront-Is-Desktop-Viewer": "true",
9
+ "CloudFront-Is-Mobile-Viewer": "false",
10
+ "CloudFront-Is-SmartTV-Viewer": "false",
11
+ "CloudFront-Is-Tablet-Viewer": "false",
12
+ "CloudFront-Viewer-Country": "US",
13
+ "Host": "qg45s7uvg2.execute-api.us-east-1.amazonaws.com",
14
+ "User-Agent": "curl/7.54.0",
15
+ "Via": "1.1 3d3d633d266d05d90a4eea7a6a59b514.cloudfront.net (CloudFront)",
16
+ "X-Amz-Cf-Id": "4mAgowukJJbA7lgTWITzgOPmdiDsXPCwy6vonS8VKPXCdEsmldVgdg==",
17
+ "X-Amzn-Trace-Id": "Root=1-59fb8ea5-38c5ad176dac130f3eb9ce97",
18
+ "X-Forwarded-For": "69.42.1.180, 54.239.203.118",
19
+ "X-Forwarded-Port": "443",
20
+ "X-Forwarded-Proto": "https"
21
+ },
22
+ "queryStringParameters": null,
23
+ "pathParameters": null,
24
+ "stageVariables": null,
25
+ "requestContext": {
26
+ "path": "/prod/posts",
27
+ "accountId": "123456789012",
28
+ "resourceId": "ery965",
29
+ "stage": "prod",
30
+ "requestId": "292fbcc8-c015-11e7-94fa-cd109b693f3c",
31
+ "identity": {
32
+ "cognitoIdentityPoolId": null,
33
+ "accountId": null,
34
+ "cognitoIdentityId": null,
35
+ "caller": null,
36
+ "apiKey": "",
37
+ "sourceIp": "69.42.1.180",
38
+ "accessKey": null,
39
+ "cognitoAuthenticationType": null,
40
+ "cognitoAuthenticationProvider": null,
41
+ "userArn": null,
42
+ "userAgent": "curl/7.54.0",
43
+ "user": null
44
+ },
45
+ "resourcePath": "/posts",
46
+ "httpMethod": "GET",
47
+ "apiId": "qg45s7uvg2"
48
+ },
49
+ "body": null,
50
+ "isBase64Encoded": false
51
+ }
@@ -0,0 +1,53 @@
1
+ {
2
+ "resource": "/posts/{id}",
3
+ "path": "/posts/tung",
4
+ "httpMethod": "GET",
5
+ "headers": {
6
+ "Accept": "*/*",
7
+ "CloudFront-Forwarded-Proto": "https",
8
+ "CloudFront-Is-Desktop-Viewer": "true",
9
+ "CloudFront-Is-Mobile-Viewer": "false",
10
+ "CloudFront-Is-SmartTV-Viewer": "false",
11
+ "CloudFront-Is-Tablet-Viewer": "false",
12
+ "CloudFront-Viewer-Country": "US",
13
+ "Host": "qg45s7uvg2.execute-api.us-east-1.amazonaws.com",
14
+ "User-Agent": "curl/7.54.0",
15
+ "Via": "1.1 dc553909528b8b63475c922dc07d8ba6.cloudfront.net (CloudFront)",
16
+ "X-Amz-Cf-Id": "s9NB2f_Z1scd6ksA4fcXA2r4QhpSKQ6QcTLQHGfxDPfI-X7sXM3YLg==",
17
+ "X-Amzn-Trace-Id": "Root=1-59fb8ecb-586ab81d73e36910793d767c",
18
+ "X-Forwarded-For": "69.42.1.180, 54.239.203.97",
19
+ "X-Forwarded-Port": "443",
20
+ "X-Forwarded-Proto": "https"
21
+ },
22
+ "queryStringParameters": null,
23
+ "pathParameters": {
24
+ "id": "tung"
25
+ },
26
+ "stageVariables": null,
27
+ "requestContext": {
28
+ "path": "/prod/posts/tung",
29
+ "accountId": "123456789012",
30
+ "resourceId": "wf2gvu",
31
+ "stage": "prod",
32
+ "requestId": "3feafb4e-c015-11e7-85c9-194f38f4c414",
33
+ "identity": {
34
+ "cognitoIdentityPoolId": null,
35
+ "accountId": null,
36
+ "cognitoIdentityId": null,
37
+ "caller": null,
38
+ "apiKey": "",
39
+ "sourceIp": "69.42.1.180",
40
+ "accessKey": null,
41
+ "cognitoAuthenticationType": null,
42
+ "cognitoAuthenticationProvider": null,
43
+ "userArn": null,
44
+ "userAgent": "curl/7.54.0",
45
+ "user": null
46
+ },
47
+ "resourcePath": "/posts/{id}",
48
+ "httpMethod": "GET",
49
+ "apiId": "qg45s7uvg2"
50
+ },
51
+ "body": null,
52
+ "isBase64Encoded": false
53
+ }
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['JETS_TEST'] = '1'
4
+ ENV['JETS_ENV'] ||= 'test'
5
+ # Ensures aws api never called. Fixture home folder does not contain ~/.aws/credentails
6
+ ENV['HOME'] = 'spec/fixtures/home'
7
+
8
+ require 'byebug'
9
+ require 'fileutils'
10
+ require 'jets'
11
+
12
+ abort('The Jets environment is running in production mode!') if Jets.env == 'production'
13
+ Jets.boot
14
+
15
+ require 'jets/spec_helpers'
16
+
17
+ # Rspec helper module
18
+ module Helpers
19
+ def payload(name)
20
+ JSON.parse(IO.read("spec/fixtures/payloads/#{name}.json"))
21
+ end
22
+ end
23
+
24
+ RSpec.configure do |c|
25
+ c.include Helpers
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0.pre
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryz310
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-23 00:00:00.000000000 Z
11
+ date: 2020-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -245,6 +245,11 @@ files:
245
245
  - Rakefile
246
246
  - bin/console
247
247
  - bin/setup
248
+ - example/api_clients/application_api_client.rb
249
+ - example/api_clients/my_error_api_client.rb
250
+ - example/api_clients/my_errors.rb
251
+ - example/api_clients/my_rest_api_client.rb
252
+ - example/api_clients/my_status_api_client.rb
248
253
  - gemfiles/rails_4.2.gemfile
249
254
  - gemfiles/rails_5.0.gemfile
250
255
  - gemfiles/rails_5.1.gemfile
@@ -280,6 +285,42 @@ files:
280
285
  - lib/my_api_client/service_abstract.rb
281
286
  - lib/my_api_client/sleeper.rb
282
287
  - lib/my_api_client/version.rb
288
+ - my_api/.envrc.skeleton
289
+ - my_api/.gitignore
290
+ - my_api/.jetskeep
291
+ - my_api/.rspec
292
+ - my_api/.ruby-version
293
+ - my_api/Gemfile
294
+ - my_api/Gemfile.lock
295
+ - my_api/Procfile
296
+ - my_api/README.md
297
+ - my_api/Rakefile
298
+ - my_api/app/controllers/application_controller.rb
299
+ - my_api/app/controllers/error_controller.rb
300
+ - my_api/app/controllers/rest_controller.rb
301
+ - my_api/app/controllers/status_controller.rb
302
+ - my_api/app/helpers/application_helper.rb
303
+ - my_api/app/jobs/application_job.rb
304
+ - my_api/app/models/application_item.rb
305
+ - my_api/config.ru
306
+ - my_api/config/application.rb
307
+ - my_api/config/dynamodb.yml
308
+ - my_api/config/environments/development.rb
309
+ - my_api/config/environments/production.rb
310
+ - my_api/config/environments/test.rb
311
+ - my_api/config/routes.rb
312
+ - my_api/db/.gitkeep
313
+ - my_api/public/404.html
314
+ - my_api/public/422.html
315
+ - my_api/public/500.html
316
+ - my_api/public/favicon.ico
317
+ - my_api/public/index.html
318
+ - my_api/spec/controllers/error_controller_spec.rb
319
+ - my_api/spec/controllers/rest_controller_spec.rb
320
+ - my_api/spec/controllers/status_controller_spec.rb
321
+ - my_api/spec/fixtures/payloads/posts-index.json
322
+ - my_api/spec/fixtures/payloads/posts-show.json
323
+ - my_api/spec/spec_helper.rb
283
324
  - my_api_client.gemspec
284
325
  - renovate.json
285
326
  homepage: https://github.com/ryz310/my_api_client
@@ -297,9 +338,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
297
338
  version: 2.4.0
298
339
  required_rubygems_version: !ruby/object:Gem::Requirement
299
340
  requirements:
300
- - - ">"
341
+ - - ">="
301
342
  - !ruby/object:Gem::Version
302
- version: 1.3.1
343
+ version: '0'
303
344
  requirements: []
304
345
  rubygems_version: 3.1.2
305
346
  signing_key: