-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: master
Are you sure you want to change the base?
Conversation
@@ -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' }) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# @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) |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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']) |
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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' | ||
}} |
There was a problem hiding this comment.
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' }) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
lib/ncmb/client.rb
Outdated
@@ -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') |
There was a problem hiding this comment.
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
lib/ncmb/client.rb
Outdated
@@ -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('&') |
There was a problem hiding this comment.
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 }.
lib/ncmb/client.rb
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/ncmb/client.rb
Outdated
@@ -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}" |
There was a problem hiding this comment.
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
lib/ncmb/client.rb
Outdated
@@ -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}" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
signature_base << params.collect { |k, v| "#{k}=#{v}" }.join('&') | ||
Base64.encode64( | ||
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), | ||
@client_key, |
There was a problem hiding this comment.
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")) |
There was a problem hiding this comment.
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
Click here if you want to create rubocop's auto-correct Pull Request See the documentation if you want to get more information about auto-correct. |
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( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
No description provided.