my_api_client 0.16.1 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +90 -15
  3. data/.rubocop.yml +4 -0
  4. data/.rubocop_challenge.yml +2 -0
  5. data/.rubocop_todo.yml +24 -1
  6. data/CHANGELOG.md +25 -0
  7. data/Gemfile.lock +14 -15
  8. data/README.jp.md +60 -0
  9. data/lib/generators/rspec/templates/api_client_spec.rb.erb +22 -15
  10. data/lib/my_api_client/base.rb +2 -2
  11. data/lib/my_api_client/errors.rb +1 -0
  12. data/lib/my_api_client/request/executor.rb +1 -1
  13. data/lib/my_api_client/version.rb +1 -1
  14. data/my_api/Gemfile.lock +24 -24
  15. data/rails_app/rails_5.2/.rspec +3 -0
  16. data/rails_app/rails_5.2/Gemfile +18 -0
  17. data/rails_app/rails_5.2/Gemfile.lock +171 -0
  18. data/rails_app/rails_5.2/README.md +24 -0
  19. data/rails_app/rails_5.2/Rakefile +8 -0
  20. data/rails_app/rails_5.2/app/controllers/application_controller.rb +4 -0
  21. data/rails_app/rails_5.2/app/jobs/application_job.rb +4 -0
  22. data/rails_app/rails_5.2/bin/bundle +5 -0
  23. data/rails_app/rails_5.2/bin/rails +6 -0
  24. data/rails_app/rails_5.2/bin/rake +6 -0
  25. data/rails_app/rails_5.2/bin/setup +27 -0
  26. data/rails_app/rails_5.2/bin/update +27 -0
  27. data/rails_app/rails_5.2/config.ru +7 -0
  28. data/rails_app/rails_5.2/config/application.rb +37 -0
  29. data/rails_app/rails_5.2/config/boot.rb +6 -0
  30. data/rails_app/rails_5.2/config/credentials.yml.enc +1 -0
  31. data/rails_app/rails_5.2/config/environment.rb +7 -0
  32. data/rails_app/rails_5.2/config/environments/development.rb +41 -0
  33. data/rails_app/rails_5.2/config/environments/production.rb +70 -0
  34. data/rails_app/rails_5.2/config/environments/test.rb +38 -0
  35. data/rails_app/rails_5.2/config/initializers/application_controller_renderer.rb +9 -0
  36. data/rails_app/rails_5.2/config/initializers/backtrace_silencers.rb +8 -0
  37. data/rails_app/rails_5.2/config/initializers/cors.rb +17 -0
  38. data/rails_app/rails_5.2/config/initializers/filter_parameter_logging.rb +6 -0
  39. data/rails_app/rails_5.2/config/initializers/inflections.rb +17 -0
  40. data/rails_app/rails_5.2/config/initializers/mime_types.rb +5 -0
  41. data/rails_app/rails_5.2/config/initializers/wrap_parameters.rb +11 -0
  42. data/rails_app/rails_5.2/config/locales/en.yml +33 -0
  43. data/rails_app/rails_5.2/config/routes.rb +5 -0
  44. data/rails_app/rails_5.2/config/spring.rb +8 -0
  45. data/rails_app/rails_5.2/public/robots.txt +1 -0
  46. data/rails_app/rails_5.2/spec/rails_helper.rb +14 -0
  47. data/rails_app/rails_5.2/spec/spec_helper.rb +13 -0
  48. data/rails_app/rails_6.0/.rspec +3 -0
  49. data/rails_app/rails_6.0/Gemfile +17 -0
  50. data/rails_app/rails_6.0/Gemfile.lock +186 -0
  51. data/rails_app/rails_6.0/README.md +24 -0
  52. data/rails_app/rails_6.0/Rakefile +8 -0
  53. data/rails_app/rails_6.0/app/controllers/application_controller.rb +4 -0
  54. data/rails_app/rails_6.0/app/jobs/application_job.rb +9 -0
  55. data/rails_app/rails_6.0/bin/rails +6 -0
  56. data/rails_app/rails_6.0/bin/rake +6 -0
  57. data/rails_app/rails_6.0/bin/setup +27 -0
  58. data/rails_app/rails_6.0/config.ru +7 -0
  59. data/rails_app/rails_6.0/config/application.rb +39 -0
  60. data/rails_app/rails_6.0/config/boot.rb +6 -0
  61. data/rails_app/rails_6.0/config/credentials.yml.enc +1 -0
  62. data/rails_app/rails_6.0/config/environment.rb +7 -0
  63. data/rails_app/rails_6.0/config/environments/development.rb +39 -0
  64. data/rails_app/rails_6.0/config/environments/production.rb +90 -0
  65. data/rails_app/rails_6.0/config/environments/test.rb +41 -0
  66. data/rails_app/rails_6.0/config/initializers/application_controller_renderer.rb +9 -0
  67. data/rails_app/rails_6.0/config/initializers/backtrace_silencers.rb +8 -0
  68. data/rails_app/rails_6.0/config/initializers/cors.rb +17 -0
  69. data/rails_app/rails_6.0/config/initializers/filter_parameter_logging.rb +6 -0
  70. data/rails_app/rails_6.0/config/initializers/inflections.rb +17 -0
  71. data/rails_app/rails_6.0/config/initializers/mime_types.rb +5 -0
  72. data/rails_app/rails_6.0/config/initializers/wrap_parameters.rb +11 -0
  73. data/rails_app/rails_6.0/config/locales/en.yml +33 -0
  74. data/rails_app/rails_6.0/config/routes.rb +5 -0
  75. data/rails_app/rails_6.0/config/spring.rb +8 -0
  76. data/rails_app/rails_6.0/public/robots.txt +1 -0
  77. data/rails_app/rails_6.0/spec/rails_helper.rb +14 -0
  78. data/rails_app/rails_6.0/spec/spec_helper.rb +13 -0
  79. metadata +66 -2
@@ -11,16 +11,28 @@ RSpec.describe <%= "#{class_name}ApiClient" %>, <%= type_metatag(:api_client) %>
11
11
  end
12
12
 
13
13
  shared_examples 'to handle errors' do
14
- it do
15
- expect { api_request }
16
- .to be_handled_as_an_error(MyApiClient::ClientError)
17
- .when_receive(status_code: 400)
14
+ context 'when the API returns 200 OK' do
15
+ it do
16
+ expect { api_request }
17
+ .not_to be_handled_as_an_error
18
+ .when_receive(status_code: 200)
19
+ end
18
20
  end
19
21
 
20
- it do
21
- expect { api_request }
22
- .to be_handled_as_an_error(MyApiClient::ServerError)
23
- .when_receive(status_code: 500)
22
+ context 'when the API returns 400 Bad Request' do
23
+ it do
24
+ expect { api_request }
25
+ .to be_handled_as_an_error(MyApiClient::ClientError::BadRequest)
26
+ .when_receive(status_code: 400)
27
+ end
28
+ end
29
+
30
+ context 'when the API returns 500 Internal Server Error' do
31
+ it do
32
+ expect { api_request }
33
+ .to be_handled_as_an_error(MyApiClient::ServerError::InternalServerError)
34
+ .when_receive(status_code: 500)
35
+ end
24
36
  end
25
37
  end
26
38
  <% yeild_request_arguments do |action, http_method, pathname| -%>
@@ -28,6 +40,8 @@ RSpec.describe <%= "#{class_name}ApiClient" %>, <%= type_metatag(:api_client) %>
28
40
  describe '#<%= action %>' do
29
41
  subject(:api_request) { api_client.<%= action %> }
30
42
 
43
+ it_behaves_like 'to handle errors'
44
+
31
45
  it do
32
46
  expect { api_request }
33
47
  .to request_to(:<%= http_method %>, 'https://example.com/<%= pathname %>')
@@ -37,13 +51,6 @@ RSpec.describe <%= "#{class_name}ApiClient" %>, <%= type_metatag(:api_client) %>
37
51
  .with(headers: headers, body: {})
38
52
  <% end -%>
39
53
  end
40
-
41
- it_behaves_like 'to handle errors' do
42
- it do
43
- expect { api_request }.not_to be_handled_as_an_error
44
- .when_receive(status_code: 200, body: nil, headers: nil)
45
- end
46
- end
47
54
  end
48
55
  <% end -%>
49
56
  end
@@ -9,12 +9,12 @@ module MyApiClient
9
9
  include MyApiClient::Request
10
10
 
11
11
  if ActiveSupport::VERSION::STRING >= '5.2.0'
12
- class_attribute :logger, instance_writer: false, default: ::Logger.new(STDOUT)
12
+ class_attribute :logger, instance_writer: false, default: ::Logger.new($stdout)
13
13
  class_attribute :error_handlers, instance_writer: false, default: []
14
14
  else
15
15
  class_attribute :logger
16
16
  class_attribute :error_handlers
17
- self.logger = ::Logger.new(STDOUT)
17
+ self.logger = ::Logger.new($stdout)
18
18
  self.error_handlers = []
19
19
  end
20
20
 
@@ -4,6 +4,7 @@ module MyApiClient
4
4
  # The ancestor class for all API request error
5
5
  class Error < StandardError
6
6
  attr_reader :params
7
+
7
8
  delegate :metadata, to: :params
