<commit_before>require 'rest-client'

class IssueReporter
  @url = ENV["HEL_URL"]+"requests"

  def self.get_all
    JSON.parse(RestClient.get @url)
  end

  def self.send(pos_id)
    position = Position.find(pos_id)

    resp = RestClient.post(@url+".json", {
      api_key: ENV["HEL_API_KEY"],
      service_code: position.deduce_service_code,
      description: position.description,
      title: position.name,
      lat: position.lat,
      long: position.lon,
      email: position.email,
      media_url: position.one_picture_url
    }, {
      content_type: :json,
      accept: :json
    })

    #first because API returns array with one item
    json = JSON.parse(resp).first
    update_position(pos_id, json)
    json
  end

  def self.update_position(pos_id, json)
    position = Position.find pos_id
    position.issue_id = json["service_request_id"]
    position.save unless position.issue_id == nil
  end

  def self.find(id)
    return nil unless id != nil
    resp = RestClient.get @url+"/#{id}.json"
    JSON.parse(resp).first
  end
end<commit_msg>Sends first picture to API via media_url, appends description with link to position on fillari.info<commit_after>require 'rest-client'

class IssueReporter
  @url = ENV["HEL_URL"]+"requests"

  def self.get_all
    JSON.parse(RestClient.get @url)
  end

  def self.send(pos_id)
    position = Position.find(pos_id)

    resp = RestClient.post(@url+".json", {
      api_key: ENV["HEL_API_KEY"],
      service_code: position.deduce_service_code,
      description: create_description(position),
      title: position.name,
      lat: position.lat,
      long: position.lon,
      email: position.email,
      media_url: position.one_picture_url
    }, {
      content_type: :json,
      accept: :json
    })

    #first because API returns array with one item
    json = JSON.parse(resp).first
    update_position(pos_id, json)
    json
  end

  def self.find(id)
    return nil unless id != nil
    resp = RestClient.get @url+"/#{id}.json"
    JSON.parse(resp).first
  end

  def self.update_position(pos_id, json)
    position = Position.find pos_id
    position.issue_id = json["service_request_id"]
    position.save unless position.issue_id == nil
  end

  def self.create_description(position)
    position.description << "\n tehty fillari.info:n kautta. Piste kartalla: http://fillari.info/#id=#{position.id}"
  end
end
{'fraction_non_alphanumeric': 0.1108786610878661, 'fraction_numerical': 0.0, 'mean_word_length': 3.194736842105263, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '196851', 'n_tokens_mistral': 791, 'n_tokens_neox': 773, 'n_words': 178}