my_api_client 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3ada9d2c8dbfadb9462b2cff381e9ccaf822a543f63672f6e5fdcd99f9ce4ed
4
- data.tar.gz: b00cc646de8c05bc5378645940732e7dec5fc80d0dd4380e816f0a228e8b6f00
3
+ metadata.gz: e0499ab884898c6a2b95fc688c095b7a3682f91dc1b5668b24bfb821a4d0a1c3
4
+ data.tar.gz: bc2d95d4973ef859aa5d95dba8adfa1f2378dfe396e53a303e223a480d93af34
5
5
  SHA512:
6
- metadata.gz: 977d55b39c0a35d56d4ff2ddc142765a7807f2b027471186d947cda8ea4f606d81fbfc842524318c9630f48a88aeb5adea5cc7e948233323f3072200e624d034
7
- data.tar.gz: e8d4f395990d049afddc3e380044e5f65ad57d0130da1b08114d4bf28965a0d53fe756d147ebf17c7ffac3b236fc8c3f9e7fc7c74edfb90e9f57b0ed94b10930
6
+ metadata.gz: 8ceb42331cb908e84d9555d33fffcbed248260d7b06345edc13effbfad2d13db213b1f1b37db40060b6d32792066821ab7c703720998c8e0bb91ea92bfa7599d
7
+ data.tar.gz: 560c704e9545c3ba16a04dabddd1ecc027b6c16591f710fc288bb7343d599c63c9dfb18ee142a3269ce87f95ea7a4f2ff9ee47ae72d8adb422886c6f772dbb8d
data/.circleci/config.yml CHANGED
@@ -4,6 +4,10 @@
4
4
  #
5
5
  version: 2.1
6
6
 
7
+ orbs:
8
+ ruby-orbs: sue445/ruby-orbs@1.4.3
9
+ code-climate: rvla/code-climate@0.0.2
10
+
7
11
  references:
8
12
  - &ruby_version
9
13
  ruby_version:
@@ -15,6 +19,10 @@ references:
15
19
  type: enum
16
20
  enum: ['4.2', '5.0', '5.1', '5.2']
17
21
  default: '4.2'
22
+ - &bundler_options
23
+ bundler_options:
24
+ type: string
25
+ default: ''
18
26
 
19
27
  executors:
20
28
  default:
@@ -25,30 +33,6 @@ executors:
25
33
  working_directory: ~/repo
26
34
 
27
35
  commands:
28
- download_cc_test_reporter:
29
- description: 'Download cc-test-reporter'
30
- steps:
31
- - run: |
32
- mkdir -p tmp/
33
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
34
- chmod +x ./tmp/cc-test-reporter
35
- setup_bundle:
36
- description: Setup Bundle
37
- parameters:
38
- <<: *ruby_version
39
- steps:
40
- - restore_cache:
41
- keys:
42
- - v1-dependencies-<< parameters.ruby_version >>-{{ checksum "Gemfile.lock" }}
43
- - v1-dependencies-
44
- - run:
45
- name: Bundle Install
46
- command: |
47
- bundle install --jobs=4 --retry=3 --path vendor/bundle
48
- - save_cache:
49
- paths:
50
- - ./vendor/bundle
51
- key: v1-dependencies-<< parameters.ruby_version >>-{{ checksum "Gemfile.lock" }}
52
36
  modify_active_support_version:
53
37
  description: Modify ActiveSupport Version
54
38
  parameters:
@@ -65,13 +49,13 @@ commands:
65
49
  command: |
66
50
  mkdir /tmp/test-results
67
51
  TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
68
- ./tmp/cc-test-reporter before-build
52
+ cc-test-reporter before-build
69
53
  bundle exec rspec --format documentation \
70
54
  --color \
71
55
  --format RspecJunitFormatter \
72
56
  --out /tmp/test-results/rspec.xml \
73
57
  $TEST_FILES
74
- ./tmp/cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?
58
+ cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?
75
59
  - store_test_results:
76
60
  path: /tmp/test-results
77
61
  - store_artifacts:
@@ -106,7 +90,7 @@ commands:
106
90
  - run:
107
91
  name: Create Rubygems Credentials
108
92
  command: |
109
- mkdir ~/.gem
93
+ mkdir ~/.gem || true
110
94
  echo -e "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}" > ~/.gem/credentials
111
95
  chmod 0600 ~/.gem/credentials
112
96
  - run:
@@ -116,21 +100,22 @@ commands:
116
100
  bundle exec rake release --trace
117
101
  setup:
118
102
  description: Setup for Job Working
103
+ parameters:
104
+ <<: *ruby_version
105
+ <<: *bundler_options
119
106
  steps:
120
107
  - checkout
