You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Few minutes into a code and this is what strikes me:
File structure.
serpapi/serpapi.rb that hosts just a Client class - should be serpapi/client.rb
SerpApi::Client::VERSION that is used as a gem version - should be in a separate file serpapi/version.rb using SerpApi::VERSION namespace
serpapi/error.rb does not include corresponding Error module, just SerpApiException class - should be enclosed in unified Errors module, e.g.:
# serpapi/errors.rbmoduleSerpApimoduleErrors# all your custom errorsendend
specs should represent actual file structure, e.g.:
spec/serpapi/client_spec.rb // client config specs
spec/serpapi/client/*_spec.rb // all the integration tests that are currently just laying around
spec/serpapi_spec.rb // should include VERSION check only
Don't use open-uri. It creates temporary file for each response, i.e. redundant IO operation that just degrades performance. BTW, why do you have different HTTP clients in different gems? Some uses faraday, some open-uri, some http etc.
classSerpApi# should be ClientDEFAULT_TIMEOUT=120attr_accessor:timeoutattr_reader:params,:engine,:api_keydefinitialize(params={})@params=params.transform_keys(&:to_sym)@timeout=@params[:timeout] || DEFAULT_TIMEOUT@engine=@params[:engine]@api_key=@params[:api_key]endend
SerpApiException should not be raised for HTTP transport errors, it's misleading just from the naming convention. There should be a separate error class or just a transparent bypass.
raiseSerpApiException,"error: #{data['error']} from url: #{url}"ifdata.key?('error')
raiseSerpApiException,"fail: get url: #{url} response: #{data}"
rescue=>e
raiseSerpApiException,"fail: get url: #{url} caused by: #{e}"
end
No full branch coverage in simplecov, you just ignore bunch of untested places:
# do thisSimpleCov.startdoenable_coverage:branchadd_filter"/spec/"end
describe/it blocks are just bad. describe should refer to namespaced objects, currently they do context role.
No VCRs and dependence on specific API_KEY with high request limit makes testing impossible for other contributors rather than those who work in company.
The text was updated successfully, but these errors were encountered:
Hi,
Few minutes into a code and this is what strikes me:
serpapi/serpapi.rb
that hosts just aClient
class - should beserpapi/client.rb
SerpApi::Client::VERSION
that is used as a gem version - should be in a separate fileserpapi/version.rb
usingSerpApi::VERSION
namespaceserpapi/error.rb
does not include correspondingError
module, justSerpApiException
class - should be enclosed in unifiedErrors
module, e.g.:open-uri
. It creates temporary file for each response, i.e. redundant IO operation that just degrades performance. BTW, why do you have different HTTP clients in different gems? Some usesfaraday
, someopen-uri
, somehttp
etc.serpapi-ruby/lib/serpapi/serpapi.rb
Lines 11 to 14 in 0a80c85
serpapi-ruby/lib/serpapi/serpapi.rb
Lines 32 to 44 in 0a80c85
serpapi-ruby/lib/serpapi/serpapi.rb
Lines 95 to 97 in 0a80c85
serpapi-ruby/lib/serpapi/serpapi.rb
Lines 100 to 102 in 0a80c85
Can be simplified to:
serpapi-ruby/lib/serpapi/serpapi.rb
Line 10 in 0a80c85
serpapi-ruby/lib/serpapi/serpapi.rb
Line 27 in 0a80c85
nil
as third param, it's optional:serpapi-ruby/lib/serpapi/serpapi.rb
Line 84 in 0a80c85
serpapi-ruby/lib/serpapi/serpapi.rb
Line 113 in 0a80c85
Can be simplified to:
serpapi-ruby/lib/serpapi/serpapi.rb
Line 119 in 0a80c85
Can be simplified to:
SerpApiException
should not be raised for HTTP transport errors, it's misleading just from the naming convention. There should be a separate error class or just a transparent bypass.serpapi-ruby/lib/serpapi/serpapi.rb
Lines 138 to 145 in 0a80c85
simplecov
, you just ignore bunch of untested places:describe
/it
blocks are just bad.describe
should refer to namespaced objects, currently they docontext
role.API_KEY
with high request limit makes testing impossible for other contributors rather than those who work in company.The text was updated successfully, but these errors were encountered: