Skip to content

Commit

Permalink
Merge pull request #305 from XeroAPI/PETOSS-565-Update-the-.rubocop.y…
Browse files Browse the repository at this point in the history
…ml-file-in-xero-ruby-with-latest-documentation-to-run-the-lint-in-CI-CD-pipeline

PETOSS-565 - Fix Linting Issues in Ruby SDK
  • Loading branch information
vigneshk-tw authored Sep 5, 2024
2 parents c2d0522 + 8313032 commit d865b1b
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 120 deletions.
20 changes: 7 additions & 13 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ AllCops:
Style/AndOr:
Enabled: true

# Do not use braces for hash literals when they are the last argument of a
# method call.
Style/BracesAroundHashParameters:
Enabled: true
EnforcedStyle: context_dependent

# Align `when` with `case`.
Layout/CaseIndentation:
Enabled: true
Expand All @@ -36,7 +30,7 @@ Layout/EmptyLineAfterMagicComment:

# In a regular class definition, no empty lines around the body.
Layout/EmptyLinesAroundClassBody:
Enabled: true
Enabled: false

# In a regular method definition, no empty lines around the body.
Layout/EmptyLinesAroundMethodBody:
Expand All @@ -46,7 +40,7 @@ Layout/EmptyLinesAroundMethodBody:
Layout/EmptyLinesAroundModuleBody:
Enabled: true

Layout/IndentFirstArgument:
Layout/FirstArgumentIndentation:
Enabled: true

# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Expand All @@ -57,7 +51,7 @@ Style/HashSyntax:
# extra level of indentation.
Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: rails
EnforcedStyle: indented_internal_methods

# Two spaces, no tabs (for indentation).
Layout/IndentationWidth:
Expand Down Expand Up @@ -119,19 +113,19 @@ Layout/SpaceInsideParens:
# EnforcedStyle: single_quotes

# Detect hard tabs, no hard tabs.
Layout/Tab:
Layout/IndentationStyle:
Enabled: true

# Blank lines should not have any spaces.
Layout/TrailingBlankLines:
Layout/TrailingEmptyLines:
Enabled: true

# No trailing whitespace.
Layout/TrailingWhitespace:
Enabled: false

# Use quotes for string literals when they are enough.
Style/UnneededPercentQ:
Style/RedundantPercentQ:
Enabled: true

# Align `end` with the matching keyword or starting expression except for
Expand All @@ -146,7 +140,7 @@ Lint/RequireParentheses:
Enabled: true

Style/RedundantReturn:
Enabled: true
Enabled: false
AllowMultipleReturnValues: true

Style/Semicolon:
Expand Down
12 changes: 6 additions & 6 deletions lib/xero-ruby/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def initialize(config: {}, credentials: {})

def append_to_default_config(default_config, user_config)
config = default_config
user_config.each{|k,v| config.send("#{k}=", v)}
user_config.each { |k, v| config.send("#{k}=", v) }
config
end

Expand Down Expand Up @@ -194,7 +194,7 @@ def validate_state(params)
return true
end

def decode_jwt(tkn, verify=true)
def decode_jwt(tkn, verify = true)
if verify == true

response = Faraday.get('https://identity.xero.com/.well-known/openid-configuration/jwks') do |req|
Expand Down Expand Up @@ -251,18 +251,18 @@ def token_request(data, path)
# Connection heplers
def connections
@config.base_url = 'https://api.xero.com'
opts = { :header_params => {'Content-Type': 'application/json'}, :auth_names => ['OAuth2'] }
opts = { :header_params => { 'Content-Type': 'application/json' }, :auth_names => ['OAuth2'] }
response = call_api(:GET, "/connections/", nil, opts)
response[0]
end

def last_connection
connections.sort { |a,b| DateTime.parse(a['updatedDateUtc']) <=> DateTime.parse(b['updatedDateUtc'])}.last
connections.sort { |a, b| DateTime.parse(a['updatedDateUtc']) <=> DateTime.parse(b['updatedDateUtc']) }.last
end

def disconnect(connection_id)
@config.base_url = 'https://api.xero.com'
opts = { :header_params => {'Content-Type': 'application/json'}, :auth_names => ['OAuth2'] }
opts = { :header_params => { 'Content-Type': 'application/json' }, :auth_names => ['OAuth2'] }
call_api(:DELETE, "/connections/#{connection_id}", nil, opts)
connections
end
Expand All @@ -286,7 +286,7 @@ def call_api(http_method, path, api_client, opts = {})
when "AssetApi"
method_base_url = @config.asset_url
when "FilesApi"
method_base_url = @config.files_url
method_base_url = @config.files_url
when "PayrollAuApi"
method_base_url = @config.payroll_au_url
when "PayrollNzApi"
Expand Down
74 changes: 37 additions & 37 deletions lib/xero-ruby/where.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,51 @@ def to_param

private

def parameterize_option(key, value)
quoted_key = quote_key(key)
def parameterize_option(key, value)
quoted_key = quote_key(key)

case value
when Array
operator, query = value
case value
when Array
operator, query = value

if STRING_FUNCTIONS.include?(camelize_key(operator))
"#{quoted_key}.#{camelize_key(operator)}(#{quote_value(query)})"
if STRING_FUNCTIONS.include?(camelize_key(operator))
"#{quoted_key}.#{camelize_key(operator)}(#{quote_value(query)})"
else
"#{quoted_key} #{operator} #{quote_value(query)}"
end
when Range
"#{quoted_key} >= #{quote_value(value.first)} AND #{quoted_key} <= #{quote_value(value.last)}"
when /^\./
"#{quoted_key}#{value}"
else
"#{quoted_key} #{operator} #{quote_value(query)}"
"#{quoted_key} #{value}"
end
when Range
"#{quoted_key} >= #{quote_value(value.first)} AND #{quoted_key} <= #{quote_value(value.last)}"
when /^\./
"#{quoted_key}#{value}"
else
"#{quoted_key} #{value}"
end
end

def quote_key(key)
case key
when :contact_id
'Contact.ContactID'
when :contact_number
'Contact.ContactNumber'
when :invoice_id
'Invoice.InvoiceId'
else
camelize_key(key)
def quote_key(key)
case key
when :contact_id
'Contact.ContactID'
when :contact_number
'Contact.ContactNumber'
when :invoice_id
'Invoice.InvoiceId'
else
camelize_key(key)
end
end
end

def quote_value(value)
case value
when DateTime, Date, Time
"DateTime(#{value.strftime("%Y,%m,%d")})"
when Numeric, false, true
value.to_s
when UUID_REGEXP
%{guid("#{value}")}
else
%{"#{value.to_s.gsub('"', '""')}"}
def quote_value(value)
case value
when DateTime, Date, Time
"DateTime(#{value.strftime("%Y,%m,%d")})"
when Numeric, false, true
value.to_s
when UUID_REGEXP
%{guid("#{value}")}
else
%{"#{value.to_s.gsub('"', '""')}"}
end
end
end
end
end
Loading

0 comments on commit d865b1b

Please sign in to comment.