121
- - setup_bundle
122
- build:
108
+ - ruby-orbs/bundle-install:
109
+ cache_key_prefix: v1-dependencies-<< parameters.ruby_version >>
110
+ bundle_extra_args: << parameters.bundler_options >>
111
+ test_and_build:
123
112
  description: Build the RubyGem
124
113
  parameters:
125
- <<: *ruby_version
126
114
  <<: *rails_version
127
115
  steps:
128
- - checkout
129
- - download_cc_test_reporter
130
- - setup_bundle:
131
- ruby_version: << parameters.ruby_version >>
132
116
  - modify_active_support_version:
133
117
  rails_version: << parameters.rails_version >>
118
+ - code-climate/install
134
119
  - run_rspec
135
120
  - rake_build
136
121
 
@@ -139,12 +124,15 @@ jobs:
139
124
  parameters:
140
125
  <<: *ruby_version
141
126
  <<: *rails_version
127
+ <<: *bundler_options
142
128
  executor:
143
129
  name: default
144
130
  ruby_version: << parameters.ruby_version >>
145
131
  steps:
146
- - build:
132
+ - setup:
147
133
  ruby_version: << parameters.ruby_version >>
134
+ bundler_options: << parameters.bundler_options >>
135
+ - test_and_build:
148
136
  rails_version: << parameters.rails_version >>
149
137
  rubocop:
150
138
  executor:
@@ -220,9 +208,15 @@ workflows:
220
208
  ruby_version: '2.6'
221
209
  rails_version: '5.1'
222
210
  - build:
223
- name: build_on_ruby_2_6_and_rails_5_2
211
+ name: build_on_ruby_2_6_and_rails_5_2_with_integrations
224
212
  ruby_version: '2.6'
225
213
  rails_version: '5.2'
214
+ bundler_options: '--with integrations'
215
+ - build:
216
+ name: build_on_ruby_2_6_and_rails_5_2_without_integrations
217
+ ruby_version: '2.6'
218
+ rails_version: '5.2'
219
+ bundler_options: '--without integrations'
226
220
  - rubocop
227
221
  - yardoc
228
222
  - release:
@@ -239,7 +233,8 @@ workflows:
239
233
  - build_on_ruby_2_6_and_rails_4_2
240
234
  - build_on_ruby_2_6_and_rails_5_0
241
235
  - build_on_ruby_2_6_and_rails_5_1
242
- - build_on_ruby_2_6_and_rails_5_2
236
+ - build_on_ruby_2_6_and_rails_5_2_with_integrations
237
+ - build_on_ruby_2_6_and_rails_5_2_without_integrations
243
238
  - rubocop
244
239
  filters:
245
240
  branches:
@@ -256,3 +251,10 @@ workflows:
256
251
  - master
257
252
  jobs:
258
253
  - rubocop_challenge
254
+
255
+ experimental:
256
+ notify:
257
+ branches:
258
+ only:
259
+ - master
260
+ - production
data/.rubocop.yml CHANGED
@@ -37,6 +37,7 @@ RSpec/ExampleLength:
37
37
 
38
38
  RSpec/FilePath:
39
39
  Exclude:
40
+ - 'spec/lib/my_api_client/integrations/**/*'
40
41
  - 'spec/lib/my_api_client/errors/**/*'
41
42
  - 'spec/lib/my_api_client/rspec/**/*'
42
43
 
data/Gemfile CHANGED
@@ -4,5 +4,9 @@ source 'https://rubygems.org'
4
4
 
5
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
+ group :integrations, optional: true do
8
+ gem 'bugsnag', '>= 6.11.0'
9
+ end
10
+
7
11
  # Specify your gem's dependencies in my_api_client.gemspec
8
12
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- my_api_client (0.4.0)
4
+ my_api_client (0.5.0)
5
5
  activesupport (>= 4.2.0)
6
6
  jsonpath
7
7
  sawyer
@@ -17,13 +17,15 @@ GEM
17
17
  addressable (2.6.0)
18
18
  public_suffix (>= 2.0.2, < 4.0)
19
19
  ast (2.4.0)
20
+ bugsnag (6.11.1)
21
+ concurrent-ruby (~> 1.0)
20
22
  byebug (11.0.1)
21
23
  coderay (1.1.2)
22
24
  concurrent-ruby (1.1.5)
23
25
  crack (0.4.3)
24
26
  safe_yaml (~> 1.0.0)
25
27
  diff-lcs (1.3)
26
- docile (1.3.1)
28
+ docile (1.3.2)
27
29
  faraday (0.15.4)
28
30
  multipart-post (>= 1.2, < 3)
29
31
  hashdiff (0.4.0)
@@ -31,7 +33,7 @@ GEM
31
33
  concurrent-ruby (~> 1.0)
