class TourCMS::Connection
Public Class Methods
new(marketp_id, private_key, result_type = "raw")
click to toggle source
# File lib/tour_cms/connection.rb, line 3 def initialize(marketp_id, private_key, result_type = "raw") Integer(marketp_id) rescue raise ArgumentError, "Marketplace ID must be an Integer" @marketp_id = marketp_id @private_key = private_key @result_type = result_type @base_url = "https://api.tourcms.com" end
Public Instance Methods
api_rate_limit_status(channel = 0)
click to toggle source
# File lib/tour_cms/connection.rb, line 11 def api_rate_limit_status(channel = 0) request("/api/rate_limit_status.xml", channel) end
list_channels()
click to toggle source
# File lib/tour_cms/connection.rb, line 15 def list_channels request("/p/channels/list.xml") end
list_tour_images(channel = 0)
click to toggle source
# File lib/tour_cms/connection.rb, line 55 def list_tour_images(channel = 0) if channel == 0 request("/p/tours/images/list.xml") else request("/c/tours/images/list.xml", channel) end end
list_tours(channel = 0)
click to toggle source
# File lib/tour_cms/connection.rb, line 47 def list_tours(channel = 0) if channel == 0 request("/p/tours/list.xml") else request("/c/tours/list.xml", channel) end end
search_hotels_range(params = {}, tour = "", channel = 0)
click to toggle source
# File lib/tour_cms/connection.rb, line 31 def search_hotels_range(params = {}, tour = "", channel = 0) if channel == 0 request("/p/hotels/search_range.xml", 0, params.merge({"single_tour_id" => tour})) else request("/c/hotels/search_range.xml", channel, params.merge({"single_tour_id" => tour})) end end
search_hotels_specific(params = {}, tour = "", channel = 0)
click to toggle source
# File lib/tour_cms/connection.rb, line 39 def search_hotels_specific(params = {}, tour = "", channel = 0) if channel == 0 request("/p/hotels/search-avail.xml", 0, params.merge({"single_tour_id" => tour})) else request("/c/hotels/search-avail.xml", channel, params.merge({"single_tour_id" => tour})) end end
search_tours(params = {}, channel = 0)
click to toggle source
# File lib/tour_cms/connection.rb, line 23 def search_tours(params = {}, channel = 0) if channel == 0 request("/p/tours/search.xml", 0, params) else request("/c/tours/search.xml", channel, params) end end
show_channel(channel)
click to toggle source
# File lib/tour_cms/connection.rb, line 19 def show_channel(channel) request("/c/channel/show.xml", channel) end
show_tour(tour, channel)
click to toggle source
# File lib/tour_cms/connection.rb, line 63 def show_tour(tour, channel) request("/c/tour/show.xml", channel, {"id" => tour}) end
show_tour_departures(tour, channel)
click to toggle source
# File lib/tour_cms/connection.rb, line 67 def show_tour_departures(tour, channel) request("/c/tour/datesprices/dep/show.xml", channel, {"id" => tour}) end
show_tour_freesale(tour, channel)
click to toggle source
# File lib/tour_cms/connection.rb, line 71 def show_tour_freesale(tour, channel) request("/c/tour/datesprices/freesale/show.xml", channel, {"id" => tour}) end
Private Instance Methods
generate_signature(path, verb, channel, outbound_time)
click to toggle source
# File lib/tour_cms/connection.rb, line 77 def generate_signature(path, verb, channel, outbound_time) string_to_sign = "#{channel}/#{@marketp_id}/#{verb}/#{outbound_time}#{path}".strip dig = OpenSSL::HMAC.digest('sha256', @private_key, string_to_sign) b64 = Base64.encode64(dig).chomp CGI.escape(b64).gsub("+", "%20") end
request(path, channel = 0, params = {}, verb = "GET")
click to toggle source
# File lib/tour_cms/connection.rb, line 85 def request(path, channel = 0, params = {}, verb = "GET") url = @base_url + path + "?#{params.to_query}" req_time = Time.now.utc signature = generate_signature(path + "?#{params.to_query}", verb, channel, req_time.to_i) headers = {"Content-type" => "text/xml", "charset" => "utf-8", "Date" => req_time.strftime("%a, %d %b %Y %H:%M:%S GMT"), "Authorization" => "TourCMS #{channel}:#{@marketp_id}:#{signature}" } response = open(url, headers).read @result_type == "raw" ? response : Hash.from_xml(response)["response"] end