my_api_client 0.14.0 → 0.18.0

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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +99 -53
  3. data/.dependabot/config.yml +19 -1
  4. data/.rubocop.yml +5 -1
  5. data/.rubocop_challenge.yml +5 -0
  6. data/.rubocop_todo.yml +53 -1
  7. data/CHANGELOG.md +192 -0
  8. data/Gemfile +0 -3
  9. data/Gemfile.lock +60 -56
  10. data/README.jp.md +159 -24
  11. data/bin/console +4 -0
  12. data/example/api_clients/application_api_client.rb +2 -10
  13. data/example/api_clients/my_pagination_api_client.rb +18 -0
  14. data/example/api_clients/my_rest_api_client.rb +9 -3
  15. data/lib/generators/rails/USAGE +1 -1
  16. data/lib/generators/rails/api_client_generator.rb +6 -0
  17. data/lib/generators/rails/templates/api_client.rb.erb +1 -1
  18. data/lib/generators/rails/templates/application_api_client.rb.erb +0 -11
  19. data/lib/generators/rspec/USAGE +1 -1
  20. data/lib/generators/rspec/api_client_generator.rb +6 -0
  21. data/lib/generators/rspec/templates/api_client_spec.rb.erb +23 -16
  22. data/lib/my_api_client.rb +7 -0
  23. data/lib/my_api_client/base.rb +4 -2
  24. data/lib/my_api_client/default_error_handlers.rb +64 -0
  25. data/lib/my_api_client/error_handling.rb +6 -6
  26. data/lib/my_api_client/error_handling/generator.rb +23 -7
  27. data/lib/my_api_client/errors.rb +1 -53
  28. data/lib/my_api_client/errors/api_limit_error.rb +6 -0
  29. data/lib/my_api_client/errors/client_error.rb +93 -0
  30. data/lib/my_api_client/errors/network_error.rb +43 -0
  31. data/lib/my_api_client/errors/server_error.rb +42 -0
  32. data/lib/my_api_client/params/params.rb +1 -3
  33. data/lib/my_api_client/request.rb +29 -34
  34. data/lib/my_api_client/request/basic.rb +32 -0
  35. data/lib/my_api_client/request/executor.rb +1 -1
  36. data/lib/my_api_client/request/pagination.rb +39 -0
  37. data/lib/my_api_client/version.rb +1 -1
  38. data/my_api/.ruby-version +1 -1
  39. data/my_api/Gemfile.lock +86 -86
  40. data/my_api/README.md +6 -0
  41. data/my_api/app/controllers/pagination_controller.rb +58 -0
  42. data/my_api/config/routes.rb +1 -0
  43. data/my_api/spec/controllers/pagination_controller_spec.rb +73 -0
  44. data/my_api/spec/controllers/rest_controller_spec.rb +23 -5
  45. data/my_api/spec/spec_helper.rb +5 -0
  46. data/my_api_client.gemspec +2 -2
  47. data/rails_app/rails_5.2/.rspec +3 -0
  48. data/rails_app/rails_5.2/Gemfile +17 -0
  49. data/rails_app/rails_5.2/Gemfile.lock +171 -0
  50. data/rails_app/rails_5.2/README.md +24 -0
  51. data/rails_app/rails_5.2/Rakefile +8 -0
  52. data/rails_app/rails_5.2/app/controllers/application_controller.rb +4 -0
  53. data/rails_app/rails_5.2/app/jobs/application_job.rb +4 -0
  54. data/rails_app/rails_5.2/bin/bundle +5 -0
  55. data/rails_app/rails_5.2/bin/rails +6 -0
  56. data/rails_app/rails_5.2/bin/rake +6 -0
  57. data/rails_app/rails_5.2/bin/setup +27 -0
  58. data/rails_app/rails_5.2/bin/update +27 -0
  59. data/rails_app/rails_5.2/config.ru +7 -0
  60. data/rails_app/rails_5.2/config/application.rb +37 -0
  61. data/rails_app/rails_5.2/config/boot.rb +6 -0
  62. data/rails_app/rails_5.2/config/credentials.yml.enc +1 -0
  63. data/rails_app/rails_5.2/config/environment.rb +7 -0
  64. data/rails_app/rails_5.2/config/environments/development.rb +41 -0
  65. data/rails_app/rails_5.2/config/environments/production.rb +70 -0
  66. data/rails_app/rails_5.2/config/environments/test.rb +38 -0
  67. data/rails_app/rails_5.2/config/initializers/application_controller_renderer.rb +9 -0
  68. data/rails_app/rails_5.2/config/initializers/backtrace_silencers.rb +8 -0
  69. data/rails_app/rails_5.2/config/initializers/cors.rb +17 -0
  70. data/rails_app/rails_5.2/config/initializers/filter_parameter_logging.rb +6 -0
  71. data/rails_app/rails_5.2/config/initializers/inflections.rb +17 -0
  72. data/rails_app/rails_5.2/config/initializers/mime_types.rb +5 -0
  73. data/rails_app/rails_5.2/config/initializers/wrap_parameters.rb +11 -0
  74. data/rails_app/rails_5.2/config/locales/en.yml +33 -0
  75. data/rails_app/rails_5.2/config/routes.rb +5 -0
  76. data/rails_app/rails_5.2/config/spring.rb +8 -0
  77. data/rails_app/rails_5.2/public/robots.txt +1 -0
  78. data/rails_app/rails_5.2/spec/rails_helper.rb +14 -0
  79. data/rails_app/rails_5.2/spec/spec_helper.rb +13 -0
  80. data/rails_app/rails_6.0/.rspec +3 -0
  81. data/rails_app/rails_6.0/Gemfile +17 -0
  82. data/rails_app/rails_6.0/Gemfile.lock +186 -0
  83. data/rails_app/rails_6.0/README.md +24 -0
  84. data/rails_app/rails_6.0/Rakefile +8 -0
  85. data/rails_app/rails_6.0/app/controllers/application_controller.rb +4 -0
  86. data/rails_app/rails_6.0/app/jobs/application_job.rb +9 -0
  87. data/rails_app/rails_6.0/bin/rails +6 -0
  88. data/rails_app/rails_6.0/bin/rake +6 -0
  89. data/rails_app/rails_6.0/bin/setup +27 -0
  90. data/rails_app/rails_6.0/config.ru +7 -0
  91. data/rails_app/rails_6.0/config/application.rb +39 -0
  92. data/rails_app/rails_6.0/config/boot.rb +6 -0
  93. data/rails_app/rails_6.0/config/credentials.yml.enc +1 -0
  94. data/rails_app/rails_6.0/config/environment.rb +7 -0
  95. data/rails_app/rails_6.0/config/environments/development.rb +39 -0
  96. data/rails_app/rails_6.0/config/environments/production.rb +90 -0
  97. data/rails_app/rails_6.0/config/environments/test.rb +41 -0
  98. data/rails_app/rails_6.0/config/initializers/application_controller_renderer.rb +9 -0
  99. data/rails_app/rails_6.0/config/initializers/backtrace_silencers.rb +8 -0
  100. data/rails_app/rails_6.0/config/initializers/cors.rb +17 -0
  101. data/rails_app/rails_6.0/config/initializers/filter_parameter_logging.rb +6 -0
  102. data/rails_app/rails_6.0/config/initializers/inflections.rb +17 -0
  103. data/rails_app/rails_6.0/config/initializers/mime_types.rb +5 -0
  104. data/rails_app/rails_6.0/config/initializers/wrap_parameters.rb +11 -0
  105. data/rails_app/rails_6.0/config/locales/en.yml +33 -0
  106. data/rails_app/rails_6.0/config/routes.rb +5 -0
  107. data/rails_app/rails_6.0/config/spring.rb +8 -0
  108. data/rails_app/rails_6.0/public/robots.txt +1 -0
  109. data/rails_app/rails_6.0/spec/rails_helper.rb +14 -0
  110. data/rails_app/rails_6.0/spec/spec_helper.rb +13 -0
  111. metadata +81 -8
  112. data/gemfiles/rails_4.2.gemfile +0 -15
  113. data/renovate.json +0 -21
