Sha256: ee8e722f2137f64b3bc1c64217c3d25efeebaffc885916675836a36ef213f3b8

Contents?: true

Size: 930 Bytes

Versions: 10

Compression:

Stored size: 930 Bytes

Contents

class EventsController < ApplicationController
  MAX_BATCH_SIZE = 100

  before_action :authorize
  before_action :contacts, only: %i[index]

  def index
  end

  def not_shown_count
    render json: { count: Event.where('created_at > ?', params[:time_mark].to_datetime).count }
  end

  private

  def authorize
    unless authorized?
      redirect_to login_path and return unless Token.any?

      session['tokens'] = Token.instance.attributes
    end

    session['tokens'] = Services::Authorization::Tokens::Refresh.new(tokens: session['tokens'], request: request).call
    Services::Authorization::AuthorizeHubspot.new(tokens: session['tokens']).call
  end

  def contacts
    contact_id_batches = Event.all.map(&:object_id).uniq.each_slice(MAX_BATCH_SIZE).to_a
    @contacts = contact_id_batches.each_with_object([]) do |batch, memo|
      memo.concat Services::Hubspot::Contacts::GetBatch.new(batch).call
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hubspot-api-client-3.2.0 sample-apps/webhooks-contacts-app/app/controllers/events_controller.rb
hubspot-api-client-3.1.1 sample-apps/webhooks-contacts-app/app/controllers/events_controller.rb
hubspot-api-client-3.1.0.pre.beta sample-apps/webhooks-contacts-app/app/controllers/events_controller.rb
hubspot-api-client-3.0.0.pre.beta sample-apps/webhooks-contacts-app/app/controllers/events_controller.rb
hubspot-api-client-2.3.2 sample-apps/webhooks-contacts-app/app/controllers/events_controller.rb
hubspot-api-client-2.3.1 sample-apps/webhooks-contacts-app/app/controllers/events_controller.rb
hubspot-api-client-2.2.0 sample-apps/webhooks-contacts-app/app/controllers/events_controller.rb
hubspot-api-client-2.1.0 sample-apps/webhooks-contacts-app/app/controllers/events_controller.rb
hubspot-api-client-2.0.0 sample-apps/webhooks-contacts-app/app/controllers/events_controller.rb
hubspot-api-client-1.0.1 sample-apps/webhooks-contacts-app/app/controllers/events_controller.rb