Probably the easiest way is to use Ruby in Twenty Minutes
Use either official instruction or any other instruction our there on the internet. Please make sure you install Ruby version 2.6
Usually it's done by running gem install http
in your terminal
Create a file assignment.rb
and type inside:
require 'http'
puts 'John Smith'
If you did everything right then executing this file (usually by running ruby assignment.rb
in a terminal) should result in printing words "Johm Smith" in your terminal
Now make it print your name instead of "John Smith".
Amend the code in assignment.rb code as follows:
require 'http'
response = HTTP.get('https://app.veeqo.com/')
puts response.status
puts 'John Smith'
If you did everything right then after executing the file it should print
200 OK
John Smith
Here and below we assume that "John Smith" is substituted with your name.
Veeqo is about e-commerce which's very heart is a sales order. So now instead of sending a request to 'https://app.veeqo.com/' please edit the code so that it sends a request to 'https://app.veeqo.com/orders/34876370'.
Expected output:
302 Found
John Smith
Please see documentation of http
gem to learn how to add a header to your request.
You are to add a header of :accept => "application/json"
to the request.
Expected output:
401 Unauthorized
John Smith
Veeqo did not recognise you in the previous step and therefore did not expose a sensitive information to you. Please fix that by adding a cookie to your request.
The cookie has to be the following: :_veeqo_session_v3 => 'BAh7CEkiD3Nlc3Npb25faWQGOgZFVEkiJWE3NzI1MjliOGE4NWVlN2JkYTdmNmY3Y2U0ZmE0ZmEzBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMVdpNURKdEJvV0g5aXMydHhZbnJsb0NYVkdpczBRNXp5YVlmSVk2N2xGenc9BjsARkkiFGN1cnJlbnRfdXNlcl9pZAY7AEZpAhBv--5fc15099e7cc294675479044baf0a6f7ef27b1d7'
Please search documentation of http
gem for the hints on how to add cookies to a request (but don't forget to keep the header in place).
If you added the cookie correctly the output should like like:
200 OK
John Smith
200 OK
in the previous step indicates that Veeqo returned some real life data in response to your request. It's time to inspect it.
Right after the line puts response.status
in your assignment.rb please add the following line:
puts response.parse['total_price']
It should make the script print the total price of the order:
200 OK
3600.0
John Smith
An order has a customer, a customer has a billing address, a billing address has its own attributes. If you try to print response.parse['customer']['billing_address']
you will see all the attributes of the billing address, you'll also see that a billing address is actually a Ruby hash.
The last step is to make your script print full name and city of the billing address.
Expected output:
200 OK
3600.0
ade mitchell
Swansea
John Smith
Please note that the first name and the last name should be printed on the same line.
When you are done please send us your assignment.rb
file, it should print what is expected in the step #9 when run.
Данил, здравствуйте! остановился на 7 пункте, логику понял, с синтаксисом ruby немного трудновато.