Skip to content

Commit

Permalink
Apply RuboCop auto-corrections for code style improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-ai-integration[bot] committed Nov 11, 2024
1 parent 2ef82c8 commit aefa98f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
56 changes: 28 additions & 28 deletions lib/omniauth/strategies/mlh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MLH < OmniAuth::Strategies::OAuth2 # :nodoc:
site: 'https://my.mlh.io',
authorize_url: 'oauth/authorize',
token_url: 'oauth/token',
auth_scheme: :request_body # Change from basic auth to request body
auth_scheme: :request_body # Change from basic auth to request body
}

# Support expandable fields through options
Expand All @@ -43,32 +43,32 @@ class MLH < OmniAuth::Strategies::OAuth2 # :nodoc:

info do
prune_hash({
# Basic fields
id: data[:id],
created_at: data[:created_at],
updated_at: data[:updated_at],
first_name: data[:first_name],
last_name: data[:last_name],
email: data[:email],
phone_number: data[:phone_number],
roles: data[:roles],
# Basic fields
id: data[:id],
created_at: data[:created_at],
updated_at: data[:updated_at],
first_name: data[:first_name],
last_name: data[:last_name],
email: data[:email],
phone_number: data[:phone_number],
roles: data[:roles],

# Expandable fields
profile: data[:profile],
address: data[:address],
social_profiles: data[:social_profiles],
professional_experience: data[:professional_experience],
education: data[:education],
identifiers: data[:identifiers]
})
# Expandable fields
profile: data[:profile],
address: data[:address],
social_profiles: data[:social_profiles],
professional_experience: data[:professional_experience],
education: data[:education],
identifiers: data[:identifiers]
})
end

def data
@data ||= begin
# Support expandable fields through options
expand_fields = options[:expand_fields] || []
expand_query = expand_fields.map { |f| "expand[]=#{f}" }.join('&')
url = "https://api.mlh.com/v4/users/me"
url = 'https://api.mlh.com/v4/users/me'
url += "?#{expand_query}" unless expand_fields.empty?

response = access_token.get(url).parsed
Expand All @@ -89,15 +89,15 @@ def prune_hash(hash)
end

def symbolize_nested_arrays(hash)
hash.each_with_object({}) do |(key, value), result|
result[key] = case value
when Hash
symbolize_nested_arrays(value)
when Array
value.map { |item| item.is_a?(Hash) ? symbolize_nested_arrays(item) : item }
else
value
end
hash.transform_values do |value|
case value
when Hash
symbolize_nested_arrays(value)
when Array
value.map { |item| item.is_a?(Hash) ? symbolize_nested_arrays(item) : item }
else
value
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/omniauth_mlh_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe OmniAuth::MLH do
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'bundler/setup'
require 'webmock/rspec'
Expand All @@ -18,7 +20,7 @@
require 'omniauth_mlh'
require 'omniauth/strategies/mlh'

Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f }
Dir[File.expand_path('support/**/*.rb', __dir__)].sort.each { |f| require f }

RSpec.configure do |config|
config.expect_with :rspec do |c|
Expand Down
22 changes: 12 additions & 10 deletions spec/support/shared_examples.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

RSpec.shared_examples 'basic data retrieval tests' do
context 'with successful API response' do
before do
Expand All @@ -18,16 +20,16 @@
RSpec.shared_examples 'expandable fields tests' do
let(:expanded_user_data) do
base_user_data.merge({
'profile' => {
'age' => 22,
'gender' => 'Female'
},
'education' => [{
'current' => true,
'school_name' => 'Hacker University',
'major' => 'Computer Science'
}]
})
'profile' => {
'age' => 22,
'gender' => 'Female'
},
'education' => [{
'current' => true,
'school_name' => 'Hacker University',
'major' => 'Computer Science'
}]
})
end

context 'with expandable fields' do
Expand Down

0 comments on commit aefa98f

Please sign in to comment.