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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d52de78feca8df4a1daac75f796382190d0f383c5f0e379111544d18ae863627
4
- data.tar.gz: 76fd03b48893738aa1a1953592c877eba6dd43a6b9c4066a197453f9425ecfa7
3
+ metadata.gz: f0b010bd5bb4ef7d0b3a99c826fefc67bedf5e9f51bcfd7779dc618c2b9a4f58
4
+ data.tar.gz: 4806eb56f7556728fc848c7e54408a127393a921a29e248a9d32ba950b4f3ef3
5
5
  SHA512:
6
- metadata.gz: 95069064c4d7e6f31abbe302db40d11f574726c11631513d3e40b3fd158e77e95ab81079d0fd4033833aac826722455938fc69605acbee0c2ecb58b11a3c949f
7
- data.tar.gz: 2c5fceee08ba837afb4901feca3d531e09c8a5d4c2ba6756b2eddd9f185050686e1eed304e077f82aa2f4aa85fe1cb723c17ec7de32470210fc1347cc94ea5fa
6
+ metadata.gz: 6bc2efb59de265f84c727ce67e9717fff724251136ffe7159a0a61151d335bb476386649e23ef5bb8a9982e387bebd53c58064817517fdac855bd9ac3fc4d6e8
7
+ data.tar.gz: f0db303e86287d71099d0c0e29024663013cf4c44dffac1ac1d9c2a18113b34a4d5a1e9a6d3a4824833d1bb413a875deb0a45bb2f2becb25d4119d1028a1d10c
@@ -25,7 +25,13 @@ references:
25
25
  default: ''
26
26
 
27
27
  executors:
28
- default:
28
+ executor_for_api:
29
+ parameters:
30
+ <<: *ruby_version
31
+ docker:
32
+ - image: circleci/ruby:<< parameters.ruby_version >>-node-browsers
33
+ working_directory: ~/repo/my_api
34
+ executor_for_gem:
29
35
  parameters:
30
36
  <<: *ruby_version
31
37
  docker:
@@ -41,8 +47,28 @@ commands:
41
47
  - run: |
42
48
  cp gemfiles/rails_<< parameters.rails_version >>.gemfile Gemfile
43
49
  bundle update activesupport
44
- run_rspec:
45
- description: Run RSpec
50
+ run_rspec_for_api:
51
+ description: Run RSpec for the API
52
+ steps:
53
+ - run:
54
+ name: Execute RSpec
55
+ command: |
56
+ bundle exec rspec --format documentation \
57
+ --color \
58
+ --format RspecJunitFormatter
59
+ deploy_api_server:
60
+ description: Deploy the API server on the AWS
61
+ steps:
62
+ - run:
63
+ name: Install RSync
64
+ command: sudo apt-get install -y rsync
65
+ - run:
66
+ # This command is not currently work. It could't reference uploaded gem file.
67
+ # You can execute `$ bundle exec jets deploy` on your local.
68
+ name: Deploy the API server with jets
69
+ command: JETS_AGREE=yes bundle exec jets deploy
70
+ run_rspec_for_gem:
71
+ description: Run RSpec for the gem
46
72
  steps:
47
73
  - code-climate/install
48
74
  - run:
@@ -114,40 +140,57 @@ commands:
114
140
  <<: *ruby_version
115
141
  <<: *bundler_options
116
142
  steps:
117
- - checkout
143
+ - checkout:
144
+ path: ~/repo
118
145
  - run:
119
146
  name: Install Bundler 2.x
120
147
  command: gem install bundler:2.1.2
121
148
  - ruby-orbs/bundle-install:
122
149
  cache_key_prefix: v1-dependencies-<< parameters.ruby_version >>
123
150
  bundle_extra_args: << parameters.bundler_options >>