@@ -28,6 +28,12 @@ This API returns arbitrary error code as JSON.
28
28
 
29
29
  * `GET error/:code`
30
30
 
31
+ ### My Pagination API
32
+
33
+ This API returns a response including pagination links.
34
+
35
+ * `GET pagination?page=1`
36
+
31
37
  ## Deployment
32
38
 
33
39
  You need to prepare following environment variables:
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A Pagination API
4
+ class PaginationController < ApplicationController
5
+ # GET pagination
6
+ def index
7
+ case params[:page]
8
+ when '1', nil
9
+ render status: :ok, json: first_page
10
+ when '2'
11
+ render status: :ok, json: second_page
12
+ when '3'
13
+ render status: :ok, json: third_page
14
+ else
15
+ render status: :not_found, json: ''
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def first_page
22
+ {
23
+ links: {
24
+ next: page_link(2),
25
+ },
26
+ page: 1,
27
+ }
28
+ end
29
+
30
+ def second_page
31
+ {
32
+ links: {
33
+ next: page_link(3),
34
+ previous: page_link(1),
35
+ },
36
+ page: 2,
37
+ }
38
+ end
39
+
40
+ def third_page
41
+ {
42
+ links: {
43
+ previous: page_link(2),
44
+ },
45
+ page: 3,
46
+ }
47
+ end
48
+
49
+ # NOTE: `#pagination_url` returns `http://xxxxx.execute-api.ap-northeast-1.amazonaws.com/pagination`
50
+ # but it should be `https://xxxxx.execute-api.ap-northeast-1.amazonaws.com/dev/pagination`.
51
+ # So this is workaround.
52
+ def page_link(page)
53
+ query_strings = '?' + { page: page }.to_query
54
+ uri = File.join(ENV['JETS_HOST'], ENV['JETS_STAGE'], pagination_path)
55
+ uri.sub!('http://', 'https://')
56
+ URI.join(uri, query_strings)
57
+ end
58
+ end
@@ -7,6 +7,7 @@ Jets.application.routes.draw do
7
7
 
