my_api_client 0.14.0.pre → 0.17.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 (139) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +179 -38
  3. data/.dependabot/config.yml +19 -1
  4. data/.envrc.skeleton +1 -0
  5. data/.rubocop.yml +9 -1
  6. data/.rubocop_challenge.yml +5 -0
  7. data/.rubocop_todo.yml +29 -1
  8. data/CHANGELOG.md +177 -1
  9. data/Gemfile.lock +47 -45
  10. data/README.jp.md +156 -21
  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/generators/rspec/templates/api_client_spec.rb.erb +22 -15
  20. data/lib/my_api_client.rb +7 -0
  21. data/lib/my_api_client/base.rb +4 -2
  22. data/lib/my_api_client/default_error_handlers.rb +64 -0
  23. data/lib/my_api_client/error_handling.rb +6 -6
  24. data/lib/my_api_client/error_handling/generator.rb +23 -7
  25. data/lib/my_api_client/errors.rb +1 -53
  26. data/lib/my_api_client/errors/api_limit_error.rb +6 -0
  27. data/lib/my_api_client/errors/client_error.rb +93 -0
  28. data/lib/my_api_client/errors/network_error.rb +43 -0
  29. data/lib/my_api_client/errors/server_error.rb +42 -0
  30. data/lib/my_api_client/request.rb +29 -34
  31. data/lib/my_api_client/request/basic.rb +32 -0
  32. data/lib/my_api_client/request/executor.rb +1 -1
  33. data/lib/my_api_client/request/pagination.rb +39 -0
  34. data/lib/my_api_client/rspec/matchers/request_to.rb +3 -4
  35. data/lib/my_api_client/version.rb +1 -1
  36. data/my_api/.envrc.skeleton +3 -0
  37. data/my_api/.gitignore +14 -0
  38. data/my_api/.jetskeep +1 -0
  39. data/my_api/.rspec +3 -0
  40. data/my_api/.ruby-version +1 -0
  41. data/my_api/Gemfile +23 -0
  42. data/my_api/Gemfile.lock +243 -0
  43. data/my_api/Procfile +7 -0
  44. data/my_api/README.md +54 -0
  45. data/my_api/Rakefile +4 -0
  46. data/my_api/app/controllers/application_controller.rb +5 -0
  47. data/my_api/app/controllers/error_controller.rb +21 -0
  48. data/my_api/app/controllers/pagination_controller.rb +58 -0
  49. data/my_api/app/controllers/rest_controller.rb +60 -0
  50. data/my_api/app/controllers/status_controller.rb +11 -0
  51. data/my_api/app/helpers/application_helper.rb +5 -0
  52. data/my_api/app/jobs/application_job.rb +7 -0
  53. data/my_api/app/models/application_item.rb +5 -0
  54. data/my_api/config.ru +7 -0
  55. data/my_api/config/application.rb +73 -0
  56. data/my_api/config/dynamodb.yml +22 -0
  57. data/my_api/config/environments/development.rb +9 -0
  58. data/my_api/config/environments/production.rb +11 -0
  59. data/my_api/config/environments/test.rb +9 -0
  60. data/my_api/config/routes.rb +17 -0
  61. data/my_api/db/.gitkeep +0 -0
  62. data/my_api/public/404.html +67 -0
  63. data/my_api/public/422.html +67 -0
  64. data/my_api/public/500.html +66 -0
  65. data/my_api/public/favicon.ico +0 -0
  66. data/my_api/public/index.html +91 -0
  67. data/my_api/spec/controllers/error_controller_spec.rb +43 -0
  68. data/my_api/spec/controllers/pagination_controller_spec.rb +73 -0
  69. data/my_api/spec/controllers/rest_controller_spec.rb +99 -0
  70. data/my_api/spec/controllers/status_controller_spec.rb +47 -0
  71. data/my_api/spec/fixtures/payloads/posts-index.json +51 -0
  72. data/my_api/spec/fixtures/payloads/posts-show.json +53 -0
  73. data/my_api/spec/spec_helper.rb +31 -0
  74. data/rails_app/rails_5.2/.rspec +3 -0
  75. data/rails_app/rails_5.2/Gemfile +18 -0
  76. data/rails_app/rails_5.2/Gemfile.lock +171 -0
  77. data/rails_app/rails_5.2/README.md +24 -0
  78. data/rails_app/rails_5.2/Rakefile +8 -0
  79. data/rails_app/rails_5.2/app/controllers/application_controller.rb +4 -0
  80. data/rails_app/rails_5.2/app/jobs/application_job.rb +4 -0
  81. data/rails_app/rails_5.2/bin/bundle +5 -0
  82. data/rails_app/rails_5.2/bin/rails +6 -0
  83. data/rails_app/rails_5.2/bin/rake +6 -0
  84. data/rails_app/rails_5.2/bin/setup +27 -0
  85. data/rails_app/rails_5.2/bin/update +27 -0
  86. data/rails_app/rails_5.2/config.ru +7 -0
  87. data/rails_app/rails_5.2/config/application.rb +37 -0
  88. data/rails_app/rails_5.2/config/boot.rb +6 -0
  89. data/rails_app/rails_5.2/config/credentials.yml.enc +1 -0
  90. data/rails_app/rails_5.2/config/environment.rb +7 -0
  91. data/rails_app/rails_5.2/config/environments/development.rb +41 -0
  92. data/rails_app/rails_5.2/config/environments/production.rb +70 -0
  93. data/rails_app/rails_5.2/config/environments/test.rb +38 -0
  94. data/rails_app/rails_5.2/config/initializers/application_controller_renderer.rb +9 -0
  95. data/rails_app/rails_5.2/config/initializers/backtrace_silencers.rb +8 -0
  96. data/rails_app/rails_5.2/config/initializers/cors.rb +17 -0
  97. data/rails_app/rails_5.2/config/initializers/filter_parameter_logging.rb +6 -0
  98. data/rails_app/rails_5.2/config/initializers/inflections.rb +17 -0
  99. data/rails_app/rails_5.2/config/initializers/mime_types.rb +5 -0
  100. data/rails_app/rails_5.2/config/initializers/wrap_parameters.rb +11 -0
  101. data/rails_app/rails_5.2/config/locales/en.yml +33 -0
  102. data/rails_app/rails_5.2/config/routes.rb +5 -0
  103. data/rails_app/rails_5.2/config/spring.rb +8 -0
  104. data/rails_app/rails_5.2/public/robots.txt +1 -0
  105. data/rails_app/rails_5.2/spec/rails_helper.rb +14 -0
  106. data/rails_app/rails_5.2/spec/spec_helper.rb +13 -0
  107. data/rails_app/rails_6.0/.rspec +3 -0
  108. data/rails_app/rails_6.0/Gemfile +17 -0
  109. data/rails_app/rails_6.0/Gemfile.lock +186 -0
  110. data/rails_app/rails_6.0/README.md +24 -0
  111. data/rails_app/rails_6.0/Rakefile +8 -0
  112. data/rails_app/rails_6.0/app/controllers/application_controller.rb +4 -0
  113. data/rails_app/rails_6.0/app/jobs/application_job.rb +9 -0
  114. data/rails_app/rails_6.0/bin/rails +6 -0
  115. data/rails_app/rails_6.0/bin/rake +6 -0
  116. data/rails_app/rails_6.0/bin/setup +27 -0
  117. data/rails_app/rails_6.0/config.ru +7 -0
  118. data/rails_app/rails_6.0/config/application.rb +39 -0
  119. data/rails_app/rails_6.0/config/boot.rb +6 -0
  120. data/rails_app/rails_6.0/config/credentials.yml.enc +1 -0
  121. data/rails_app/rails_6.0/config/environment.rb +7 -0
  122. data/rails_app/rails_6.0/config/environments/development.rb +39 -0
  123. data/rails_app/rails_6.0/config/environments/production.rb +90 -0
  124. data/rails_app/rails_6.0/config/environments/test.rb +41 -0
  125. data/rails_app/rails_6.0/config/initializers/application_controller_renderer.rb +9 -0
  126. data/rails_app/rails_6.0/config/initializers/backtrace_silencers.rb +8 -0
  127. data/rails_app/rails_6.0/config/initializers/cors.rb +17 -0
  128. data/rails_app/rails_6.0/config/initializers/filter_parameter_logging.rb +6 -0
  129. data/rails_app/rails_6.0/config/initializers/inflections.rb +17 -0
  130. data/rails_app/rails_6.0/config/initializers/mime_types.rb +5 -0
  131. data/rails_app/rails_6.0/config/initializers/wrap_parameters.rb +11 -0
  132. data/rails_app/rails_6.0/config/locales/en.yml +33 -0
  133. data/rails_app/rails_6.0/config/routes.rb +5 -0
  134. data/rails_app/rails_6.0/config/spring.rb +8 -0
  135. data/rails_app/rails_6.0/public/robots.txt +1 -0
  136. data/rails_app/rails_6.0/spec/rails_helper.rb +14 -0
  137. data/rails_app/rails_6.0/spec/spec_helper.rb +13 -0
  138. metadata +120 -5
  139. data/renovate.json +0 -21
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MyApiClient
4
- VERSION = '0.14.0.pre'
4
+ VERSION = '0.17.0'
5
5
  end
