You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: artifact.rb
    path of file: ./repos/travis.rb/lib/travis/client
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

require 'travis/client'
require 'travis/tools/safe_string'

module Travis
  module Client
    class Artifact < Entity
      CHUNKED = 'application/json; chunked=true; version=2, application/json; version=2'
      TEXT    = "#{CHUNKED}, text/plain".freeze

      # @!parse attr_reader :job_id, :type, :body
      attributes :job_id, :type, :
    
      def body(stream = block_given?)
        return current_body unless block_given? || stream
        return yield(current_body) unless stream && job.pending?

        number = 0

        session.listen(self) do |listener|
          listener.on 'job:log' do |event|
            next unless event.payload['number'] > number

            number = event.payload['number']
            yield event.payload['_log']
            listener.disconnect if event.payload['final']
          end

          listener.on 'job:finished' do |_event|
            listener.disconnect
          end

          listener.on_connect do
            data = session.get_raw("/logs/#{id}", nil, 'Accept' => CHUNKED)['log']
            if data['parts']
              data['parts'].each { |p| yield p['content'] }
              number = data['parts'].last['number'] if data['parts'].any?
            else
              yield data['body']
              listener.disconnect
            end
          end
        end