Skip to content

Commit ae35060

Browse files
committed
lint fixed
1 parent 20da819 commit ae35060

File tree

8 files changed

+78
-78
lines changed

8 files changed

+78
-78
lines changed

lib/zendesk_api/client.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def build_connection
183183
set_authentication(builder, config)
184184

185185
if config.cache
186-
builder.use ZendeskAPI::Middleware::Request::EtagCache, { :cache => config.cache, :instrumentation => config.instrumentation }
186+
builder.use ZendeskAPI::Middleware::Request::EtagCache, {cache: config.cache, instrumentation: config.instrumentation}
187187
end
188188

189189
builder.use ZendeskAPI::Middleware::Request::Upload
@@ -193,10 +193,10 @@ def build_connection
193193
# Should always be first in the stack
194194
if config.retry
195195
builder.use ZendeskAPI::Middleware::Request::Retry,
196-
:logger => config.logger,
197-
:retry_codes => config.retry_codes,
198-
:retry_on_exception => config.retry_on_exception,
199-
:instrumentation => config.instrumentation
196+
logger: config.logger,
197+
retry_codes: config.retry_codes,
198+
retry_on_exception: config.retry_on_exception,
199+
instrumentation: config.instrumentation
200200
end
201201
if config.raise_error_when_rate_limited
202202
builder.use ZendeskAPI::Middleware::Request::RaiseRateLimited, logger: config.logger

lib/zendesk_api/middleware/request/etag_cache.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "faraday/middleware"
2-
require 'active_support/notifications'
2+
require "active_support/notifications"
33

44
module ZendeskAPI
55
module Middleware
@@ -44,17 +44,17 @@ def call(environment)
4444
content_encoding: cached[:response_headers][:content_encoding]
4545
)
4646
@instrumentation&.instrument("zendesk.cache_hit",
47-
{
48-
endpoint: env[:url].path,
49-
status: env[:status]
50-
})
47+
{
48+
endpoint: env[:url].path,
49+
status: env[:status]
50+
})
5151
elsif env[:status] == 200 && env[:response_headers]["Etag"] # modified and cacheable
5252
@cache.write(cache_key(env), env.to_hash)
5353
@instrumentation&.instrument("zendesk.cache_miss",
54-
{
55-
endpoint: env[:url].path,
56-
status: env[:status]
57-
})
54+
{
55+
endpoint: env[:url].path,
56+
status: env[:status]
57+
})
5858
end
5959
end
6060
end

lib/zendesk_api/middleware/request/retry.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class Retry < Faraday::Middleware
1313
def initialize(app, options = {})
1414
super(app)
1515
@logger = options[:logger]
16-
@error_codes = options.key?(:retry_codes) && options[:retry_codes] ? options[:retry_codes] : DEFAULT_ERROR_CODES
17-
@retry_on_exception = options.key?(:retry_on_exception) && options[:retry_on_exception] ? options[:retry_on_exception] : false
16+
@error_codes = (options.key?(:retry_codes) && options[:retry_codes]) ? options[:retry_codes] : DEFAULT_ERROR_CODES
17+
@retry_on_exception = (options.key?(:retry_on_exception) && options[:retry_on_exception]) ? options[:retry_on_exception] : false
1818
@instrumentation = options[:instrumentation]
1919
end
2020

@@ -29,7 +29,7 @@ def call(env)
2929
if @retry_on_exception
3030
begin
3131
response = @app.call(env)
32-
rescue StandardError => ex
32+
rescue => ex
3333
exception_happened = true
3434
exception = ex
3535
end
@@ -42,7 +42,7 @@ def call(env)
4242
original_env[:call_attempt] += 1
4343
seconds_left = DEFAULT_RETRY_AFTER.to_i
4444
@logger.warn "An exception happened, waiting #{seconds_left} seconds... #{exception}" if @logger
45-
instrument_retry(original_env, 'exception', seconds_left)
45+
instrument_retry(original_env, "exception", seconds_left)
4646
sleep_with_logging(seconds_left)
4747
return @app.call(original_env)
4848
end
@@ -52,7 +52,7 @@ def call(env)
5252
original_env[:call_attempt] += 1
5353
seconds_left = (response.env[:response_headers][:retry_after] || DEFAULT_RETRY_AFTER).to_i
5454
@logger.warn "You may have been rate limited. Retrying in #{seconds_left} seconds..." if @logger
55-
instrument_retry(original_env, response.env[:status] == 429 ? 'rate_limited' : 'server_error', seconds_left)
55+
instrument_retry(original_env, (response.env[:status] == 429) ? "rate_limited" : "server_error", seconds_left)
5656
sleep_with_logging(seconds_left)
5757
response = @app.call(original_env)
5858
end

