Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BookReservation < ActiveRecord::Base
- attr_reader :confirmation_number, :reservation_id
- validates :partner_code,
- :restaurant_location_id,
- :session_id,
- :dining_date_and_time,
- :size,
- :first_name,
- :last_name,
- :email,
- :guest_accepts_email_marketing,
- :confirmation_number,
- :reservation_id,
- presence: :true
- before_create :send_reservation_request
- def client
- Savon.client(wsdl: "http://example-wsdl-link", follow_redirects: :follow_redirects)
- end
- def send_reservation_request
- message = {'PartnerCode' => partner_code, 'RestaurantLocationId' => restaurant_location_id, 'SessionId' => session_id, 'DiningDateAndTime' => dining_date_and_time, 'Size' => size}
- message.merge!('Booker' => {'UserWithoutALogin' => {'FirstName' => first_name, 'LastName' => last_name, 'EMail' => email, 'GuestAcceptsEmailMarketingFromPartner' => guest_accepts_email_marketing}})
- response = client.call(:book_reservation, message: message)
- if response.success?
- data = response.to_array(:book_reservation_response).first
- if data
- @confirmation_number = data[:confirmation_number]
- @reservation_id = data[:reservation_id]
- end
- else
- errors.add "Failed to do the stuff you wanted to do with SOAP request"
- end
- end
- end
- class BookReservationsController < ApplicationController
- before_filter :concatenate_date, only: :index
- def index
- reservation = BookReservation.new(book_reservation_params)
- if reservation.save
- #put your logics here
- render :nothing
- else
- flash[:error] = reservation.errors.full_messages
- redirect_to book_reservation_path
- end
- end
- private
- def book_reservation_params
- params.require(:book_reservation).permit(:partner_code, :restaurant_location_id, :session_id, :dining_date_and_time, :size, :first_name, :last_name, :email, :guest_accepts_email_marketing, :confirmation_number, :reservation_id)
- end
- def concatenate_date
- params[:dining_date_and_time] = "#{(params[:dining_date] + ' ' + params[:dining_time]).to_datetime.strftime("%Y-%m-%dT%H:%M:%S")}"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement