Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions client/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# screen.

response = HttpConnection.get('/')
puts # <fill this in>
puts JSON.parse(response)['message']


##################################################
Expand All @@ -24,8 +24,16 @@
# B. Send a POST to /sum with 'the_sum: <the sum>' as a parameter in the post body.
# C. Use `puts` to print the message portion of the response to the screen.

numbers = []
# <replace this with your code!>
total = 0
loop do
response = HttpConnection.get('/number')
total += JSON.parse(response)['number']
break if JSON.parse(response)['stop_asking']
end

puts total
response = HttpConnection.post('/sum', body: { the_sum: total })
puts JSON.parse(response)['message']

##################################################
# Exercise 3: Introducing sidekiq
Expand Down Expand Up @@ -56,9 +64,9 @@
# Instead, it'll appear in the sidekiq terminal.
# - Question to think about: why does all of this have to be this way?

# <insert first call here>
GetRequestSender.perform_async '/the_hard_stuff'
sleep 0.1
# <insert second call here>
GetRequestSender.perform_async '/the_easy_stuff'

verify_ex_4!

Expand All @@ -74,7 +82,7 @@
#
# (Remember to restart sidekiq after editing the file.)

# <code goes here>
GetRequestSender.perform_async '/touchy'

verify_ex_5! # This can take up to 30 seconds

Expand Down
9 changes: 4 additions & 5 deletions client/sidekiq_workers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ class GetRequestSender
sidekiq_retry_in { 0 }

def perform(path, params={})
# For exercise 3, replace this comment with code that
# sends the request, parses the response, and uses `puts` to
# print the message part of the response
path += '?' + params.map { |k,v| "#{k}=#{v}" }.join('&')
response = HttpConnection.get(path)
puts JSON.parse(response)['message']

# For exercise 5, replace this comment with code that
# retries the request if it fails
raise unless response.code == 200
end
end