32
34
  jaro_winkler (1.5.2)
33
35
  json (2.2.0)
34
- jsonpath (1.0.3)
36
+ jsonpath (1.0.4)
35
37
  multi_json
36
38
  to_regexp (~> 0.2.1)
37
39
  method_source (0.9.2)
@@ -43,8 +45,9 @@ GEM
43
45
  parallel (1.17.0)
44
46
  parser (2.6.3.0)
45
47
  ast (~> 2.4.0)
46
- pr_comet (0.1.1)
48
+ pr_comet (0.2.0)
47
49
  octokit
50
+ rainbow
48
51
  pry (0.12.2)
49
52
  coderay (~> 1.1.0)
50
53
  method_source (~> 0.9.0)
@@ -58,15 +61,15 @@ GEM
58
61
  rspec-core (~> 3.8.0)
59
62
  rspec-expectations (~> 3.8.0)
60
63
  rspec-mocks (~> 3.8.0)
61
- rspec-core (3.8.0)
64
+ rspec-core (3.8.1)
62
65
  rspec-support (~> 3.8.0)
63
- rspec-expectations (3.8.3)
66
+ rspec-expectations (3.8.4)
64
67
  diff-lcs (>= 1.2.0, < 2.0)
65
68
  rspec-support (~> 3.8.0)
66
- rspec-mocks (3.8.0)
69
+ rspec-mocks (3.8.1)
67
70
  diff-lcs (>= 1.2.0, < 2.0)
68
71
  rspec-support (~> 3.8.0)
69
- rspec-support (3.8.0)
72
+ rspec-support (3.8.2)
70
73
  rspec_junit_formatter (0.4.1)
71
74
  rspec-core (>= 2, < 4, != 2.12.0)
72
75
  rubocop (0.71.0)
@@ -95,16 +98,17 @@ GEM
95
98
  tzinfo (1.2.5)
96
99
  thread_safe (~> 0.1)
97
100
  unicode-display_width (1.6.0)
98
- webmock (3.5.1)
101
+ webmock (3.6.0)
99
102
  addressable (>= 2.3.6)
100
103
  crack (>= 0.3.2)
101
- hashdiff
104
+ hashdiff (>= 0.4.0, < 2.0.0)
102
105
  yard (0.9.19)
103
106
 
104
107
  PLATFORMS
105
108
  ruby
106
109
 
107
110
  DEPENDENCIES
111
+ bugsnag (>= 6.11.0)
108
112
  bundler (~> 1.16)
109
113
  my_api_client!
110
114
  pr_comet
@@ -8,4 +8,8 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
8
8
 
9
9
  gem 'activesupport', '~> 4.2.0'
10
10
 
11
+ group :integrations, optional: true do
12
+ gem 'bugsnag', '>= 6.11.0'
13
+ end
14
+
11
15
  gemspec
@@ -8,4 +8,8 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
8
8
 
9
9
  gem 'activesupport', '~> 5.0.0'
10
10
 
11
+ group :integrations, optional: true do
12
+ gem 'bugsnag', '>= 6.11.0'
13
+ end
14
+
11
15
  gemspec
@@ -8,4 +8,8 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
8
8
 
9
9
  gem 'activesupport', '~> 5.1.0'
10
10
 
11
+ group :integrations, optional: true do
12
+ gem 'bugsnag', '>= 6.11.0'
13
+ end
14
+
11
15
  gemspec
@@ -8,4 +8,8 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
8
8
 
9
9
  gem 'activesupport', '~> 5.2.0'
10
10
 
11
+ group :integrations, optional: true do
12
+ gem 'bugsnag', '>= 6.11.0'
13
+ end
14
+
11
15
  gemspec
data/lib/my_api_client.rb CHANGED
@@ -18,6 +18,14 @@ require 'my_api_client/params/request'
18
18
  require 'my_api_client/request'
19
19
  require 'my_api_client/base'
20
20
 
21
+ # Loads gems for feature of integrations
22
+ begin
23
+ require 'bugsnag'
24
+ require 'my_api_client/integrations/bugsnag' if defined?(Bugsnag) && Bugsnag::VERSION >= '6.11.0'
25
+ rescue LoadError
26
+ nil
27
+ end
28
+
21
29
  if Sawyer::VERSION < '0.8.2'
22
30
  module Sawyer
23
31
  # NOTE: Old sawyer does not have attribute reader for response body.
@@ -4,12 +4,15 @@ module MyApiClient
4
4
  # The ancestor class for all API request error
5
5
  class Error < StandardError
6
6
  attr_reader :params
7
- delegate :to_bugsnag, to: :params
7
+ delegate :metadata, to: :params
8
+ alias to_bugsnag metadata
8
9
 
