From cf2c8908cbc6a88be4d4c72b763cb4ef57d698f4 Mon Sep 17 00:00:00 2001 From: Mwaki Magotswi Date: Wed, 31 May 2017 10:55:40 -0400 Subject: [PATCH 1/6] Updating homepage to point to the correct repository --- omniauth-dotloop.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omniauth-dotloop.gemspec b/omniauth-dotloop.gemspec index 5892f79..d6e431d 100644 --- a/omniauth-dotloop.gemspec +++ b/omniauth-dotloop.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |gem| gem.email = 'api@contactually.com' gem.description = 'OmniAuth OAuth2 strategy for Contactually.' gem.summary = gem.description - gem.homepage = 'https://github.com/dotloop/omniauth-dotloop' + gem.homepage = 'https://github.com/contactually/omniauth-dotloop' gem.licenses = %w(MIT) gem.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) } From 4a096667423724dc51f48812653de4c0c177f0a2 Mon Sep 17 00:00:00 2001 From: Mwaki Magotswi Date: Wed, 31 May 2017 11:20:31 -0400 Subject: [PATCH 2/6] One more gem documentation update --- omniauth-dotloop.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omniauth-dotloop.gemspec b/omniauth-dotloop.gemspec index d6e431d..23c7e2d 100644 --- a/omniauth-dotloop.gemspec +++ b/omniauth-dotloop.gemspec @@ -3,7 +3,7 @@ require File.expand_path('../lib/omniauth-dotloop/version', __FILE__) Gem::Specification.new do |gem| gem.authors = 'Contactually' gem.email = 'api@contactually.com' - gem.description = 'OmniAuth OAuth2 strategy for Contactually.' + gem.description = 'OmniAuth OAuth2 strategy for Dotloop.' gem.summary = gem.description gem.homepage = 'https://github.com/contactually/omniauth-dotloop' gem.licenses = %w(MIT) From d6b7cd000b1c8fec3d932ea0df439b26ce32d1cf Mon Sep 17 00:00:00 2001 From: Mwaki Magotswi Date: Wed, 31 May 2017 16:41:05 -0400 Subject: [PATCH 3/6] Implementing the omnioauth strategy for Dotloop --- lib/omniauth/strategies/dotloop.rb | 40 +++++++++++++++++++++++++++--- omniauth-dotloop.gemspec | 4 +-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/lib/omniauth/strategies/dotloop.rb b/lib/omniauth/strategies/dotloop.rb index 674c8fb..3c42553 100644 --- a/lib/omniauth/strategies/dotloop.rb +++ b/lib/omniauth/strategies/dotloop.rb @@ -19,12 +19,46 @@ class Dotloop < OmniAuth::Strategies::OAuth2 # additional calls (if the user id is returned with the token # or as a URI parameter). This may not be possible with all # providers. - uid {} + uid { raw_info['data']['id'] } # https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema#schema-10-and-later - info {} + info do + prune!( + :email => raw_info['data']['email'], + :first_name => raw_info['data']['first_name'], + :last_name => raw_info['data']['last_name'] + ) + end - extra {} + extra do + hash = {} + hash['raw_info'] = raw_info + prune! hash + end + + def raw_info + @raw_info ||= access_token.get('https://api-gateway.dotloop.com/public/v2/account').parsed || {} + end + + protected + + def build_access_token + options.token_params[:headers] = { 'Authorization' => basic_auth_header } + super + end + + def basic_auth_header + "Basic #{Base64.urlsafe_encode64("#{options[:client_id]}:#{options[:client_secret]}")}" + end + + private + + def prune!(hash) + hash.delete_if do |_, value| + prune!(value) if value.is_a?(Hash) + value.nil? || (value.respond_to?(:empty?) && value.empty?) + end + end end end end diff --git a/omniauth-dotloop.gemspec b/omniauth-dotloop.gemspec index 23c7e2d..ef05625 100644 --- a/omniauth-dotloop.gemspec +++ b/omniauth-dotloop.gemspec @@ -1,8 +1,8 @@ require File.expand_path('../lib/omniauth-dotloop/version', __FILE__) Gem::Specification.new do |gem| - gem.authors = 'Contactually' - gem.email = 'api@contactually.com' + gem.authors = ['Contactually', 'Mwaki Harri Magotswi'] + gem.email = ['api@contactually.com', 'magotswi@gmail.com'] gem.description = 'OmniAuth OAuth2 strategy for Dotloop.' gem.summary = gem.description gem.homepage = 'https://github.com/contactually/omniauth-dotloop' From 2b70c4104515660d5bc1ccc2ca49306f06a12d77 Mon Sep 17 00:00:00 2001 From: Mwaki Magotswi Date: Wed, 31 May 2017 16:56:37 -0400 Subject: [PATCH 4/6] A number of updates to rubocop.yml file to remove errors/warnings --- .rubocop.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 83af90c..0b2e342 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,4 @@ -Style/AlignParameters: +Layout/AlignParameters: # Alignment of parameters in multi-line method calls. # # The `with_first_parameter` style aligns the following lines along the same @@ -32,8 +32,8 @@ Style/BracesAroundHashParameters: - context_dependent # Indentation of `when`. -Style/CaseIndentation: - IndentWhenRelativeTo: end +Layout/CaseIndentation: + EnforcedStyle: end SupportedStyles: - case - end @@ -81,7 +81,7 @@ Style/HashSyntax: - hash_rockets # Checks the indentation of the first element in an array literal. -Style/IndentArray: +Layout/IndentArray: # The value `special_inside_parentheses` means that array literals with # brackets that have their opening bracket on the same line as a surrounding # opening round parenthesis, shall have their first element indented relative @@ -103,7 +103,7 @@ Style/IndentArray: IndentationWidth: ~ # Checks the indentation of the first key in a hash literal. -Style/IndentHash: +Layout/IndentHash: # The value `special_inside_parentheses` means that hash literals with braces # that have their opening brace on the same line as a surrounding opening # round parenthesis, shall have their first key indented relative to the @@ -116,7 +116,7 @@ Style/IndentHash: - special_inside_parentheses - consistent -Style/MultilineMethodCallIndentation: +Layout/MultilineMethodCallIndentation: EnforcedStyle: indented SupportedStyles: - aligned @@ -125,7 +125,7 @@ Style/MultilineMethodCallIndentation: # But it can be overridden by setting this parameter IndentationWidth: ~ -Style/MultilineOperationIndentation: +Layout/MultilineOperationIndentation: EnforcedStyle: indented SupportedStyles: - aligned From 2932703e66aa0bbcb87ecbdfc384c3e143c97d57 Mon Sep 17 00:00:00 2001 From: Mwaki Magotswi Date: Wed, 31 May 2017 17:25:40 -0400 Subject: [PATCH 5/6] Getting rubocop to a happy place --- .rubocop.yml | 10 ++++++++++ Rakefile | 2 +- omniauth-dotloop.gemspec | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 0b2e342..67c9977 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -157,12 +157,22 @@ Metrics/MethodLength: Metrics/LineLength: Max: 120 +Metrics/BlockLength: + CountComments: false + Exclude: + - 'Rakefile' + - '**/*.rake' + - 'spec/**/*.rb' + ##################### Lint ################################ Lint/AssignmentInCondition: Description: "Don't use assignment in conditions." Enabled: false +Lint/ScriptPermission: + Enabled: false + ##################### Performance ######################### # Performance improvement is negligible and the readability is poor. See: diff --git a/Rakefile b/Rakefile index 8811322..503a524 100644 --- a/Rakefile +++ b/Rakefile @@ -15,4 +15,4 @@ rescue LoadError end end -task :default => [:spec, :rubocop] +task :default => %i[spec rubocop] diff --git a/omniauth-dotloop.gemspec b/omniauth-dotloop.gemspec index ef05625..ec84eb8 100644 --- a/omniauth-dotloop.gemspec +++ b/omniauth-dotloop.gemspec @@ -6,13 +6,13 @@ Gem::Specification.new do |gem| gem.description = 'OmniAuth OAuth2 strategy for Dotloop.' gem.summary = gem.description gem.homepage = 'https://github.com/contactually/omniauth-dotloop' - gem.licenses = %w(MIT) + gem.licenses = %w[MIT] gem.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) } gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") gem.name = 'omniauth-dotloop' - gem.require_paths = %w(lib) + gem.require_paths = %w[lib] gem.version = OmniAuth::Dotloop::VERSION # Lock at 1.3.x due to https://github.com/intridea/omniauth-oauth2/issues/81 From 595ae6e1b85758f8dba7478e5b842476a56af068 Mon Sep 17 00:00:00 2001 From: Mwaki Magotswi Date: Wed, 31 May 2017 17:50:55 -0400 Subject: [PATCH 6/6] Final tweaks to rubocop.yml and adding ruby-(version|gemset) to the gitignore file --- .gitignore | 4 ++++ .rubocop.yml | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8b06bc2..81240ee 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,7 @@ test/version_tmp tmp *.swp example/app.log + +.ruby-gemset + +.ruby-version diff --git a/.rubocop.yml b/.rubocop.yml index 67c9977..49f3b90 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,10 @@ +AllCops: + Exclude: + - 'vendor/**/*' + - 'spec/fixtures/**/*' + - 'tmp/**/*' + TargetRubyVersion: 2.2 + Layout/AlignParameters: # Alignment of parameters in multi-line method calls. # @@ -77,7 +84,6 @@ Style/CommandLiteral: Style/HashSyntax: EnforcedStyle: hash_rockets SupportedStyles: - - ruby19 - hash_rockets # Checks the indentation of the first element in an array literal.