124
- test_and_build:
151
+ restore_bundled_with: false
152
+ test_and_deploy_for_api:
153
+ description: Build the API
154
+ steps:
155
+ - run_rspec_for_api
156
+ - deploy_api_server
157
+ test_and_build_for_gem:
125
158
  description: Build the RubyGem
126
159
  parameters:
127
160
  <<: *rails_version
128
161
  steps:
129
162
  - modify_active_support_version:
130
163
  rails_version: << parameters.rails_version >>
131
- - run_rspec
164
+ - run_rspec_for_gem
132
165
  - rake_build
133
166
 
134
167
  jobs:
135
- build:
168
+ deploy_api:
169
+ parameters:
170
+ <<: *ruby_version
171
+ executor:
172
+ name: executor_for_api
173
+ ruby_version: << parameters.ruby_version >>
174
+ steps:
175
+ - setup:
176
+ ruby_version: << parameters.ruby_version >>
177
+ - test_and_deploy_for_api
178
+ build_gem:
136
179
  parameters:
137
180
  <<: *ruby_version
138
181
  <<: *rails_version
139
182
  <<: *bundler_options
140
183
  executor:
141
- name: default
184
+ name: executor_for_gem
142
185
  ruby_version: << parameters.ruby_version >>
143
186
  steps:
144
187
  - setup:
145
188
  ruby_version: << parameters.ruby_version >>
146
189
  bundler_options: << parameters.bundler_options >>
147
- - test_and_build:
190
+ - test_and_build_for_gem:
148
191
  rails_version: << parameters.rails_version >>
149
192
  upload-coverage:
150
- executor: default
193
+ executor: executor_for_gem
151
194
  steps:
152
195
  - attach_workspace:
153
196
  at: ~/repo
@@ -157,22 +200,22 @@ jobs:
157
200
  parts: 19
158
201
  - code-climate/upload-coverage
159
202
  rubocop:
160
- executor: default
203
+ executor: executor_for_gem
161
204
  steps:
162
205
  - setup
163
206
  - rubocop
164
207
  yardoc:
165
- executor: default
208
+ executor: executor_for_gem
166
209
  steps:
167
210
  - setup
168
211
  - yardoc
169
212
  rubocop_challenge:
170
- executor: default
213
+ executor: executor_for_gem
171
214
  steps:
172
215
  - checkout
173
216
  - rubocop_challenge
174
217
  release:
175
- executor: default
218
+ executor: executor_for_gem
176
219
  steps:
177
220
  - setup
178
221
  - release
@@ -182,80 +225,80 @@ workflows:
182
225
 
183
226
  commit:
184
227
  jobs:
185
- - build:
228
+ - build_gem:
186
229
  name: build_on_ruby_2.4_and_rails_4.2
187
230
  ruby_version: '2.4'
188
231
  rails_version: '4.2'
189
- - build:
232
+ - build_gem:
190
233
  name: build_on_ruby_2.4_and_rails_5.0
191
234
  ruby_version: '2.4'
192
235
  rails_version: '5.0'
193
- - build:
236
+ - build_gem:
194
237
  name: build_on_ruby_2.4_and_rails_5.1
195
238
  ruby_version: '2.4'
196
239
  rails_version: '5.1'
197
- - build:
240
+ - build_gem:
198
241
  name: build_on_ruby_2.4_and_rails_5.2
199
242
  ruby_version: '2.4'
200
243
  rails_version: '5.2'
201
- - build:
244
+ - build_gem:
202
245
  name: build_on_ruby_2.5_and_rails_4.2
203
246
  ruby_version: '2.5'
204
247
  rails_version: '4.2'
205
- - build:
248
+ - build_gem:
206
249
  name: build_on_ruby_2.5_and_rails_5.0
207
250
  ruby_version: '2.5'
208
251
  rails_version: '5.0'
209
- - build:
252
+ - build_gem:
210
253
  name: build_on_ruby_2.5_and_rails_5.1
211
254
  ruby_version: '2.5'
