Skip to content

Commit

Permalink
fix(rubocop): ENV.fetch('xy') instead of ENV['xy'] per rubocop (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdeme authored May 30, 2022
1 parent c7c5843 commit 6b25736
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

## 📝 About Stream

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

You can use this library to access Feeds API endpoints server-side.
Expand Down
4 changes: 2 additions & 2 deletions lib/stream/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class Client
#
def initialize(api_key = '', api_secret = '', app_id = nil, opts = {})
if api_key.nil? || api_key.empty?
env_url = ENV['STREAM_URL']
env_url = ENV.fetch('STREAM_URL', nil)
if env_url =~ Stream::STREAM_URL_COM_RE
re = Stream::STREAM_URL_COM_RE
elsif env_url =~ Stream::STREAM_URL_IO_RE
re = Stream::STREAM_URL_IO_RE
end
raise ArgumentError, 'empty api_key parameter and missing or invalid STREAM_URL env variable' unless re

matches = re.match(ENV['STREAM_URL'])
matches = re.match(ENV.fetch('STREAM_URL', nil))
api_key = matches['key']
api_secret = matches['secret']
app_id = matches['app_id']
Expand Down
6 changes: 3 additions & 3 deletions lib/stream/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def initialize(options)
location = make_location(options[:location])
location ||= 'api'
api_version = options[:api_version] || 'v1.0'
if ENV['STREAM_URL']
uri = URI.parse(ENV['STREAM_URL'])
if ENV.fetch('STREAM_URL', nil)
uri = URI.parse(ENV.fetch('STREAM_URL'))
scheme = uri.scheme
host = uri.host
port = uri.port
Expand All @@ -22,7 +22,7 @@ def initialize(options)
host = options[:api_hostname]
port = 443
end
unless ENV['STREAM_URL'] =~ /localhost/
unless ENV.fetch('STREAM_URL', nil) =~ /localhost/
host_parts = host.split('.')
host = host_parts.slice(1..-1).join('.') if host_parts.length == 3
host = "#{location}.#{host}" if location
Expand Down
2 changes: 1 addition & 1 deletion spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

describe Stream::Client do
before do
@env_url = ENV['STREAM_URL']
@env_url = ENV.fetch('STREAM_URL', nil)
end

after do
Expand Down
2 changes: 1 addition & 1 deletion spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

Expand Down

0 comments on commit 6b25736

Please sign in to comment.