Skip to content

Commit

Permalink
[#6] Review methods order and exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Jun 16, 2021
1 parent 91aacc3 commit a930f34
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions app/services/google_service/client_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@ class ClientService

def initialize(keyword, lang = 'en')
escaped_keyword = CGI.escape(keyword)
@uri = URI("https://auibawsasxasxechjksdc.fr/search?q=#{escaped_keyword}&hl=#{lang}&gl=#{lang}")
end

# Inspect Http response status code
# Any non 200 response code will be logged
# response is set to nil in order to notify the error
def validate_result
return if @result.response.code == '200'

Rails.logger.warn "Warning: Query Google with keyword #{@keyword} return status code #{@result.response.code}"
@result = nil
@uri = URI("https://google.com/search?q=#{escaped_keyword}&hl=#{lang}&gl=#{lang}")
end

def query_result
Expand All @@ -33,5 +23,16 @@ def query_result
end
@result
end

private
# Inspect Http response status code
# Any non 200 response code will be logged
# response is set to nil in order to notify the error
def validate_result
return if @result.response.code == '200'

Rails.logger.warn "Warning: Query Google with keyword #{@keyword} return status code #{@result.response.code}"
@result = nil
end
end
end

0 comments on commit a930f34

Please sign in to comment.