212
255
  rails_version: '5.1'
213
- - build:
256
+ - build_gem:
214
257
  name: build_on_ruby_2.5_and_rails_5.2
215
258
  ruby_version: '2.5'
216
259
  rails_version: '5.2'
217
- - build:
260
+ - build_gem:
218
261
  name: build_on_ruby_2.5_and_rails_6.0
219
262
  ruby_version: '2.5'
220
263
  rails_version: '6.0'
221
- - build:
264
+ - build_gem:
222
265
  name: build_on_ruby_2.6_and_rails_4.2
223
266
  ruby_version: '2.6'
224
267
  rails_version: '4.2'
225
- - build:
268
+ - build_gem:
226
269
  name: build_on_ruby_2.6_and_rails_5.0
227
270
  ruby_version: '2.6'
228
271
  rails_version: '5.0'
229
- - build:
272
+ - build_gem:
230
273
  name: build_on_ruby_2.6_and_rails_5.1
231
274
  ruby_version: '2.6'
232
275
  rails_version: '5.1'
233
- - build:
276
+ - build_gem:
234
277
  name: build_on_ruby_2.6_and_rails_5.2
235
278
  ruby_version: '2.6'
236
279
  rails_version: '5.2'
237
- - build:
280
+ - build_gem:
238
281
  name: build_on_ruby_2.6_and_rails_6.0
239
282
  ruby_version: '2.6'
240
283
  rails_version: '6.0'
241
- - build:
284
+ - build_gem:
242
285
  name: build_on_ruby_2.7_and_rails_5.0
243
286
  ruby_version: '2.7'
244
287
  rails_version: '5.0'
245
- - build:
288
+ - build_gem:
246
289
  name: build_on_ruby_2.7_and_rails_5.1
247
290
  ruby_version: '2.7'
248
291
  rails_version: '5.1'
249
- - build:
292
+ - build_gem:
250
293
  name: build_on_ruby_2.7_and_rails_5.2
251
294
  ruby_version: '2.7'
252
295
  rails_version: '5.2'
253
- - build:
296
+ - build_gem:
254
297
  name: build_on_ruby_2.7_and_rails_6.0_with_integrations
255
298
  ruby_version: '2.7'
256
299
  rails_version: '6.0'
257
300
  bundler_options: '--with integrations'
258
- - build:
301
+ - build_gem:
259
302
  name: build_on_ruby_2.7_and_rails_6.0_without_integrations
260
303
  ruby_version: '2.7'
261
304
  rails_version: '6.0'
@@ -317,11 +360,23 @@ workflows:
317
360
  cron: "30 23 * * *" # 8:30am every day (JST)
318
361
  filters:
319
362
  branches:
320
- only:
321
- - master
363
+ only: [master]
322
364
  jobs:
323
365
  - rubocop_challenge
324
366
 
367
+ # deploy_api_server:
368
+ # triggers:
369
+ # - schedule:
370
+ # cron: "0 12 * * *" # 3:00am every day (JST)
371
+ # filters:
372
+ # branches:
373
+ # only: [master]
374
+ # jobs:
375
+ # - deploy_api:
376
+ # ruby_version: '2.5'
377
+ # - build_gem:
378
+ # requires: [deploy_api]
379
+
325
380
  experimental:
326
381
  notify:
327
382
  branches:
@@ -1 +1,2 @@
1
1
  export GITHUB_ACCESS_TOKEN={GITHUB_ACCESS_TOKEN}
2
+ export MY_API_ENDPOINT={API gateway endtpoint of "my_api" for integration testing}
@@ -9,19 +9,22 @@ AllCops:
9
9
 
10
10
  Layout/LineLength:
11
11
  Max: 100
12
+ Exclude:
13
+ - my_api/config/application.rb
12
14
 
13
15
  Metrics/BlockLength:
14
16
  Exclude:
15
17
  - 'my_api_client.gemspec'