lib/zendesk_api/middleware/response/zendesk_request_event.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ def call(env)
1818
instrumentation = @client.config.instrumentation
1919
if instrumentation
2020
instrumentation.instrument("zendesk.request",
21-
{ duration: duration,
22-
endpoint: response_env[:url].path,
23-
method: response_env[:method],
24-
status: response_env[:status] })
21+
{duration: duration,
22+
endpoint: response_env[:url].path,
23+
method: response_env[:method],
24+
status: response_env[:status]})
2525
if response_env[:status] < 500
2626
instrumentation.instrument("zendesk.rate_limit",
27-
{
28-
endpoint: response_env[:url].path,
29-
status: response_env[:status],
30-
threshold: response_env[:response_headers] ? response_env[:response_headers]['X-Rate-Limit-Remaining'] : nil,
31-
limit: response_env[:response_headers] ? response_env[:response_headers]['X-Rate-Limit'] : nil,
32-
reset: response_env[:response_headers] ? response_env[:response_headers]['X-Rate-Limit-Reset'] : nil
33-
})
27+
{
28+
endpoint: response_env[:url].path,
29+
status: response_env[:status],
30+
threshold: response_env[:response_headers] ? response_env[:response_headers]["X-Rate-Limit-Remaining"] : nil,
31+
limit: response_env[:response_headers] ? response_env[:response_headers]["X-Rate-Limit"] : nil,
32+
reset: response_env[:response_headers] ? response_env[:response_headers]["X-Rate-Limit-Reset"] : nil
33+
})
3434
end
3535
end
3636
end

spec/core/middleware/request/etag_cache_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
require 'core/spec_helper'
2-
require 'active_support/cache'
1+
require "core/spec_helper"
2+
require "active_support/cache"
33

44
describe ZendeskAPI::Middleware::Request::EtagCache do
55
it "caches" do
@@ -36,10 +36,10 @@
3636
url: URI("https://example.zendesk.com/api/v2/blergh"),
3737
method: :get,
3838
request_headers: {},
39-
response_headers: { "Etag" => "x", x_rate_limit_remaining: 10 },
39+
response_headers: {"Etag" => "x", :x_rate_limit_remaining => 10},
4040
status: status,
41-
body: { "x" => 1 },
42-
response_body: { "x" => 1 }
41+
body: {"x" => 1},
42+
response_body: {"x" => 1}
4343
}
4444
end
4545
let(:no_instrumentation_middleware) do

spec/core/middleware/request/retry_spec.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,59 +128,59 @@ def runtime
128128
client.config.instrumentation = instrumentation
129129
# Inject instrumentation into middleware instance
130130
allow_any_instance_of(ZendeskAPI::Middleware::Request::Retry).to receive(:instrumentation).and_return(instrumentation)
131-
stub_request(:get, %r{instrumented}).to_return(:status => 429, :headers => { :retry_after => 1 }).to_return(:status => 200)
131+
stub_request(:get, %r{instrumented}).to_return(status: 429, headers: {retry_after: 1}).to_return(status: 200)
132132
end
133133

134134
it "calls instrumentation on retry" do
135135
expect(instrumentation).to receive(:instrument).with(
136136
"zendesk.retry",
137-
hash_including(:attempt => 1, :endpoint => anything, :method => anything, :reason => anything, :delay => anything)
137+
hash_including(attempt: 1, endpoint: anything, method: anything, reason: anything, delay: anything)
138138
).at_least(:once)
139139
client.connection.get("instrumented")
140140
end
141141

