Skip to content

Commit 6b25736

Browse files
authored
fix(rubocop): ENV.fetch('xy') instead of ENV['xy'] per rubocop (#140)
1 parent c7c5843 commit 6b25736

5 files changed

Lines changed: 9 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
## 📝 About Stream
2222

23+
> 💡 This is a library for the **Feeds** product. The Chat SDKs can be found [here](https://getstream.io/chat/docs/).
24+
2325
You can sign up for a Stream account at our [Get Started](https://getstream.io/get_started/) page.
2426

2527
You can use this library to access Feeds API endpoints server-side.

lib/stream/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ class Client
3838
#
3939
def initialize(api_key = '', api_secret = '', app_id = nil, opts = {})
4040
if api_key.nil? || api_key.empty?
41-
env_url = ENV['STREAM_URL']
41+
env_url = ENV.fetch('STREAM_URL', nil)
4242
if env_url =~ Stream::STREAM_URL_COM_RE
4343
re = Stream::STREAM_URL_COM_RE
4444
elsif env_url =~ Stream::STREAM_URL_IO_RE
4545
re = Stream::STREAM_URL_IO_RE
4646
end
4747
raise ArgumentError, 'empty api_key parameter and missing or invalid STREAM_URL env variable' unless re
4848

49-
matches = re.match(ENV['STREAM_URL'])
49+
matches = re.match(ENV.fetch('STREAM_URL', nil))
5050
api_key = matches['key']
5151
api_secret = matches['secret']
5252
app_id = matches['app_id']

lib/stream/url.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def initialize(options)
1212
location = make_location(options[:location])
1313
location ||= 'api'
1414
api_version = options[:api_version] || 'v1.0'
15-
if ENV['STREAM_URL']
16-
uri = URI.parse(ENV['STREAM_URL'])
15+
if ENV.fetch('STREAM_URL', nil)
16+
uri = URI.parse(ENV.fetch('STREAM_URL'))
1717
scheme = uri.scheme
1818
host = uri.host
1919
port = uri.port
@@ -22,7 +22,7 @@ def initialize(options)
2222
host = options[:api_hostname]
2323
port = 443
2424
end
25-
unless ENV['STREAM_URL'] =~ /localhost/
25+
unless ENV.fetch('STREAM_URL', nil) =~ /localhost/
2626
host_parts = host.split('.')
2727
host = host_parts.slice(1..-1).join('.') if host_parts.length == 3
2828
host = "#{location}.#{host}" if location

spec/client_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
describe Stream::Client do
55
before do
6-
@env_url = ENV['STREAM_URL']
6+
@env_url = ENV.fetch('STREAM_URL', nil)
77
end
88

99
after do

spec/integration_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
describe 'Integration tests' do
1010
before(:all) do
11-
@client = Stream::Client.new(ENV['STREAM_API_KEY'], ENV['STREAM_API_SECRET'], nil, location: ENV['STREAM_REGION'], default_timeout: 10)
11+
@client = Stream::Client.new(ENV.fetch('STREAM_API_KEY'), ENV.fetch('STREAM_API_SECRET'), nil, location: ENV.fetch('STREAM_REGION', nil), default_timeout: 10)
1212
@feed42 = @client.feed('flat', generate_uniq_feed_name)
1313
@feed43 = @client.feed('flat', generate_uniq_feed_name)
1414

0 commit comments

Comments
 (0)