16
18
  - 'lib/my_api_client/rspec/matchers/**/*'
17
19
  - 'spec/**/*'
20
+ - 'my_api/spec/**/*'
18
21
 
19
22
  Metrics/MethodLength:
20
23
  Max: 15
21
24
 
22
25
  Naming/AccessorMethodName:
23
26
  Exclude:
24
- - spec/dummy_app/api_clients/example_api_client.rb
27
+ - example/api_clients/**/*
25
28
  - spec/lib/my_api_client/rspec/matchers/be_handled_as_an_error_spec.rb
26
29
 
27
30
  Style/TrailingCommaInArrayLiteral:
@@ -32,6 +35,7 @@ Style/TrailingCommaInHashLiteral:
32
35
 
33
36
  RSpec/DescribeClass:
34
37
  Exclude:
38
+ - 'spec/integrations/api_clients/**/*'
35
39
  - 'spec/lib/my_api_client/rspec/matchers/**/*'
36
40
 
37
41
  RSpec/ExampleLength:
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-02-21 23:30:47 +0000 using RuboCop version 0.80.0.
3
+ # on 2020-02-29 23:30:46 +0000 using RuboCop version 0.80.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -1,6 +1,13 @@
1
1
  # Change log
2
2
 
3
- ## v0.14.0.pre (Feb 23, 2020)
3
+ ## v0.14.0 (Mar 14, 2020)
4
+
5
+ ### Feature
6
+
7
+ * [#211](https://github.com/ryz310/my_api_client/pull/211) Integration testing using the jets framework ([@ryz310](https://github.com/ryz310))
8
+ * [#213](https://github.com/ryz310/my_api_client/pull/213) Add status API to integration testing ([@ryz310](https://github.com/ryz310))
9
+ * [#214](https://github.com/ryz310/my_api_client/pull/214) Add error API to integration testing ([@ryz310](https://github.com/ryz310))
10
+ * [#215](https://github.com/ryz310/my_api_client/pull/215) Update the REST API to enhance integration testing ([@ryz310](https://github.com/ryz310))
4
11
 
5
12
  ### Refactoring
6
13
 
@@ -60,6 +67,7 @@
60
67
  ### Rubocop Challenge
61
68
 
62
69
  * [#205](https://github.com/ryz310/my_api_client/pull/205) Re-generate .rubocop_todo.yml with RuboCop v0.80.0 ([@ryz310](https://github.com/ryz310))
70
+ * [#210](https://github.com/ryz310/my_api_client/pull/210) Re-generate .rubocop_todo.yml with RuboCop v0.80.1 ([@ryz310](https://github.com/ryz310))
63
71
 
64
72
  ### Dependabot
65
73
 
@@ -68,6 +76,7 @@
68
76
  * [#194](https://github.com/ryz310/my_api_client/pull/194) Bump bugsnag from 6.12.2 to 6.13.0 ([@ryz310](https://github.com/ryz310))
69
77
  * [#197](https://github.com/ryz310/my_api_client/pull/197) Bump webmock from 3.8.0 to 3.8.1 ([@ryz310](https://github.com/ryz310))
70
78
  * [#199](https://github.com/ryz310/my_api_client/pull/199) Bump webmock from 3.8.1 to 3.8.2 ([@ryz310](https://github.com/ryz310))
79
+ * [#216](https://github.com/ryz310/my_api_client/pull/216) Bump webmock from 3.8.2 to 3.8.3 ([@ryz310](https://github.com/ryz310))
71
80
 
72
81
  ### Renovate
73
82
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- my_api_client (0.14.0.pre)
4
+ my_api_client (0.14.0)
5
5
  activesupport (>= 4.2.0)
6
6
  faraday (>= 0.17.1)
7
7
  jsonpath
@@ -29,7 +29,7 @@ GEM
29
29
  docile (1.3.2)
30
30
  faraday (1.0.0)
31
31
  multipart-post (>= 1.2, < 3)
32
- hashdiff (1.0.0)
32
+ hashdiff (1.0.1)
33
33
  i18n (1.8.2)
34
34
  concurrent-ruby (~> 1.0)
35
35
  jaro_winkler (1.5.4)
@@ -42,7 +42,7 @@ GEM
42
42
  multi_json (1.14.1)
43
43
  multipart-post (2.1.1)
44
44
  parallel (1.19.1)
45
- parser (2.7.0.2)
45
+ parser (2.7.0.4)
46
46
  ast (~> 2.4.0)
47
47
  pry (0.12.2)
48
48
  coderay (~> 1.1.0)
@@ -60,7 +60,7 @@ GEM
60
60
  rspec-mocks (~> 3.9.0)
61
61
  rspec-core (3.9.1)
62
62
  rspec-support (~> 3.9.1)
63
- rspec-expectations (3.9.0)
63
+ rspec-expectations (3.9.1)
64
64
  diff-lcs (>= 1.2.0, < 2.0)
65
65
  rspec-support (~> 3.9.0)
66
66
  rspec-mocks (3.9.1)
@@ -69,7 +69,7 @@ GEM
69
69
  rspec-support (3.9.2)
70
70
  rspec_junit_formatter (0.4.1)
71
71
  rspec-core (>= 2, < 4, != 2.12.0)
72
- rubocop (0.80.0)
72
+ rubocop (0.80.1)
73
73
  jaro_winkler (~> 1.5.1)
74
74
  parallel (~> 1.10)
75
75
  parser (>= 2.7.0.1)
@@ -96,7 +96,7 @@ GEM
96
96
  tzinfo (1.2.6)
97
97
  thread_safe (~> 0.1)
98
98
  unicode-display_width (1.6.1)
99
- webmock (3.8.2)
99
+ webmock (3.8.3)
100
100
  addressable (>= 2.3.6)
101
101
  crack (>= 0.3.2)
102
102
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'my_errors'
4
+
5
+ # An usage example of the `my_api_client`.
6
+ class ApplicationApiClient < MyApiClient::Base
7
+ endpoint ENV['MY_API_ENDPOINT']
8
+
9
+ self.logger = ::Logger.new(nil)
10
+
11
+ http_open_timeout 2.seconds
12
+ http_read_timeout 3.seconds
13
+
14
+ retry_on MyApiClient::NetworkError, wait: 0.seconds, attempts: 3
15
+
16
+ error_handling status_code: 400..499, raise: MyApiClient::ClientError
17
+ error_handling status_code: 500..599 do |params, logger|
18
+ logger.warn 'Server error occurred.'
19
+ raise MyApiClient::ServerError, params
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'application_api_client'
4
+
5
+ # An usage example of the `my_api_client`.
6
+ # See also: my_api/app/controllers/status_controller.rb
7
+ class MyErrorApiClient < ApplicationApiClient
8
+ error_handling json: { '$.error.message': /You requested error code/ },
9
+ raise: MyErrors::ErrorCodeOther
10
+
11
+ error_handling json: { '$.error.code': :zero? },
12
+ raise: MyErrors::ErrorCode00
13
+
14
+ error_handling json: { '$.error.code': 10 },
15
+ raise: MyErrors::ErrorCode10
16
+
17
+ error_handling json: { '$.error.code': 20..29 },
18
+ raise: MyErrors::ErrorCode2x
19
+
20
+ error_handling json: { '$.error.code': 30 },
21
+ status_code: 400,
22
+ raise: MyErrors::ErrorCode30
23
+
24
+ # GET error/:code
25
+ def get_error(code:)
26
+ get "error/#{code}", headers: headers
27
+ end
28
+
29
+ private
30
+
31
+ def headers
32
+ { 'Content-Type': 'application/json;charset=UTF-8' }
33
+ end
34
+ end