Ruby OOP, SOAP request with Savon: "uninitialized constant CustomError (NameError)"

320 views Asked by At

I am very new to OOP programming with Ruby and using the Savon gem to make requests to a SOAP XML Webservice / API. I was able to successfully see responses back when using a much more simplified non object oriented approach but I wanted to refactor my code and ensure that it is extendible and works in Rails later. I'm sure it's something pretty simple but I have no idea where I'm going wrong! Please help, thanks very much in advance!

Below is my ruby file reserve.rb:

require 'savon'

class Reservation
  attr_accessor :first_name

def initialize(options={})
  @first_name = options[:first_name]
end

def client
client = Savon.client(wsdl: "http://some_wdsl_url_link", adapter: :curb, follow_redirects: :follow_redirects)
end

def first_name(confirm_number, email) 
  message = { confirmation_number: confirm_number, email: email }
  response = client.call(:search_for_reservation, message: message)
  response.body[:search_for_reservation_response][:reservation][:first_name]
rescue Savon::SOAPFault => error
  fault_code = error.to_hash[:fault][:faultcode]
  raise CustomError, fault_code
end

end
reserve = Reservation.new
puts reserve.first_name("NTSOTHJN", "[email protected]")

And here is the output in the terminal when I run ruby reserve.rb:

reserve.rb:20:in `rescue in first_name': uninitialized constant Reservation::CustomError (NameError)
    from reserve.rb:15:in `first_name'
    from reserve.rb:25:in `<main>'
0

There are 0 answers