<commit_before>module Qblox
  module Api

    class Dialog < Connections::ApiEndpoint
      @path = 'chat/Dialog'
      include RequireUserSession

      # Get a list of Dialogs that a user participates
      # http://quickblox.com/developers/Chat#Retrieve_dialogs
      #
      # options keyword should be a hash and could contain keys
      # to filter results. Just as explained on the link above
      def index(options = {})
        result = options.delete(:result)
        all = options.delete('all') || true
        response = query(:get) do |req|
          req.params = options
        end
        data = json_parse(response.body)
        return data unless all

        if result
          result['items'].concat(data['items'])
        else
          result ||= data
        end

        if result['total_entries'] > result['items'].size
          result = index(options.merge(skip: result['items'].size,
                                     result: result))
        end
        return result
      end

      def create(data = {})
        fail ArgumentError, 'type is required' if data[:type].nil?
        if data[:type] != 1 && data[:occupants_ids].to_a.size == 0
          fail(ArgumentError, 'occupant_ids should have at least one id '\
               "for type = #{data[:type]}")
        end
        if data[:type] != 3 && data[:name].nil?
          fail(ArgumentError, 'name should be provided for '\
               "type = #{data[:type]}")
        end

        response = query(:post, data)
        data = json_parse(response.body)
      end

      def update(chat_dialog_id, data = {})
        response = query(:put) do |req|
          req.url url(id: chat_dialog_id), data
        end
        json_parse(response.body)
      end

      def delete(chat_dialog_id, data = {})
        response = query(:delete) do |req|
          req.url url(id: chat_dialog_id), data
        end
        response
      end
    end
  end
end<commit_msg>Fix create_dialog<commit_after>module Qblox
  module Api

    class Dialog < Connections::ApiEndpoint
      @path = 'chat/Dialog'
      include RequireUserSession

      # Get a list of Dialogs that a user participates
      # http://quickblox.com/developers/Chat#Retrieve_dialogs
      #
      # options keyword should be a hash and could contain keys
      # to filter results. Just as explained on the link above
      def index(options = {})
        result = options.delete(:result)
        all = options.delete('all') || true
        response = query(:get) do |req|
          req.params = options
        end
        data = json_parse(response.body)
        return data unless all

        if result
          result['items'].concat(data['items'])
        else
          result ||= data
        end

        if result['total_entries'] > result['items'].size
          result = index(options.merge(skip: result['items'].size,
                                     result: result))
        end
        return result
      end

      def create(data = {})
        fail ArgumentError, 'type is required' if data[:type].nil?
        if data[:type] != 1 && data[:occupants_ids].to_a.size == 0
          fail(ArgumentError, 'occupant_ids should have at least one id '\
               "for type = #{data[:type]}")
        end
        if data[:type] != 3 && data[:name].nil?
          fail(ArgumentError, 'name should be provided for '\
               "type = #{data[:type]}")
        end

        response = query(:post, params: data)
        data = json_parse(response.body)
      end

      def update(chat_dialog_id, data = {})
        response = query(:put) do |req|
          req.url url(id: chat_dialog_id), data
        end
        json_parse(response.body)
      end

      def delete(chat_dialog_id, data = {})
        response = query(:delete) do |req|
          req.url url(id: chat_dialog_id), data
        end
        response
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1060296371997956, 'fraction_numerical': 0.0015329586101175269, 'mean_word_length': 1.8978534418948927, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6503780', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1063, 'n_words': 313}