@@ -0,0 +1,3 @@
1
+ export AWS_REGION=ap-northeast-1
2
+ export AWS_ACCESS_KEY_ID={AWS Access Key ID}
3
+ export AWS_SECRET_ACCESS_KEY={AWS Secret Access Key}
@@ -0,0 +1,14 @@
1
+ *.gem
2
+ .bundle
3
+ .byebug_history
4
+ .DS_Store
5
+ .env
6
+ .env.*
7
+ .envrc
8
+ /node_modules
9
+ /public/packs
10
+ /public/packs-test
11
+ bundled
12
+ coverage
13
+ pkg
14
+ tmp
@@ -0,0 +1 @@
1
+ pack
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.5.7
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'jets'
6
+
7
+ gem 'dynomite'
8
+
9
+ # development and test groups are not bundled as part of the deployment
10
+ group :development, :test do
11
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
12
+ gem 'byebug', platforms: %i[mri mingw x64_mingw]
13
+ gem 'puma'
14
+ gem 'rack'
15
+ gem 'shotgun'
16
+ end
17
+
18
+ group :test do
19
+ gem 'capybara'
20
+ gem 'launchy'
21
+ gem 'rspec'
22
+ gem 'rspec_junit_formatter'
23
+ end
@@ -0,0 +1,243 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionmailer (6.0.3.3)
5
+ actionpack (= 6.0.3.3)
6
+ actionview (= 6.0.3.3)
7
+ activejob (= 6.0.3.3)
8
+ mail (~> 2.5, >= 2.5.4)
9
+ rails-dom-testing (~> 2.0)
10
+ actionpack (6.0.3.3)
11
+ actionview (= 6.0.3.3)
12
+ activesupport (= 6.0.3.3)
13
+ rack (~> 2.0, >= 2.0.8)
14
+ rack-test (>= 0.6.3)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
+ actionview (6.0.3.3)
18
+ activesupport (= 6.0.3.3)
19
+ builder (~> 3.1)
20
+ erubi (~> 1.4)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
+ activejob (6.0.3.3)
24
+ activesupport (= 6.0.3.3)
25
+ globalid (>= 0.3.6)
26
+ activemodel (6.0.3.3)
27
+ activesupport (= 6.0.3.3)
28
+ activerecord (6.0.3.3)
29
+ activemodel (= 6.0.3.3)
30
+ activesupport (= 6.0.3.3)
31
+ activesupport (6.0.3.3)
32
+ concurrent-ruby (~> 1.0, >= 1.0.2)
33
+ i18n (>= 0.7, < 2)
34
+ minitest (~> 5.1)
35
+ tzinfo (~> 1.1)
36
+ zeitwerk (~> 2.2, >= 2.2.2)
37
+ addressable (2.7.0)
38
+ public_suffix (>= 2.0.2, < 5.0)
39
+ aws-eventstream (1.1.0)
40
+ aws-mfa-secure (0.4.2)
41
+ activesupport
42
+ aws-sdk-core
43
+ aws_config
44
+ memoist
45
+ rainbow
46
+ thor
47
+ zeitwerk
48
+ aws-partitions (1.358.0)
49
+ aws-sdk-apigateway (1.49.0)
50
+ aws-sdk-core (~> 3, >= 3.99.0)
51
+ aws-sigv4 (~> 1.1)
52
+ aws-sdk-cloudformation (1.41.0)
53
+ aws-sdk-core (~> 3, >= 3.99.0)
54
+ aws-sigv4 (~> 1.1)
55
+ aws-sdk-cloudwatchlogs (1.34.0)
56
+ aws-sdk-core (~> 3, >= 3.99.0)
57
+ aws-sigv4 (~> 1.1)
58
+ aws-sdk-core (3.104.4)
59
+ aws-eventstream (~> 1, >= 1.0.2)
60
+ aws-partitions (~> 1, >= 1.239.0)
61
+ aws-sigv4 (~> 1.1)
62
+ jmespath (~> 1.0)
63
+ aws-sdk-dynamodb (1.51.0)
64
+ aws-sdk-core (~> 3, >= 3.99.0)
65
+ aws-sigv4 (~> 1.1)
66
+ aws-sdk-kinesis (1.27.0)
67
+ aws-sdk-core (~> 3, >= 3.99.0)
68
+ aws-sigv4 (~> 1.1)
69
+ aws-sdk-kms (1.36.0)
70
+ aws-sdk-core (~> 3, >= 3.99.0)
71
+ aws-sigv4 (~> 1.1)
72
+ aws-sdk-lambda (1.48.0)
73
+ aws-sdk-core (~> 3, >= 3.99.0)
74
+ aws-sigv4 (~> 1.1)
75
+ aws-sdk-s3 (1.78.0)
76
+ aws-sdk-core (~> 3, >= 3.104.3)
77
+ aws-sdk-kms (~> 1)
78
+ aws-sigv4 (~> 1.1)
79
+ aws-sdk-sns (1.29.0)
80
+ aws-sdk-core (~> 3, >= 3.99.0)
81
+ aws-sigv4 (~> 1.1)
82
+ aws-sdk-sqs (1.30.0)
83
+ aws-sdk-core (~> 3, >= 3.99.0)
84
+ aws-sigv4 (~> 1.1)
85
+ aws-sdk-ssm (1.86.0)
86
+ aws-sdk-core (~> 3, >= 3.99.0)
87
+ aws-sigv4 (~> 1.1)
88
+ aws-sigv4 (1.2.2)
89
+ aws-eventstream (~> 1, >= 1.0.2)
90
+ aws_config (0.1.0)
91
+ builder (3.2.4)
92
+ byebug (11.1.3)
93
+ capybara (3.33.0)
94
+ addressable
95
+ mini_mime (>= 0.1.3)
96
+ nokogiri (~> 1.8)
97
+ rack (>= 1.6.0)
98
+ rack-test (>= 0.6.3)
99
+ regexp_parser (~> 1.5)
100
+ xpath (~> 3.2)
101
+ cfn_camelizer (0.4.9)
102
+ activesupport
103
+ memoist
104
+ rainbow
105
+ cfnresponse (0.4.0)
106
+ concurrent-ruby (1.1.7)
107
+ crass (1.0.6)
108
+ diff-lcs (1.3)
109
+ dotenv (2.7.6)
110
+ dynomite (1.2.6)
111
+ activesupport
112
+ aws-sdk-dynamodb
113
+ rainbow
114
+ erubi (1.9.0)
115
+ gems (1.2.0)
116
+ globalid (0.4.2)
117
+ activesupport (>= 4.2.0)
118
+ hashie (4.1.0)
119
+ i18n (1.8.5)
120
+ concurrent-ruby (~> 1.0)
121
+ jets (2.3.17)
122
+ actionmailer (~> 6.0.0)
123
+ actionpack (~> 6.0.0)
124
+ actionview (~> 6.0.0)
125
+ activerecord (~> 6.0.0)
126
+ activesupport (~> 6.0.0)
127
+ aws-mfa-secure (~> 0.4.0)
128
+ aws-sdk-apigateway
129
+ aws-sdk-cloudformation
130
+ aws-sdk-cloudwatchlogs
131
+ aws-sdk-dynamodb
132
+ aws-sdk-kinesis
133
+ aws-sdk-lambda
134
+ aws-sdk-s3
135
+ aws-sdk-sns
136
+ aws-sdk-sqs
137
+ aws-sdk-ssm
138
+ cfn_camelizer (~> 0.4.6)
139
+ cfnresponse
140
+ dotenv
141
+ gems
142
+ hashie
143
+ jets-gems
144
+ jets-html-sanitizer
145
+ kramdown
146
+ memoist
147
+ mimemagic
148
+ rack
149
+ railties (~> 6.0.0)
150
+ rainbow
151
+ recursive-open-struct
152
+ shotgun
153
+ text-table
154
+ thor
155
+ zeitwerk
156
+ jets-gems (0.2.2)
157
+ gems
158
+ jets-html-sanitizer (1.0.4)
159
+ loofah (~> 2.2, >= 2.2.2)
160
+ jmespath (1.4.0)
161
+ kramdown (2.3.0)
162
+ rexml
163
+ launchy (2.5.0)
164
+ addressable (~> 2.7)
165
+ loofah (2.7.0)
166
+ crass (~> 1.0.2)
167
+ nokogiri (>= 1.5.9)
168
+ mail (2.7.1)
169
+ mini_mime (>= 0.1.1)
170
+ memoist (0.16.2)
171
+ method_source (1.0.0)
172
+ mimemagic (0.3.5)
173
+ mini_mime (1.0.2)
174
+ mini_portile2 (2.4.0)
175
+ minitest (5.14.2)
176
+ nio4r (2.5.4)
177
+ nokogiri (1.10.10)
178
+ mini_portile2 (~> 2.4.0)
179
+ public_suffix (4.0.5)
180
+ puma (5.0.0)
181
+ nio4r (~> 2.0)
182
+ rack (2.2.3)
183
+ rack-test (1.1.0)
184
+ rack (>= 1.0, < 3)
185
+ rails-dom-testing (2.0.3)
186
+ activesupport (>= 4.2.0)
187
+ nokogiri (>= 1.6)
188
+ rails-html-sanitizer (1.3.0)
189
+ loofah (~> 2.3)
190
+ railties (6.0.3.3)
191
+ actionpack (= 6.0.3.3)
192
+ activesupport (= 6.0.3.3)
193
+ method_source
194
+ rake (>= 0.8.7)
195
+ thor (>= 0.20.3, < 2.0)
196
+ rainbow (3.0.0)
197
+ rake (13.0.1)
198
+ recursive-open-struct (1.1.2)
199
+ regexp_parser (1.7.1)
200
+ rexml (3.2.4)
201
+ rspec (3.9.0)
202
+ rspec-core (~> 3.9.0)
203
+ rspec-expectations (~> 3.9.0)
204
+ rspec-mocks (~> 3.9.0)
205
+ rspec-core (3.9.1)
206
+ rspec-support (~> 3.9.1)
207
+ rspec-expectations (3.9.1)
208
+ diff-lcs (>= 1.2.0, < 2.0)
209
+ rspec-support (~> 3.9.0)
210
+ rspec-mocks (3.9.1)
211
+ diff-lcs (>= 1.2.0, < 2.0)
212
+ rspec-support (~> 3.9.0)
213
+ rspec-support (3.9.2)
214
+ rspec_junit_formatter (0.4.1)
215
+ rspec-core (>= 2, < 4, != 2.12.0)
216
+ shotgun (0.9.2)
217
+ rack (>= 1.0)
218
+ text-table (1.2.4)
219
+ thor (1.0.1)
220
+ thread_safe (0.3.6)
221
+ tzinfo (1.2.7)
222
+ thread_safe (~> 0.1)
223
+ xpath (3.2.0)
224
+ nokogiri (~> 1.8)
225
+ zeitwerk (2.4.0)
226
+
227
+ PLATFORMS
228
+ ruby
229
+
230
+ DEPENDENCIES
231
+ byebug
232
+ capybara
233
+ dynomite
234
+ jets
235
+ launchy
236
+ puma
237
+ rack
238
+ rspec
239
+ rspec_junit_formatter
240
+ shotgun
241
+
242
+ BUNDLED WITH
243
+ 2.1.4
@@ -0,0 +1,7 @@
1
+ local: dynamodb-local # port 8000
2
+ admin: env AWS_ACCESS_KEY_ID=$DYNAMODB_ADMIN_AWS_ACCESS_KEY_ID PORT=8001 dynamodb-admin # port 8001
3
+ # web: jets server # port 8888
4
+
5
+ # Using Procfile to just start local dynamodb services for now.
6
+ # To start jets server for now use:
7
+ # jets server
@@ -0,0 +1,54 @@
1
+ # My API
2
+
3
+ This is the real API for integration testing with `my_api_client`.
4
+
5
+ It's built by [Ruby on Jets](https://rubyonjets.com/).
6
+
7
+ ## APIs
8
+
9
+ ### My Rest API
10
+
11
+ This is a simple REST API that returns a specified response.
12
+
13
+ * `GET rest`
14
+ * `GET rest/:id`
15
+ * `POST rest`
16
+ * `POST/PUT/PATCH rest/:id`
17
+ * `DELETE rest/:id`
18
+
19
+ ### My Status API
20
+
21
+ This API returns arbitrary status code.
22
+
23
+ * `GET status/:status`
24
+
25
+ ### My Error API
26
+
27
+ This API returns arbitrary error code as JSON.
28
+
29
+ * `GET error/:code`
30
+
31
+ ### My Pagination API
32
+
33
+ This API returns a response including pagination links.
34
+
35
+ * `GET pagination?page=1`
36
+
37
+ ## Deployment
38
+
39
+ You need to prepare following environment variables:
40
+
41
+ * `AWS_REGION`
42
+ * `AWS_ACCESS_KEY_ID`
43
+ * `AWS_SECRET_ACCESS_KEY`
44
+
45
+ For information on how to create an AWS access key and secret, see the following site:
46
+
47
+ :link: [Minimal Deploy IAM Policy \- Jets Ruby Serverless Framework](https://rubyonjets.com/docs/extras/minimal-deploy-iam/)
48
+
49
+
50
+ And execute following command:
51
+
52
+ ```sh
53
+ $ bundle exec jets deploy
54
+ ```
@@ -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,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