<commit_before>class Provider::Desk < Provider
  def client
    @client ||= ::Desk.client({
      subdomain: auth.site.name, 
      oauth_token: <PASSWORD>, 
      oauth_token_secret: auth.secret
    })
  end
  
  def markup_create
    @@markup_create ||= ({}).tap do |markup|
      SUPPORTED_TYPES.each do |item|
        markup[item] = JSON.parse(File.new("#{Rails.root}/app/models/provider/desk/#{item.to_s}_create.json").read)
      end
    end
  end
  
  def markup
    @@markup ||= ({}).tap do |markup|
      SUPPORTED_TYPES.each do |item|
        markup[item] = JSON.parse(File.new("#{Rails.root}/app/models/provider/desk/#{item.to_s}.json").read)
      end
    end
  end
  
  %w(cases interactions customers topics).each do |method|
    define_method(method) { |filter = {}| client.send(method, prepare_filter(filter)) }
  end
  
  %w(articles).each do |method|
    define_method(method) { |id = nil, filter = {}| client.send(method, id, prepare_filter(filter)) }
  end
private
  def prepare_filter(filter)
    tmp = {}
    filter.each_pair{ |key, value| 
      tmp[key] = (DateTime.strptime(value, "%m/%d/%y").strftime("%s") rescue value)
    }
    tmp
  end
end<commit_msg>Added create methods to the desk provider for import.<commit_after>class Provider::Desk < Provider
  def client
    @client ||= ::Desk.client({
      subdomain: auth.site.name, 
      oauth_token: <PASSWORD>, 
      oauth_token_secret: auth.secret
    })
  end
  
  def markup_create
    @@markup_create ||= ({}).tap do |markup|
      SUPPORTED_TYPES.each do |item|
        markup[item] = JSON.parse(File.new("#{Rails.root}/app/models/provider/desk/#{item.to_s}_create.json").read)
      end
    end
  end
  
  def markup
    @@markup ||= ({}).tap do |markup|
      SUPPORTED_TYPES.each do |item|
        markup[item] = JSON.parse(File.new("#{Rails.root}/app/models/provider/desk/#{item.to_s}.json").read)
      end
    end
  end
  
  %w(cases interactions customers topics).each do |method|
    define_method(method) { |filter = {}| client.send(method, prepare_filter(filter)) }
    define_method("create_#{method.singularize}") do |element = {}|
      unless method == 'cases'
        client.send("create_#{method.singularize}", element)
      else
        client.send("create_interaction", element)
      end
    end
  end
  
  %w(articles).each do |method|
    define_method(method) { |id = nil, filter = {}| client.send(method, id, prepare_filter(filter)) }
  end
private
  def prepare_filter(filter)
    tmp = {}
    filter.each_pair{ |key, value| 
      tmp[key] = (DateTime.strptime(value, "%m/%d/%y").strftime("%s") rescue value)
    }
    tmp
  end
end
{'fraction_non_alphanumeric': 0.15431164901664146, 'fraction_numerical': 0.0, 'mean_word_length': 3.08179012345679, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6171387', 'n_tokens_mistral': 945, 'n_tokens_neox': 915, 'n_words': 178}