142142
it "calls instrumentation on second retry attempt" do
143143
# Override stub for this test to force two rate limit responses before success
144-
stub_request(:get, %r{instrumented_twice}).
145-
to_return(:status => 429, :headers => { :retry_after => 0 }).
146-
to_return(:status => 429, :headers => { :retry_after => 0 }).
147-
to_return(:status => 200)
144+
stub_request(:get, %r{instrumented_twice})
145+
.to_return(status: 429, headers: {retry_after: 0})
146+
.to_return(status: 429, headers: {retry_after: 0})
147+
.to_return(status: 200)
148148

149149
# Expect instrumentation for attempt 1 and attempt 2
150150
expect(instrumentation).to receive(:instrument).with(
151151
"zendesk.retry",
152-
hash_including(:attempt => 1, :endpoint => anything, :method => anything, :reason => 'rate_limited', :delay => anything)
152+
hash_including(attempt: 1, endpoint: anything, method: anything, reason: "rate_limited", delay: anything)
153153
).at_least(:once)
154154
expect(instrumentation).to receive(:instrument).with(
155155
"zendesk.retry",
156-
hash_including(:attempt => 2, :endpoint => anything, :method => anything, :reason => 'rate_limited', :delay => anything)
156+
hash_including(attempt: 2, endpoint: anything, method: anything, reason: "rate_limited", delay: anything)
157157
).at_least(:once)
158158

159159
client.connection.get("instrumented_twice")
160160
end
161161

162162
it "calls instrumentation with first attempt server error, and rate limited on second retry attempt" do
163163
# Override stub for this test to force two rate limit responses before success
164-
stub_request(:get, %r{instrumented_twice}).
165-
to_return(:status => 503, :headers => { :retry_after => 0 }).
166-
to_return(:status => 429, :headers => { :retry_after => 0 }).
167-
to_return(:status => 200)
164+
stub_request(:get, %r{instrumented_twice})
165+
.to_return(status: 503, headers: {retry_after: 0})
166+
.to_return(status: 429, headers: {retry_after: 0})
167+
.to_return(status: 200)
168168

169169
# Expect instrumentation for attempt 1 and attempt 2
170170
expect(instrumentation).to receive(:instrument).with(
171171
"zendesk.retry",
172-
hash_including(:attempt => 1, :endpoint => anything, :method => anything, :reason => 'server_error', :delay => anything)
172+
hash_including(attempt: 1, endpoint: anything, method: anything, reason: "server_error", delay: anything)
173173
).at_least(:once)
174174
expect(instrumentation).to receive(:instrument).with(
175175
"zendesk.retry",
176-
hash_including(:attempt => 2, :endpoint => anything, :method => anything, :reason => 'rate_limited', :delay => anything)
176+
hash_including(attempt: 2, endpoint: anything, method: anything, reason: "rate_limited", delay: anything)
177177
).at_least(:once)
178178

179179
client.connection.get("instrumented_twice")
180180
end
181181