9
- # Description of #initialize
10
+ # Initialize the error class
10
11
  #
11
- # @param params [MyApiClient::Params::Params] describe_params_here
12
- # @param error_message [String] default: nil
12
+ # @param params [MyApiClient::Params::Params]
13
+ # The request and response parameters
14
+ # @param error_message [String]
15
+ # The error description
13
16
  def initialize(params, error_message = nil)
14
17
  @params = params
15
18
  super error_message
@@ -35,10 +38,12 @@ module MyApiClient
35
38
  class NetworkError < Error
36
39
  attr_reader :original_error
37
40
 
38
- # Description of #initialize
41
+ # Initialize the error class
39
42
  #
40
- # @param params [MyApiClient::Params::Params] describe_params_here
41
- # @param original_error [StandardError] Some network error
43
+ # @param params [MyApiClient::Params::Params]
44
+ # The request and response parameters
45
+ # @param original_error [StandardError]
46
+ # Some network error
42
47
  def initialize(params, original_error)
43
48
  @original_error = original_error
44
49
  super params, original_error.message
@@ -50,6 +55,13 @@ module MyApiClient
50
55
  def inspect
51
56
  { error: original_error, params: params }.inspect
52
57
  end
58
+
59
+ # Generate metadata for bugsnag.
60
+ #
61
+ # @return [Hash] Metadata for bugsnag
62
+ def metadata
63
+ super.merge(original_error: original_error.inspect)
64
+ end
53
65
  end
54
66
 
55
67
  # NOTE: The built-in error classes are following. Although they are prepared
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyApiClient
4
+ # Override lib/my_api_client/errors.rb for supporting Bugsnag breadcrumbs
5
+ class Error < StandardError
6
+ alias _original_initialize initialize
7
+
8
+ # Override MyApiClient::Error#initialize
9
+ def initialize(params, error_message = nil)
10
+ _original_initialize(params, error_message)
11
+
12
+ Bugsnag.leave_breadcrumb(
13
+ "#{self.class.name} occurred",
14
+ metadata,
15
+ Bugsnag::Breadcrumbs::ERROR_BREADCRUMB_TYPE
16
+ )
17
+ end
18
+ end
19
+ end
@@ -20,9 +20,10 @@ module MyApiClient
20
20
  # Blank parameter will be omitted.
21
21
  #
22
22
  # @return [Hash] Metadata for bugsnag
23
- def to_bugsnag
23
+ def metadata
24
24
  request_metadata.merge(response_metadata)
25
25
  end
26
+ alias to_bugsnag metadata
26
27
 
27
28
  # Returns contents as string for to be readable for human
28
29
  #
@@ -39,7 +40,7 @@ module MyApiClient
39
40
  # @return [Hash] Metadata for bugsnag
40
41
  def request_metadata
41
42
  if request.present?
42
- request.to_bugsnag.each_with_object({}) do |(key, value), memo|
43
+ request.metadata.each_with_object({}) do |(key, value), memo|
43
44
  memo[:"request_#{key}"] = value
44
45
  end
45
46
  else
@@ -32,7 +32,7 @@ module MyApiClient
32
32
  # Blank parameter will be omitted.
33
33
  #
34
34
  # @return [Hash] Metadata for bugsnag
35
- def to_bugsnag
35
+ def metadata
36
36
  {
37
37
  line: "#{method.upcase} #{pathname}",
38
38
  headers: headers,
@@ -40,6 +40,7 @@ module MyApiClient
40
40
  body: body,
41
41
  }.compact
42
42
  end
43
+ alias to_bugsnag metadata
43
44
 
44
45
  # Returns contents as string for to be readable for human
45
46
  #
@@ -46,7 +46,7 @@ module MyApiClient
46
46
  def process_raise_option(exception)
47
47
  case exception
48
48
  when Class
49
- params = instance_double(MyApiClient::Params::Params, to_bugsnag: {})
49
+ params = instance_double(MyApiClient::Params::Params, metadata: {})
50
50
  if exception == MyApiClient::NetworkError
51
51
  exception.new(params, Net::OpenTimeout.new)
52
52
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MyApiClient
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryz310
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-03 00:00:00.000000000 Z
11
+ date: 2019-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -260,6 +260,7 @@ files:
260
260
  - lib/my_api_client/error_handling.rb
261
261
  - lib/my_api_client/errors.rb
262
262
  - lib/my_api_client/exceptions.rb
263
+ - lib/my_api_client/integrations/bugsnag.rb
263
264
  - lib/my_api_client/logger.rb
264
265
  - lib/my_api_client/params/params.rb
265
266
  - lib/my_api_client/params/request.rb