<commit_before>require 'httparty'

module Booker
  BASE_HOST = "stable-app.secure-booker.com"
  BASE_PATH = "/WebService4/json/customerService.svc"

  class Client
    attr_reader :url, :access_token, :expires_in

    def initialize(key, secret)
      @key = key
      @secret = secret
      set_access_token
    end

    # Useful to pull all of paged results and return them as if you did one
    # request for them all
    #
    # ex: client.all(:find_locations, 'Results')
    def all method, result_name, options = {}
      page_number = 1
      results = []

      # this allows page size to be overidden but NOT page_number as I want to
      # control that to know when we have all results
      options = {"PageSize" => 500}.merge options

      begin
        options.merge!({
          "PageNumber" => page_number,
        })

        last_result = self.send(method, options)

        results << last_result[result_name]
        results.flatten!

        total_results  = last_result['TotalResultsCount'] || 0

        page_number+=1
      end while results.length < total_results-1

      last_result.merge({
        result_name => results
      })
    end

    #http://apidoc.booker.com/Method/Detail/129
    def run_multi_service_availability options = {}
      raise Booker::ArgumentError, 'Itineraries is required' unless options['Itineraries']
      url = build_url "/availability/multiservice"
      defaults =
        {
        "access_token" => @access_token,
        "StartDateTime" => "/Date(#{Time.now.to_i})/",<commit_msg>Fix nil error from total results<commit_after>require 'httparty'

module Booker
  BASE_HOST = "stable-app.secure-booker.com"
  BASE_PATH = "/WebService4/json/customerService.svc"

  class Client
    attr_reader :url, :access_token, :expires_in

    def initialize(key, secret)
      @key = key
      @secret = secret
      set_access_token
    end

    # Useful to pull all of paged results and return them as if you did one
    # request for them all
    #
    # ex: client.all(:find_locations, 'Results')
    def all method, result_name, options = {}
      page_number = 1
      results = []

      # this allows page size to be overidden but NOT page_number as I want to
      # control that to know when we have all results
      options = {"PageSize" => 500}.merge options

      begin
        options.merge!({
          "PageNumber" => page_number,
        })

        last_result = self.send(method, options)

        results << last_result[result_name]
        results.flatten!

        if last_result['TotalResultsCount']
          total_results  = last_result['TotalResultsCount']
        else
          total_results = 0
        end

        page_number+=1
      end while results.length < total_results-1

      last_result.merge({
        result_name => results
      })
    end

    #http://apidoc.booker.com/Method/Detail/129
    def run_multi_service_availability options = {}
      raise Booker::ArgumentError, 'Itineraries is required' unless options['Itineraries']
      url = build_url "/availability/multiservice"
      defaults =
        {
        "access_token" => @access_token,
        "StartDateTime" => "/Date(#{Time.now.to_i})/",
{'fraction_non_alphanumeric': 0.09653233364573571, 'fraction_numerical': 0.006872852233676976, 'mean_word_length': 2.507119386637459, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '709429', 'n_tokens_mistral': 972, 'n_tokens_neox': 919, 'n_words': 251}