<commit_before>class ActivityCreator
  include Rails.application.routes.url_helpers

  def initialize(user, action, event)
    @action = action
    @user = user
    @event = event
  end

  def create
    response = RestClient.post rest_client_url,
    generate_json,
    :content_type => :json,
    :accept => :json
  # rescue Exception => e
  #   Rails.logger.error(e.response.inspect)
  #   Rails.logger.error(generate_json)
  #   Rails.logger.error(@user.access_token)
  #   raise
  end

  private

  def generate_json
    {
      activity: {
        actor: { name: @user.name, email: @user.email },
        action: @action,
        object: {
          url: event_url(@event),
          type: 'page',
          title: @event.name,
          image: ActionController::Base.helpers.asset_path('logo.png')
        }
      },
      message: 'Fake message for testing purposes',
      users: @event.invitees_for_json
    }.to_json
  end

  def rest_client_url
    @user.yammer_endpoint + "api/v1/activity.json?access_token=#{@user.access_token}"
  end
end<commit_msg>Add Exception handling+logging for ActivityCreator<commit_after>class ActivityCreator
  include Rails.application.routes.url_helpers

  def initialize(user, action, event)
    @action = action
    @user = user
    @event = event
  end

  def create
    response = RestClient.post rest_client_url,
    generate_json,
    :content_type => :json,
    :accept => :json
  rescue Exception => e
    Rails.logger.error(e.response.inspect)
    Rails.logger.error(generate_json)
    Rails.logger.error(@user.access_token)
    raise
  end

  private

  def generate_json
    {
      activity: {
        actor: { name: @user.name, email: @user.email },
        action: @action,
        object: {
          url: event_url(@event),
          type: 'page',
          title: @event.name,
          image: ActionController::Base.helpers.asset_path('logo.png')
        }
      },
      message: 'Fake message for testing purposes',
      users: @event.invitees_for_json
    }.to_json
  end

  def rest_client_url
    @user.yammer_endpoint + "api/v1/activity.json?access_token=#{@user.access_token}"
  end
end
{'fraction_non_alphanumeric': 0.11044083526682134, 'fraction_numerical': 0.0009280742459396752, 'mean_word_length': 2.6791808873720138, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '751780', 'n_tokens_mistral': 696, 'n_tokens_neox': 688, 'n_words': 141}