my_api_client 0.13.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +102 -36
  3. data/.dependabot/config.yml +34 -0
  4. data/.envrc.skeleton +1 -0
  5. data/.rubocop.yml +8 -10
  6. data/.rubocop_challenge.yml +3 -0
  7. data/.rubocop_todo.yml +5 -10
  8. data/CHANGELOG.md +229 -0
  9. data/Gemfile.lock +48 -43
  10. data/README.jp.md +98 -23
  11. data/bin/console +4 -0
  12. data/example/api_clients/application_api_client.rb +13 -0
  13. data/example/api_clients/my_error_api_client.rb +34 -0
  14. data/example/api_clients/my_errors.rb +27 -0
  15. data/example/api_clients/my_pagination_api_client.rb +18 -0
  16. data/example/api_clients/my_rest_api_client.rb +48 -0
  17. data/example/api_clients/my_status_api_client.rb +22 -0
  18. data/lib/generators/rails/templates/application_api_client.rb.erb +0 -11
  19. data/lib/my_api_client.rb +10 -2
  20. data/lib/my_api_client/base.rb +2 -18
  21. data/lib/my_api_client/config.rb +0 -29
  22. data/lib/my_api_client/default_error_handlers.rb +64 -0
  23. data/lib/my_api_client/error_handling.rb +13 -23
  24. data/lib/my_api_client/error_handling/generator.rb +30 -10
  25. data/lib/my_api_client/error_handling/{process_retry_option.rb → retry_option_processor.rb} +1 -1
  26. data/lib/my_api_client/errors.rb +0 -53
  27. data/lib/my_api_client/errors/api_limit_error.rb +6 -0
  28. data/lib/my_api_client/errors/client_error.rb +93 -0
  29. data/lib/my_api_client/errors/network_error.rb +43 -0
  30. data/lib/my_api_client/errors/server_error.rb +42 -0
  31. data/lib/my_api_client/params/request.rb +7 -10
  32. data/lib/my_api_client/request.rb +48 -70
  33. data/lib/my_api_client/request/basic.rb +32 -0
  34. data/lib/my_api_client/request/executor.rb +89 -0
  35. data/lib/my_api_client/request/logger.rb +37 -0
  36. data/lib/my_api_client/request/pagination.rb +39 -0
  37. data/lib/my_api_client/rspec/matcher_helper.rb +2 -2
  38. data/lib/my_api_client/rspec/matchers/be_handled_as_an_error.rb +2 -0
  39. data/lib/my_api_client/rspec/matchers/request_to.rb +3 -4
  40. data/lib/my_api_client/version.rb +1 -1
  41. data/my_api/.envrc.skeleton +3 -0
  42. data/my_api/.gitignore +14 -0
  43. data/my_api/.jetskeep +1 -0
  44. data/my_api/.rspec +3 -0
  45. data/my_api/.ruby-version +1 -0
  46. data/my_api/Gemfile +23 -0
  47. data/my_api/Gemfile.lock +243 -0
  48. data/my_api/Procfile +7 -0
  49. data/my_api/README.md +54 -0
  50. data/my_api/Rakefile +4 -0
  51. data/my_api/app/controllers/application_controller.rb +5 -0
  52. data/my_api/app/controllers/error_controller.rb +21 -0
  53. data/my_api/app/controllers/pagination_controller.rb +58 -0
  54. data/my_api/app/controllers/rest_controller.rb +60 -0
  55. data/my_api/app/controllers/status_controller.rb +11 -0
  56. data/my_api/app/helpers/application_helper.rb +5 -0
  57. data/my_api/app/jobs/application_job.rb +7 -0
  58. data/my_api/app/models/application_item.rb +5 -0
  59. data/my_api/config.ru +7 -0
  60. data/my_api/config/application.rb +73 -0
  61. data/my_api/config/dynamodb.yml +22 -0
  62. data/my_api/config/environments/development.rb +9 -0
  63. data/my_api/config/environments/production.rb +11 -0
  64. data/my_api/config/environments/test.rb +9 -0
  65. data/my_api/config/routes.rb +17 -0
  66. data/my_api/db/.gitkeep +0 -0
  67. data/my_api/public/404.html +67 -0
  68. data/my_api/public/422.html +67 -0
  69. data/my_api/public/500.html +66 -0
  70. data/my_api/public/favicon.ico +0 -0
  71. data/my_api/public/index.html +91 -0
  72. data/my_api/spec/controllers/error_controller_spec.rb +43 -0
  73. data/my_api/spec/controllers/pagination_controller_spec.rb +73 -0
  74. data/my_api/spec/controllers/rest_controller_spec.rb +99 -0
  75. data/my_api/spec/controllers/status_controller_spec.rb +47 -0
  76. data/my_api/spec/fixtures/payloads/posts-index.json +51 -0
  77. data/my_api/spec/fixtures/payloads/posts-show.json +53 -0
  78. data/my_api/spec/spec_helper.rb +31 -0
  79. data/my_api_client.gemspec +1 -1
  80. metadata +62 -9
  81. data/lib/my_api_client/logger.rb +0 -36
  82. data/renovate.json +0 -5
@@ -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,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['JETS_TEST'] = '1'
4
+ ENV['JETS_ENV'] ||= 'test'
5
+ ENV['JETS_STAGE'] ||= 'test'
6
+ # Ensures aws api never called. Fixture home folder does not contain ~/.aws/credentails
7
+ ENV['HOME'] = 'spec/fixtures/home'
8
+
9
+ require 'byebug'
10
+ require 'fileutils'
11
+ require 'jets'
12
+
13
+ abort('The Jets environment is running in production mode!') if Jets.env == 'production'
14
+ Jets.boot
15
+
16
+ require 'jets/spec_helpers'
17
+
18
+ # Rspec helper module
19
+ module Helpers
20
+ def payload(name)
21
+ JSON.parse(IO.read("spec/fixtures/payloads/#{name}.json"))
22
+ end
23
+ end
24
+
25
+ RSpec.configure do |c|
26
+ c.include Helpers
27
+ end
28
+
29
+ Jets.application.configure do
30
+ config.helpers.host = 'https://example.com'
31
+ end
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'rubocop'
38
38
  spec.add_development_dependency 'rubocop-performance'
39
39
  spec.add_development_dependency 'rubocop-rspec'
40
- spec.add_development_dependency 'simplecov'
40
+ spec.add_development_dependency 'simplecov', '0.17.1'
41
41
  spec.add_development_dependency 'webmock'
42
42
  spec.add_development_dependency 'yard'
43
43
  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.13.0
4
+ version: 0.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryz310
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-21 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -182,16 +182,16 @@ dependencies:
182
182
  name: simplecov
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - ">="
185
+ - - '='
186
186
  - !ruby/object:Gem::Version
187
- version: '0'
187
+ version: 0.17.1
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - ">="
192
+ - - '='
193
193
  - !ruby/object:Gem::Version
194
- version: '0'
194
+ version: 0.17.1
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: webmock
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -228,11 +228,13 @@ extensions: []
228
228
  extra_rdoc_files: []
229
229
  files:
230
230
  - ".circleci/config.yml"
231
+ - ".dependabot/config.yml"
231
232
  - ".envrc.skeleton"
232
233
  - ".gem_comet.yml"
233
234
  - ".gitignore"
234
235
  - ".rspec"
235
236
  - ".rubocop.yml"
237
+ - ".rubocop_challenge.yml"
236
238
  - ".rubocop_todo.yml"
237
239
  - CHANGELOG.md
238
240
  - CODE_OF_CONDUCT.md
@@ -244,6 +246,12 @@ files:
244
246
  - Rakefile
245
247
  - bin/console
246
248
  - bin/setup
249
+ - example/api_clients/application_api_client.rb
250
+ - example/api_clients/my_error_api_client.rb
251
+ - example/api_clients/my_errors.rb
252
+ - example/api_clients/my_pagination_api_client.rb
253
+ - example/api_clients/my_rest_api_client.rb
254
+ - example/api_clients/my_status_api_client.rb
247
255
  - gemfiles/rails_4.2.gemfile
248
256
  - gemfiles/rails_5.0.gemfile
249
257
  - gemfiles/rails_5.1.gemfile
@@ -260,16 +268,24 @@ files:
260
268
  - lib/my_api_client.rb
261
269
  - lib/my_api_client/base.rb
262
270
  - lib/my_api_client/config.rb
271
+ - lib/my_api_client/default_error_handlers.rb
263
272
  - lib/my_api_client/error_handling.rb
264
273
  - lib/my_api_client/error_handling/generator.rb
265
- - lib/my_api_client/error_handling/process_retry_option.rb
274
+ - lib/my_api_client/error_handling/retry_option_processor.rb
266
275
  - lib/my_api_client/errors.rb
