<commit_before>

class PostStream::ApiController < ApplicationController


skip_before_filter :verify_authenticity_token

 before_filter :api_request

 protected

 def api_request
   if params[:apikey]
     user = EndUser.find_by_api_token(params[:apikey])
     process_login user
   end
   true
 end



 public

 def create

   if myself.has_role?('post_stream_manage')

     args = params.slice(:target_type,:target_id,:subject,:message)
     target = PostStreamTarget.find_by_target_type_and_target_id(args[:target_type],args[:target_id])

     if target 
       @post = PostStreamPost.new :body => args[:message], :title => args[:subject], :end_user_id => myself.id, :posted_by => target.target

       if @post.save
         PostStreamPostTarget.link_post_to_target(@post,target)
<commit_msg>Added support for missing targets<commit_after>

class PostStream::ApiController < ApplicationController


skip_before_filter :verify_authenticity_token

 before_filter :api_request

 protected

 def api_request
   if params[:apikey]
     user = EndUser.find_by_api_token(params[:apikey])
     process_login user
   end
   true
 end



 public

 def create

   if myself.has_role?('post_stream_manage')

     args = params.slice(:target_type,:target_id,:subject,:message)
     target = PostStreamTarget.find_by_target_type_and_target_id(args[:target_type],args[:target_id])


     if !target && PostStreamTarget.find_by_target_type(args[:target_type])
       target = PostStreamTarget.create(:target_type => args[:target_type],
                               :target_id => args[:target_id])
    end

     if target 
       @post = PostStreamPost.new :body => args[:message], :title => args[:subject], :end_user_id => myself.id, :posted_by => target.target

       if @post.save
         PostStreamPostTarget.link_post_to_target(@post,target)

{'fraction_non_alphanumeric': 0.10005437737901034, 'fraction_numerical': 0.0, 'mean_word_length': 4.183098591549296, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '4143595', 'n_tokens_mistral': 584, 'n_tokens_neox': 549, 'n_words': 101}