8
8
  get 'status/:status', to: 'status#show'
9
9
  get 'error/:code', to: 'error#show'
10
+ get 'pagination', to: 'pagination#index'
10
11
 
11
12
  # The jets/public#show controller can serve static utf8 content out of the public folder.
12
13
  # Note, as part of the deploy process Jets uploads files in the public folder to s3
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PaginationController, type: :controller do
4
+ describe '#index' do
5
+ let(:first_page) do
6
+ {
7
+ links: {
8
+ next: 'https://example.com/test/pagination?page=2',
9
+ },
10
+ page: 1,
11
+ }.to_json
12
+ end
13
+
14
+ let(:second_page) do
15
+ {
16
+ links: {
17
+ next: 'https://example.com/test/pagination?page=3',
18
+ previous: 'https://example.com/test/pagination?page=1',
19
+ },
20
+ page: 2,
21
+ }.to_json
22
+ end
23
+
24
+ let(:third_page) do
25
+ {
26
+ links: {
27
+ previous: 'https://example.com/test/pagination?page=2',
28
+ },
29
+ page: 3,
30
+ }.to_json
31
+ end
32
+
33
+ context 'without page' do
34
+ it 'returns a 1st page contents including 2nd page link' do
35
+ get '/pagination'
36
+ expect(response.status).to eq 200
37
+ expect(response.body).to eq first_page
38
+ end
39
+ end
40
+
41
+ context 'with page = 1' do
42
+ it 'returns a 1st page contents including 2nd page link' do
43
+ get '/pagination', page: 1
44
+ expect(response.status).to eq 200
45
+ expect(response.body).to eq first_page
46
+ end
47
+ end
48
+
49
+ context 'with page = 2' do
50
+ it 'returns a 2nd page contents including 3rd page link' do
51
+ get '/pagination', page: 2
52
+ expect(response.status).to eq 200
53
+ expect(response.body).to eq second_page
54
+ end
55
+ end
56
+
57
+ context 'with page = 3' do
58
+ it 'returns a 3rd page contents not including next page link' do
59
+ get '/pagination', page: 3
60
+ expect(response.status).to eq 200
61
+ expect(response.body).to eq third_page
62
+ end
63
+ end
64
+
65
+ context 'with page = 4' do
66
+ it 'returns 404 NOT FOUND' do
67
+ get '/pagination', page: 4
68
+ expect(response.status).to eq 404
69
+ expect(response.body).to be_blank
70
+ end
71
+ end
72
+ end
73
+ end
@@ -60,14 +60,32 @@ describe RestController, type: :controller do
60
60
  end
61
61
 
62
62
  describe '#update' do
63
- let(:post) do
63
+ let(:the_post) do
64
64
  { id: 1, title: 'Modified title' }.to_json
65
65
  end
66
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
67
+ context 'with POST method' do
68
+ it 'returns a updated post' do
69
+ post '/rest/:id', id: 1, title: 'Modified title'
70
+ expect(response.status).to eq 200
71
+ expect(response.body).to eq the_post
72
+ end
73
+ end
74
+
75
+ context 'with PUT method' do
76
+ it 'returns a updated post' do
77
+ put '/rest/:id', id: 1, title: 'Modified title'
78
+ expect(response.status).to eq 200
79
+ expect(response.body).to eq the_post
80
+ end
81
+ end
82
+
83
+ context 'with PATCH method' do
84
+ it 'returns a updated post' do
85
+ patch '/rest/:id', id: 1, title: 'Modified title'
86
+ expect(response.status).to eq 200
87
+ expect(response.body).to eq the_post
88
+ end
71
89
  end