276
+ - lib/my_api_client/errors/api_limit_error.rb
277
+ - lib/my_api_client/errors/client_error.rb
278
+ - lib/my_api_client/errors/network_error.rb
279
+ - lib/my_api_client/errors/server_error.rb
267
280
  - lib/my_api_client/exceptions.rb
268
281
  - lib/my_api_client/integrations/bugsnag.rb
269
- - lib/my_api_client/logger.rb
270
282
  - lib/my_api_client/params/params.rb
271
283
  - lib/my_api_client/params/request.rb
272
284
  - lib/my_api_client/request.rb
285
+ - lib/my_api_client/request/basic.rb
286
+ - lib/my_api_client/request/executor.rb
287
+ - lib/my_api_client/request/logger.rb
288
+ - lib/my_api_client/request/pagination.rb
273
289
  - lib/my_api_client/rspec.rb
274
290
  - lib/my_api_client/rspec/matcher_helper.rb
275
291
  - lib/my_api_client/rspec/matchers/be_handled_as_an_error.rb
@@ -278,8 +294,45 @@ files:
278
294
  - lib/my_api_client/service_abstract.rb
279
295
  - lib/my_api_client/sleeper.rb
280
296
  - lib/my_api_client/version.rb
297
+ - my_api/.envrc.skeleton
298
+ - my_api/.gitignore
299
+ - my_api/.jetskeep
300
+ - my_api/.rspec
301
+ - my_api/.ruby-version
302
+ - my_api/Gemfile
303
+ - my_api/Gemfile.lock
304
+ - my_api/Procfile
305
+ - my_api/README.md
306
+ - my_api/Rakefile
307
+ - my_api/app/controllers/application_controller.rb
308
+ - my_api/app/controllers/error_controller.rb
309
+ - my_api/app/controllers/pagination_controller.rb
310
+ - my_api/app/controllers/rest_controller.rb
311
+ - my_api/app/controllers/status_controller.rb
312
+ - my_api/app/helpers/application_helper.rb
313
+ - my_api/app/jobs/application_job.rb
314
+ - my_api/app/models/application_item.rb
315
+ - my_api/config.ru
316
+ - my_api/config/application.rb
317
+ - my_api/config/dynamodb.yml
318
+ - my_api/config/environments/development.rb
319
+ - my_api/config/environments/production.rb
320
+ - my_api/config/environments/test.rb
321
+ - my_api/config/routes.rb
322
+ - my_api/db/.gitkeep
323
+ - my_api/public/404.html
324
+ - my_api/public/422.html
325
+ - my_api/public/500.html
326
+ - my_api/public/favicon.ico
327
+ - my_api/public/index.html
328
+ - my_api/spec/controllers/error_controller_spec.rb
329
+ - my_api/spec/controllers/pagination_controller_spec.rb
330
+ - my_api/spec/controllers/rest_controller_spec.rb
331
+ - my_api/spec/controllers/status_controller_spec.rb
332
+ - my_api/spec/fixtures/payloads/posts-index.json
333
+ - my_api/spec/fixtures/payloads/posts-show.json
334
+ - my_api/spec/spec_helper.rb
281
335
  - my_api_client.gemspec
282
- - renovate.json
283
336
  homepage: https://github.com/ryz310/my_api_client
284
337
  licenses:
285
338
  - MIT
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MyApiClient
4
- # Description of Logger
5
- class Logger
6
- attr_reader :logger, :method, :pathname
7
-
8
- LOG_LEVEL = %i[debug info warn error fatal].freeze
9
-
10
- # Description of #initialize
11
- #
12
- # @param logger [::Logger] describe_logger_here
13
- # @param faraday [Faraday::Connection] describe_faraday_here
14
- # @param method [String] HTTP method
15
- # @param pathname [String] The path name
16
- def initialize(logger, faraday, method, pathname)
17
- @logger = logger
18
- @method = method.to_s.upcase
19
- @pathname = faraday.build_exclusive_url(pathname)
20
- end
21
-
22
- LOG_LEVEL.each do |level|
23
- class_eval <<~METHOD, __FILE__, __LINE__ + 1
24
- def #{level}(message)
25
- logger.#{level}(format(message))
26
- end
27
- METHOD
28
- end
29
-
30
- private
31
-
32
- def format(message)
33
- "API request `#{method} #{pathname}`: \"#{message}\""
34
- end
35
- end
36
- end
@@ -1,5 +0,0 @@
1
- {
2
- "extends": [
3
- "config:base"
4
- ]
5
- }