182182
it "does not call instrumentation when no retry occurs" do
183-
stub_request(:get, %r{no_retry}).to_return(:status => 200)
183+
stub_request(:get, %r{no_retry}).to_return(status: 200)
184184
expect(instrumentation).not_to receive(:instrument).with(
185185
"zendesk.retry",
186186
hash_including(:attempt, :endpoint, :method, :reason, :delay)

spec/core/middleware/response/zendesk_request_event_spec.rb

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
require_relative '../../../spec_helper'
2-
require 'faraday'
3-
require 'zendesk_api/middleware/response/zendesk_request_event'
1+
require_relative "../../../spec_helper"
2+
require "faraday"
3+
require "zendesk_api/middleware/response/zendesk_request_event"
44

55
RSpec.describe ZendeskAPI::Middleware::Response::ZendeskRequestEvent do
6-
let(:instrumentation) { double('Instrumentation') }
6+
let(:instrumentation) { double("Instrumentation") }
77
let(:client) do
8-
double('Client', config: double('Config', instrumentation: instrumentation))
8+
double("Client", config: double("Config", instrumentation: instrumentation))
99
end
1010
let(:app) { ->(env) { Faraday::Response.new(env) } }
1111
let(:middleware) { described_class.new(app, client) }
1212
let(:response_headers) do
1313
{
14-
'X-Rate-Limit-Remaining': 10,
15-
'X-Rate-Limit': 100,
16-
'X-Rate-Limit-Reset': 1234567890
14+
"X-Rate-Limit-Remaining": 10,
15+
"X-Rate-Limit": 100,
16+
"X-Rate-Limit-Reset": 1234567890
1717
}
1818
end
1919
let(:env) do
2020
{
21-
url: URI('https://example.zendesk.com/api/v2/tickets'),
21+
url: URI("https://example.zendesk.com/api/v2/tickets"),
2222
method: :get,
2323
status: status,
2424
response_headers: response_headers
@@ -29,57 +29,57 @@
2929
allow(instrumentation).to receive(:instrument)
3030
end
3131

32-
context 'when the response status is less than 500' do
32+
context "when the response status is less than 500" do
3333
let(:status) { 200 }
3434

35-
it 'instruments zendesk.request and zendesk.rate_limit' do
35+
it "instruments zendesk.request and zendesk.rate_limit" do
3636
expect(instrumentation).to receive(:instrument).with(
37-
'zendesk.request',
38-
hash_including(:duration, endpoint: '/api/v2/tickets', method: :get, status: 200)
37+
"zendesk.request",
38+
hash_including(:duration, endpoint: "/api/v2/tickets", method: :get, status: 200)
3939
)
4040
expect(instrumentation).to receive(:instrument).with(
41-
'zendesk.rate_limit',
42-
hash_including(endpoint: '/api/v2/tickets', status: 200)
41+
"zendesk.rate_limit",
42+
hash_including(endpoint: "/api/v2/tickets", status: 200)
4343
)
4444
middleware.call(env).on_complete { |_response_env| 1 }
4545
end
4646
end
4747

48-
context 'when the response status is 500 or greater' do
48+
context "when the response status is 500 or greater" do
4949
let(:status) { 500 }
5050

51-
it 'instruments only zendesk.request' do
51+
it "instruments only zendesk.request" do
5252
expect(instrumentation).to receive(:instrument).with(
53-
'zendesk.request',
54-
hash_including(:duration, endpoint: '/api/v2/tickets', method: :get, status: 500)
53+
"zendesk.request",
54+
hash_including(:duration, endpoint: "/api/v2/tickets", method: :get, status: 500)
5555
)
56-
expect(instrumentation).not_to receive(:instrument).with('zendesk.rate_limit', anything)
56+
expect(instrumentation).not_to receive(:instrument).with("zendesk.rate_limit", anything)
5757
middleware.call(env).on_complete { |_response_env| 1 }
5858
end
5959
end
6060

61-
context 'duration calculation' do
61+
context "duration calculation" do
6262
let(:status) { 201 }
6363

64-
it 'passes a positive duration to instrumentation' do
64+
it "passes a positive duration to instrumentation" do
6565
expect(instrumentation).to receive(:instrument) do |event, payload|
66-
if event == 'zendesk.request'
66+
if event == "zendesk.request"
6767
expect(payload[:duration]).to be > 0
6868
end
6969
end
70-
expect(instrumentation).to receive(:instrument).with('zendesk.rate_limit', anything)
70+
expect(instrumentation).to receive(:instrument).with("zendesk.rate_limit", anything)
7171
middleware.call(env).on_complete { |_response_env| 1 }
7272
end
7373
end
7474

75-
context 'when instrumentation is nil' do
75+
context "when instrumentation is nil" do
7676
let(:status) { 200 }
7777
let(:client) do
78-
double('Client', config: double('Config', instrumentation: nil))
78+
double("Client", config: double("Config", instrumentation: nil))
7979
end
8080
let(:middleware) { described_class.new(app, client) }
8181

82-
it 'does not raise an error' do
82+
it "does not raise an error" do
8383
expect { middleware.call(env).on_complete { |_response_env| 1 } }.not_to raise_error
8484
end
8585
end

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'rspec'
1+
require "rspec"
22

33
RSpec.configure do |config|
44
config.expect_with :rspec do |c|

0 commit comments

Comments
 (0)