72
90
  end
73
91
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  ENV['JETS_TEST'] = '1'
4
4
  ENV['JETS_ENV'] ||= 'test'
5
+ ENV['JETS_STAGE'] ||= 'test'
5
6
  # Ensures aws api never called. Fixture home folder does not contain ~/.aws/credentails
6
7
  ENV['HOME'] = 'spec/fixtures/home'
7
8
 
@@ -24,3 +25,7 @@ end
24
25
  RSpec.configure do |c|
25
26
  c.include Helpers
26
27
  end
28
+
29
+ Jets.application.configure do
30
+ config.helpers.host = 'https://example.com'
31
+ end
@@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.required_ruby_version = '>= 2.4.0'
25
+ spec.required_ruby_version = '>= 2.5.0'
26
26
 
27
- spec.add_dependency 'activesupport', '>= 4.2.0'
27
+ spec.add_dependency 'activesupport', '>= 5.0.0'
28
28
  spec.add_dependency 'faraday', '>= 0.17.1'
29
29
  spec.add_dependency 'jsonpath'
30
30
  spec.add_dependency 'sawyer', '>= 0.8.2'
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
+
6
+ gem 'bootsnap', '>= 1.1.0', require: false
7
+ gem 'my_api_client', path: '../..'
8
+ gem 'rails', '~> 5.2.4'
9
+
10
+ group :development, :test do
11
+ gem 'byebug', platforms: %i[mri mingw x64_mingw]
12
+ gem 'rspec-rails'
13
+ end
14
+
15
+ group :development do
16
+ gem 'spring'
17
+ end
@@ -0,0 +1,171 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ my_api_client (0.17.0)
5
+ activesupport (>= 5.0.0)
6
+ faraday (>= 0.17.1)
7
+ jsonpath
8
+ sawyer (>= 0.8.2)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actioncable (5.2.4.4)
14
+ actionpack (= 5.2.4.4)
15
+ nio4r (~> 2.0)
16
+ websocket-driver (>= 0.6.1)
17
+ actionmailer (5.2.4.4)
18
+ actionpack (= 5.2.4.4)
19
+ actionview (= 5.2.4.4)
20
+ activejob (= 5.2.4.4)
21
+ mail (~> 2.5, >= 2.5.4)
22
+ rails-dom-testing (~> 2.0)
23
+ actionpack (5.2.4.4)
24
+ actionview (= 5.2.4.4)
25
+ activesupport (= 5.2.4.4)
26
+ rack (~> 2.0, >= 2.0.8)
27
+ rack-test (>= 0.6.3)
28
+ rails-dom-testing (~> 2.0)
29
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
+ actionview (5.2.4.4)
31
+ activesupport (= 5.2.4.4)
32
+ builder (~> 3.1)
33
+ erubi (~> 1.4)
34
+ rails-dom-testing (~> 2.0)
35
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
36
+ activejob (5.2.4.4)
37
+ activesupport (= 5.2.4.4)
38
+ globalid (>= 0.3.6)
39
+ activemodel (5.2.4.4)
40
+ activesupport (= 5.2.4.4)
41
+ activerecord (5.2.4.4)
42
+ activemodel (= 5.2.4.4)
43
+ activesupport (= 5.2.4.4)
44
+ arel (>= 9.0)
45
+ activestorage (5.2.4.4)
46
+ actionpack (= 5.2.4.4)
47
+ activerecord (= 5.2.4.4)
48
+ marcel (~> 0.3.1)
49
+ activesupport (5.2.4.4)
50
+ concurrent-ruby (~> 1.0, >= 1.0.2)
51
+ i18n (>= 0.7, < 2)
52
+ minitest (~> 5.1)
53
+ tzinfo (~> 1.1)
54
+ addressable (2.7.0)
55
+ public_suffix (>= 2.0.2, < 5.0)
56
+ arel (9.0.0)
57
+ bootsnap (1.4.8)
58
+ msgpack (~> 1.0)
59
+ builder (3.2.4)
60
+ byebug (11.1.3)
61
+ concurrent-ruby (1.1.7)
62
+ crass (1.0.6)
63
+ diff-lcs (1.4.4)
64
+ erubi (1.9.0)
65
+ faraday (1.0.1)
66
+ multipart-post (>= 1.2, < 3)
67
+ globalid (0.4.2)
68
+ activesupport (>= 4.2.0)
69
+ i18n (1.8.5)
70
+ concurrent-ruby (~> 1.0)
71
+ jsonpath (1.0.5)
72
+ multi_json
73
+ to_regexp (~> 0.2.1)
74
+ loofah (2.7.0)
75
+ crass (~> 1.0.2)
76
+ nokogiri (>= 1.5.9)
77
+ mail (2.7.1)
78
+ mini_mime (>= 0.1.1)
79
+ marcel (0.3.3)
80
+ mimemagic (~> 0.3.2)
81
+ method_source (1.0.0)
82
+ mimemagic (0.3.5)
83
+ mini_mime (1.0.2)
84
+ mini_portile2 (2.4.0)
85
+ minitest (5.14.2)
86
+ msgpack (1.3.3)
87
+ multi_json (1.15.0)
88
+ multipart-post (2.1.1)
89
+ nio4r (2.5.4)
90
+ nokogiri (1.10.10)
91
+ mini_portile2 (~> 2.4.0)
92
+ public_suffix (4.0.6)
93
+ rack (2.2.3)
94
+ rack-test (1.1.0)
95
+ rack (>= 1.0, < 3)
96
+ rails (5.2.4.4)
97
+ actioncable (= 5.2.4.4)
98
+ actionmailer (= 5.2.4.4)
99
+ actionpack (= 5.2.4.4)
100
+ actionview (= 5.2.4.4)
101
+ activejob (= 5.2.4.4)
102
+ activemodel (= 5.2.4.4)
103
+ activerecord (= 5.2.4.4)
104
+ activestorage (= 5.2.4.4)
105
+ activesupport (= 5.2.4.4)
106
+ bundler (>= 1.3.0)
107
+ railties (= 5.2.4.4)
108
+ sprockets-rails (>= 2.0.0)
109
+ rails-dom-testing (2.0.3)
110
+ activesupport (>= 4.2.0)
111
+ nokogiri (>= 1.6)
112
+ rails-html-sanitizer (1.3.0)
113
+ loofah (~> 2.3)
114
+ railties (5.2.4.4)
115
+ actionpack (= 5.2.4.4)
116
+ activesupport (= 5.2.4.4)
117
+ method_source
118
+ rake (>= 0.8.7)
119
+ thor (>= 0.19.0, < 2.0)
120
+ rake (13.0.1)
121
+ rspec-core (3.9.2)
122
+ rspec-support (~> 3.9.3)
123
+ rspec-expectations (3.9.2)
124
+ diff-lcs (>= 1.2.0, < 2.0)
125
+ rspec-support (~> 3.9.0)
126
+ rspec-mocks (3.9.1)
127
+ diff-lcs (>= 1.2.0, < 2.0)
128
+ rspec-support (~> 3.9.0)
129
+ rspec-rails (4.0.1)
130
+ actionpack (>= 4.2)
131
+ activesupport (>= 4.2)
132
+ railties (>= 4.2)
133
+ rspec-core (~> 3.9)
134
+ rspec-expectations (~> 3.9)
135
+ rspec-mocks (~> 3.9)
136
+ rspec-support (~> 3.9)
137
+ rspec-support (3.9.3)
138
+ sawyer (0.8.2)
139
+ addressable (>= 2.3.5)
140
+ faraday (> 0.8, < 2.0)
141
+ spring (2.1.1)
142
+ sprockets (3.7.2)
143
+ concurrent-ruby (~> 1.0)
144
+ rack (> 1, < 3)
145
+ sprockets-rails (3.2.2)
146
+ actionpack (>= 4.0)
147
+ activesupport (>= 4.0)
148
+ sprockets (>= 3.0.0)
149
+ thor (1.0.1)
150
+ thread_safe (0.3.6)
151
+ to_regexp (0.2.1)
152
+ tzinfo (1.2.7)
153
+ thread_safe (~> 0.1)
154
+ websocket-driver (0.7.3)
155
+ websocket-extensions (>= 0.1.0)
156
+ websocket-extensions (0.1.5)
157
+
158
+ PLATFORMS
159
+ ruby
160
+
161
+ DEPENDENCIES
162
+ bootsnap (>= 1.1.0)
163
+ byebug
164
+ my_api_client!
165
+ rails (~> 5.2.4)
166
+ rspec-rails
167
+ spring
168
+ sprockets (~> 3.0)
169
+
170
+ BUNDLED WITH
171
+ 2.1.4
@@ -0,0 +1,24 @@
1
+ # README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
4
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
5
+
6
+ require_relative 'config/application'
7
+
8
+ Rails.application.load_tasks