class Google::Cloud::Bigquery::Service

def service

def service
  return mocked_service if mocked_service
  @service ||= begin
    service = API::BigqueryService.new
    service.client_options.application_name    = "gcloud-ruby"
    service.client_options.application_version = Google::Cloud::Bigquery::VERSION
    service.client_options.open_timeout_sec = timeout
    service.client_options.read_timeout_sec = timeout
    service.client_options.send_timeout_sec = timeout
    service.request_options.retries = 0 # handle retries in #execute
    service.request_options.header ||= {}
    service.request_options.header["x-goog-api-client"] =
      "gl-ruby/#{RUBY_VERSION} gccl/#{Google::Cloud::Bigquery::VERSION}"
    service.request_options.query ||= {}
    service.request_options.query["prettyPrint"] = false
    service.request_options.quota_project = @quota_project if @quota_project
    service.authorization = @credentials.client
    service.universe_domain = @universe_domain
    service.root_url = host if host
    begin
      service.verify_universe_domain!
    rescue Google::Apis::UniverseDomainError => e
      # TODO: Create a Google::Cloud::Error subclass for this.
      raise Google::Cloud::Error, e.message
    end
    service
  end
end