8
9
  alias to_bugsnag metadata
9
10
 
@@ -32,7 +32,7 @@ module MyApiClient
32
32
  def call
33
33
  request_logger.info('Start')
34
34
  response = api_request
35
- request_logger.info("Duration #{response.timing} sec")
35
+ request_logger.info("Duration #{response.timing.in_milliseconds} msec")
36
36
  verify(response)
37
37
  rescue MyApiClient::Error => e
38
38
  request_logger.warn("Failure (#{e.message})")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MyApiClient
4
- VERSION = '0.16.1'
4
+ VERSION = '0.17.0'
5
5
  end
@@ -1,34 +1,34 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- actionmailer (6.0.3.2)
5
- actionpack (= 6.0.3.2)
6
- actionview (= 6.0.3.2)
7
- activejob (= 6.0.3.2)
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
8
  mail (~> 2.5, >= 2.5.4)
9
9
  rails-dom-testing (~> 2.0)
10
- actionpack (6.0.3.2)
11
- actionview (= 6.0.3.2)
12
- activesupport (= 6.0.3.2)
10
+ actionpack (6.0.3.3)
11
+ actionview (= 6.0.3.3)
12
+ activesupport (= 6.0.3.3)
13
13
  rack (~> 2.0, >= 2.0.8)
14
14
  rack-test (>= 0.6.3)
15
15
  rails-dom-testing (~> 2.0)
16
16
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
- actionview (6.0.3.2)
18
- activesupport (= 6.0.3.2)
17
+ actionview (6.0.3.3)
18
+ activesupport (= 6.0.3.3)
19
19
  builder (~> 3.1)
20
20
  erubi (~> 1.4)
21
21
  rails-dom-testing (~> 2.0)
22
22
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
- activejob (6.0.3.2)
24
- activesupport (= 6.0.3.2)
23
+ activejob (6.0.3.3)
24
+ activesupport (= 6.0.3.3)
25
25
  globalid (>= 0.3.6)
26
- activemodel (6.0.3.2)
27
- activesupport (= 6.0.3.2)
28
- activerecord (6.0.3.2)
29
- activemodel (= 6.0.3.2)
30
- activesupport (= 6.0.3.2)
31
- activesupport (6.0.3.2)
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
32
  concurrent-ruby (~> 1.0, >= 1.0.2)
33
33
  i18n (>= 0.7, < 2)
34
34
  minitest (~> 5.1)
@@ -162,7 +162,7 @@ GEM
162
162
  rexml
163
163
  launchy (2.5.0)
164
164
  addressable (~> 2.7)
165
- loofah (2.6.0)
165
+ loofah (2.7.0)
166
166
  crass (~> 1.0.2)
167
167
  nokogiri (>= 1.5.9)
168
168
  mail (2.7.1)
@@ -172,12 +172,12 @@ GEM
172
172
  mimemagic (0.3.5)
173
173
  mini_mime (1.0.2)
174
174
  mini_portile2 (2.4.0)
175
- minitest (5.14.1)
176
- nio4r (2.5.2)
175
+ minitest (5.14.2)
176
+ nio4r (2.5.4)
177
177
  nokogiri (1.10.10)
178
178
  mini_portile2 (~> 2.4.0)
179
179
  public_suffix (4.0.5)
180
- puma (4.3.5)
180
+ puma (5.0.0)
181
181
  nio4r (~> 2.0)
182
182
  rack (2.2.3)
183
183
  rack-test (1.1.0)
@@ -187,9 +187,9 @@ GEM
187
187
  nokogiri (>= 1.6)
188
188
  rails-html-sanitizer (1.3.0)
189
189
  loofah (~> 2.3)
190
- railties (6.0.3.2)
191
- actionpack (= 6.0.3.2)
192
- activesupport (= 6.0.3.2)
190
+ railties (6.0.3.3)
191
+ actionpack (= 6.0.3.3)
192
+ activesupport (= 6.0.3.3)
193
193
  method_source
194
194
  rake (>= 0.8.7)
195
195
  thor (>= 0.20.3, < 2.0)
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,18 @@
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
+ gem 'sprockets', '~> 3.0' # for ruby 2.4
10
+
11
+ group :development, :test do
12
+ gem 'byebug', platforms: %i[mri mingw x64_mingw]
13
+ gem 'rspec-rails'
14
+ end
15
+
16
+ group :development do
17
+ gem 'spring'
18
+ end
@@ -0,0 +1,171 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ my_api_client (0.17.0)
5
+ activesupport (>= 4.2.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
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationController < ActionController::API
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
5
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ APP_PATH = File.expand_path('../config/application', __dir__)
5
+ require_relative '../config/boot'
6
+ require 'rails/commands'