Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up client.rb #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Clean up client.rb #24

wants to merge 2 commits into from

Conversation

goofmint
Copy link
Owner

No description provided.

@@ -21,7 +21,7 @@
item.set('Integer', i)
item.set('Boolean', true)
item.set('Array', [i, i * 2, i * 3, 'Orange', 'Tomato'])
item.set('Object', {test1: 'a', test2: 'b'})
item.set('Object', { test1: 'a', test2: 'b' })
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Redundant curly braces around a hash parameter.

# @todo = @todo.limit(20).inArray("Array", [4])
# @todo = @todo.limit(20).notInArray("Array", ['Orange'])
# @todo = @todo.limit(20).allInArray("Array", [1, 2, 4])
=begin
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Do not use block comments. :ref
  • Use only ascii symbols in comments. :ref

# @todo = @todo.limit(20).notInArray("Array", ['Orange'])
# @todo = @todo.limit(20).allInArray("Array", [1, 2, 4])
=begin
@todo = @todo.limit(20).where("String", 'テスト100').greaterThan("Integer", 1)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Use only ascii symbols in comments. :ref

# @todo = @todo.limit(20).allInArray("Array", [1, 2, 4])
=begin
@todo = @todo.limit(20).where("String", 'テスト100').greaterThan("Integer", 1)
@todo = @todo.limit(20).notEqualTo("String", 'テスト100')
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Use only ascii symbols in comments. :ref

=begin
@todo = @todo.limit(20).where("String", 'テスト100').greaterThan("Integer", 1)
@todo = @todo.limit(20).notEqualTo("String", 'テスト100')
@todo = @todo.limit(20).in("String", ['テスト100'])
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Use only ascii symbols in comments. :ref

testKey: 'testValue'
}
}
{ where: {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Redundant curly braces around a hash parameter.

}
{ where: {
testKey: 'testValue'
}}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Space inside } missing. :ref

@@ -25,7 +25,7 @@
item.set('Integer', i)
item.set('Boolean', true)
item.set('Array', [i, i * 2, i * 3, 'Orange', 'Tomato'])
item.set('Object', {test1: 'a', test2: 'b'})
item.set('Object', { test1: 'a', test2: 'b' })
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Redundant curly braces around a hash parameter.

def deletable?
if self.acl['*'.to_sym][:write] == true
if acl['*'.to_sym][:write] == true
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||. :ref

@@ -108,8 +110,8 @@ def put
@fields[:updateDate] = result[:updateDate]
self
end
alias :update :put

alias update put
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Use a guard clause instead of wrapping the code inside a conditional expression. :ref

@@ -60,7 +60,7 @@ def encode_query(queries = {})
results = {}
queries.each do |k, v|
v = array2hash(v) if v.is_a? Array
value = URI.encode(v.is_a?(Hash) ? v.to_json : v.to_s).gsub("[", "%5B").gsub(":", "%3A").gsub("]", "%5D")
value = URI.encode(v.is_a?(Hash) ? v.to_json : v.to_s).gsub('[', '%5B').gsub(':', '%3A').gsub(']', '%5D')
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Line is too long. [113/80] :ref

