Skip to content

Commit

Permalink
Fix Linting Issues in Ruby SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Vignesh Kennadi committed Sep 5, 2024
1 parent c2d0522 commit 356d43d
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 127 deletions.
18 changes: 6 additions & 12 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 Down
28 changes: 14 additions & 14 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 @@ -143,7 +143,7 @@ def set_token_set(token_set)
set_access_token(token_set[:access_token]) if token_set[:access_token]
set_id_token(token_set[:id_token]) if token_set[:id_token]

return true
true
end

def set_access_token(access_token)
Expand All @@ -160,7 +160,7 @@ def get_client_credentials_token
}
token_set = token_request(data, '/token')

return token_set
token_set
end

def get_token_set_from_callback(params)
Expand All @@ -173,7 +173,7 @@ def get_token_set_from_callback(params)

validate_tokens(token_set)
validate_state(params)
return token_set
token_set
end

def validate_tokens(token_set)
Expand All @@ -184,17 +184,17 @@ def validate_tokens(token_set)
decode_jwt(access_token) if access_token
decode_jwt(id_token) if id_token
end
return true
true
end

def validate_state(params)
if params['state'] != @state
raise StandardError.new "WARNING: @config.state: #{@state} and OAuth callback state: #{params['state']} do not match!"
end
return true
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 All @@ -220,15 +220,15 @@ def refresh_token_set(token_set)
grant_type: 'refresh_token',
refresh_token: token_set[:refresh_token]
}
return token_request(data, '/token')
token_request(data, '/token')
end

def revoke_token(token_set)
token_set = token_set.with_indifferent_access
data = {
token: token_set[:refresh_token]
}
return token_request(data, '/revocation')
token_request(data, '/revocation')
end

def token_request(data, path)
Expand All @@ -245,24 +245,24 @@ def token_request(data, path)
else
body = {}
end
return body
body
end

# 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 356d43d

Please sign in to comment.