class ExternalApi
Public Class Methods
new(amount = nil, tip = "15")
click to toggle source
# File lib/calculate-tip/external-api.rb, line 7 def initialize(amount = nil, tip = "15") @amount = amount.to_f @tip = tip.to_f @base_url = "http://office.code-runners.com:8888" end
Public Instance Methods
calculate()
click to toggle source
# File lib/calculate-tip/external-api.rb, line 21 def calculate uri = URI.parse(@base_url) request = Net::HTTP::Post.new(uri) request.set_form_data( "amount" => @amount.to_s, "tip" => @tip.to_s, ) req_options = { use_ssl: uri.scheme == "https", } response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| http.request(request) end return response.body end
get_amount()
click to toggle source
# File lib/calculate-tip/external-api.rb, line 13 def get_amount @amount end
get_tip()
click to toggle source
# File lib/calculate-tip/external-api.rb, line 17 def get_tip @tip end