@@ -116,7 +116,7 @@ def generate_signature(method, path, now = nil, queries = {})
signature_base << method.upcase
signature_base << @domain
signature_base << path
signature_base << params.collect{|k,v| "#{k}=#{v}"}.join("&")
signature_base << params.collect{|k,v| "#{k}=#{v}"}.join('&')
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Space missing to the left of {.
  • Space between { and | missing.
  • Space missing after comma. :ref
  • Space missing inside }.

@@ -158,7 +158,7 @@ def request(method, path, queries = {})
query = encode_query(queries).map do |key, value|
"#{key}=#{value}"
end.join("&")
path = path + (query == '' ? "" : "?"+query)
path = path + (query == '' ? '' : "?"+query)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Use self-assignment shorthand +=. :ref
  • Prefer single-quoted strings when you don't need string interpolation or special symbols. :ref
  • Surrounding space missing for operator +. :ref

@@ -170,7 +170,7 @@ def request(method, path, queries = {})
if queries[:file].is_a?(File) || queries[:file].is_a?(StringIO)
boundary = SecureRandom.uuid
req.body = make_boundary(boundary, queries)
headers["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
headers['Content-Type'] = "multipart/form-data; boundary=#{boundary}"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Line is too long. [81/80] :ref

@@ -184,7 +184,7 @@ def request(method, path, queries = {})
if queries[:file].is_a?(File) || queries[:file].is_a?(StringIO)
boundary = SecureRandom.uuid
req.body = make_boundary(boundary, queries)
headers["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
headers['Content-Type'] = "multipart/form-data; boundary=#{boundary}"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Line is too long. [81/80] :ref

@@ -52,15 +52,19 @@ def array2hash(ary)
new_v = [hash]
end
end
new_v = new_v.sort_by{|a, b| a.to_s}.to_h
new_v = new_v.sort_by{ |a, b| a.to_s }.to_h
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Space missing to the left of {.
  • Unused block argument - b. If it's necessary, use _ or _b as an argument name to indicate that it won't be used. :ref

new_v
end

def encode_query(queries = {})
results = {}
queries.each do |k, v|
v = array2hash(v) if v.is_a? Array
value = URI.encode(v.is_a?(Hash) ? v.to_json : v.to_s).gsub("[", "%5B").gsub(":", "%3A").gsub("]", "%5D")
value = URI.encode(v.is_a?(Hash) ? v.to_json : v.to_s)
.encode("UTF-8")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Align .encode with .encode on line 63.
  • Prefer single-quoted strings when you don't need string interpolation or special symbols. :ref

value = URI.encode(v.is_a?(Hash) ? v.to_json : v.to_s).gsub("[", "%5B").gsub(":", "%3A").gsub("]", "%5D")
value = URI.encode(v.is_a?(Hash) ? v.to_json : v.to_s)
.encode("UTF-8")
.gsub('[', '%5B')
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Align .gsub with .encode on line 63.

value = URI.encode(v.is_a?(Hash) ? v.to_json : v.to_s)
.encode("UTF-8")
.gsub('[', '%5B')
.gsub(':', '%3A')
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Align .gsub with .encode on line 63.

.encode("UTF-8")
.gsub('[', '%5B')
.gsub(':', '%3A')
.gsub(']', '%5D')
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Align .gsub with .encode on line 63.

params = params.sort_by{|a, b| a.to_s}.to_h
params = params.merge 'X-NCMB-Timestamp' => now
if [].respond_to?('to_h') # Array#to_h inpremented over ruby 2.1
params = params.sort_by { |a, b| a.to_s }.to_h
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Unused block argument - b. If it's necessary, use _ or _b as an argument name to indicate that it won't be used. :ref

else
sorted_params = {}
params = params.sort_by{|a, b| a.to_s}.each {|kv|
params = params.sort_by { |a, b| a.to_s }.each { |kv|
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Useless assignment to variable - params. :ref
  • Unused block argument - b. If it's necessary, use _ or _b as an argument name to indicate that it won't be used. :ref
  • Avoid using {...} for multi-line blocks. :ref

signature_base << params.collect { |k, v| "#{k}=#{v}" }.join('&')
Base64.encode64(
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'),
@client_key,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Align the parameters of a method call if they span more than one line. :ref

Base64.encode64(
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'),
@client_key,
signature_base.join("\n"))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Align the parameters of a method call if they span more than one line. :ref

@goofmint
Copy link
Owner Author

Click here if you want to create rubocop's auto-correct Pull Request
Auto Correct by SideCI

See the documentation if you want to get more information about auto-correct.
Document

rp = Regexp.new "/#{NCMB::API_VERSION}/files/.*"
if path =~ rp
json = http.get(path, headers).body
else
json = JSON.parse(http.get(path, headers).body, symbolize_names: true)
json = JSON.parse(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Use 2 (not -5) spaces for indentation. :ref

end
rescue => e
@@last_error = e
@@last_error = e
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Replace class var @@last_error with a class instance var. :ref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant