def get(name = nil, token = :last, not_found = :wait, found = :return, options = {})
      @raw = send_get_request(@conn, ['/v1/event/list'], options, use_named_parameter('name', name))
      body = JSON.parse(@raw.body)
      # TODO: deal with unknown symbols, invalid indices (find_index will return nil)
      idx = case token
            when :first then 0
            when :last then body.length - 1
            when :next then body.length
            else body.find_index { |e| e['ID'] == token } + 1
            end
      if JSON.parse(@raw.body).count.zero? || idx == body.length
        case not_found
        when :reject
          raise Diplomat::EventNotFound, name
        when :return
          event_name = ''
          event_payload = ''
          event_token = :last
        when :wait
          @raw = wait_for_next_event(['/v1/event/list'], options, use_named_parameter('name', name))
          @raw = parse_body
          # If it's possible for two events to arrive at once,
          # this needs to #find again:
          event = @raw.last
          event_name = event['Name']
          event_payload = Base64.decode64(event['Payload'])
          event_token = event['ID']
        end
      else
        case found
        when :reject
          raise Diplomat::EventAlreadyExits, name
        when :return
          event = body[idx]
          event_name = event['Name']
          event_payload = event['Payload'].nil? ? nil : Base64.decode64(event['Payload'])
          event_token = event['ID']
        end
      end

      {
        value: { name: event_name, payload: event_payload },
        token: event_token
      }
    end
def get(name = nil, token = :last, not_found = :wait, found = :return, options = {})
      @raw = send_get_request(@conn, ['/v1/event/list'], options, use_named_parameter('name', name))
      body = JSON.parse(@raw.body)
      # TODO: deal with unknown symbols, invalid indices (find_index will return nil)
      idx = case token
            when :first then 0
            when :last then body.length - 1
            when :next then body.length
            else body.find_index { |e| e['ID'] == token } + 1
            end
      if JSON.parse(@raw.body).count.zero? || idx == body.length
        case not_found
        when :reject
          raise Diplomat::EventNotFound, name
        when :return
          event_name = ''
          event_payload = ''
          event_token = :last
        when :wait
          @raw = wait_for_next_event(['/v1/event/list'], options, use_named_parameter('name', name))
          @raw = parse_body
          # If it's possible for two events to arrive at once,
          # this needs to #find again:
          event = @raw.last
          event_name = event['Name']
          event_payload = Base64.decode64(event['Payload'])
          event_token = event['ID']
        end
      else
        case found
        when :reject
          raise Diplomat::EventAlreadyExits, name
        when :return
          event = body[idx]
          event_name = event['Name']
          event_payload = event['Payload'].nil? ? nil : Base64.decode64(event['Payload'])
          event_token = event['ID']
        end
      end

      {
        value: { name: event_name, payload: event_payload },
        token: event_token
      }
    end
Get a specific event in the sequence matching name
 @param name [String] the name of the event (regex)
 @param token [String|Symbol] the ordinate of the event in the sequence;
   String are tokens returned by previous calls to this function
   Symbols are the special tokens :first, :last, and :next
 @param not_found [Symbol] behaviour if there is no matching event;
   :reject with exception, :return degenerate value, or :wait for event
 @param found [Symbol] behaviour if there is a matching event;
   :reject with exception, or :return its current value
 @return [hash] A hash with keys :value and :token;
   :value is a further hash of the :name and :payload of the event,
   :token is the event's ordinate in the sequence and can be passed to future calls to get the subsequent event
 @param options [Hash] options parameter hash
 @note
   Whereas the consul API for events returns all past events that match
   name, this method allows retrieval of individual events from that
   sequence. However, because consul's API isn't conducive to this, we can
   offer first, last, next (last + 1) events, or arbitrary events in the
   middle, though these can only be identified relative to the preceding
   event. However, this is ideal for iterating through the sequence of
   events (while being sure that none are missed).
 rubocop:disable PerceivedComplexity